Ignore:
Timestamp:
May 30, 2012, 7:57:34 AM (12 years ago)
Author:
psli
Message:

Pre-Version 2.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Psli_BingMaps/JS/Psli-BingMaps.js

    r14891 r15432  
    22Plugin Name: Psli-BingMaps
    33Author: psli
    4 Description: Maintenance function for plugin "Psli-BingMaps"
    54*/
    65
     
    2221
    2322/**************************************************************************/
    24 // JS Function used by admin script while setting up plugin
    25 function psli_AdminUpdateMap() {
    26         psli_g_MapCenter = new Microsoft.Maps.Location(document.getElementById("lat").value, document.getElementById("lon").value);
    27         psli_g_zoomInitial = document.getElementById("zoom").value
    28         var pin = new Microsoft.Maps.Pushpin(psli_g_MapCenter);
     23// JS global function for Map
     24function psli_InitMap() {
     25        psli_g_Map = new Microsoft.Maps.Map(document.getElementById("myMap"), psli_g_MapOptions);
     26        Microsoft.Maps.Events.addHandler(psli_g_Map, "viewchangeend", psli_MapViewChangeEnd);
     27        psli_g_Map.setView({center: psli_g_MapCenter, zoom: psli_g_zoomInitial});
     28}
     29       
     30function psli_MapViewChangeEnd () {
    2931        psli_g_Map.entities.clear();
    30         psli_g_Map.entities.push(pin);
     32        psli_g_Map.entities.push(psli_g_ZoomEntity[psli_g_Map.getZoom() - 1]);
     33}
     34                       
     35function psli_InitGuestMap() {
     36    psli_g_mode = "guest";
    3137       
    32         psli_g_Map.setView({center: psli_g_MapCenter, zoom: psli_g_zoomInitial});       
    33 }
    34 
    35 function psli_AdminMapClick(e) {
    36         if (e.targetType == "map") {
    37                 var psli_l_Point = new Microsoft.Maps.Point(e.getX(), e.getY());
    38                 psli_g_MapCenter = e.target.tryPixelToLocation(psli_l_Point);
    39                 psli_g_zoomInitial = Math.round(psli_g_Map.getZoom());
    40                
    41                 document.getElementById("lat").value = psli_g_MapCenter.latitude;
    42                 document.getElementById("lon").value = psli_g_MapCenter.longitude;
    43                 document.getElementById("zoom").value = psli_g_zoomInitial;
    44                                
    45                 var pin = new Microsoft.Maps.Pushpin(psli_g_MapCenter);
    46                 psli_g_Map.entities.clear();
    47                 psli_g_Map.entities.push(pin);
    48                
    49                 psli_g_Map.setView({center: psli_g_MapCenter, zoom: psli_g_zoomInitial});
    50         }
    51 }
    52 
    53 function psli_InitAdminSetup () {
    5438        psli_g_MapOptions = {
    5539                credentials: psli_g_BingKey,
     
    6246        };
    6347       
    64         psli_g_Map = new Microsoft.Maps.Map(document.getElementById("myMap"), psli_g_MapOptions);
    65         Microsoft.Maps.Events.addHandler(psli_g_Map, "click", psli_AdminMapClick);
    66         var pin = new Microsoft.Maps.Pushpin(psli_g_MapCenter);
    67         psli_g_Map.entities.clear();
    68         psli_g_Map.entities.push(pin);
    69         psli_g_Map.setView({center: psli_g_MapCenter, zoom: psli_g_zoomInitial});
    70 }
    71        
    72 /**************************************************************************/
    73 // JS Function used by admin script while editing category location     
    74 function psli_MapsMouseOut (e) {
    75          document.getElementById("Coordonates").innerHTML = "";
    76 }
    77        
    78 function psli_InitGuestMap()
    79 {
    80         psli_g_MapOptions = {
    81                 credentials: psli_g_BingKey,
    82                 showDashboard:false,
    83                 showMapTypeSelector:false,
    84                 showScalebar:false,
    85                 mapTypeId: Microsoft.Maps.MapTypeId.road,
    86                 center: psli_g_MapCenter,
    87                 zoom: psli_g_zoomInitial
    88         };
    89        
    90         psli_g_Map = new Microsoft.Maps.Map(document.getElementById("myMap"), psli_g_MapOptions);
    91         Microsoft.Maps.Events.addHandler(psli_g_Map, "viewchangeend", psli_ViewChangeEnd);
     48        psli_InitMap();
    9249        psli_g_Map.entities.clear();
    9350        psli_g_Map.entities.push(psli_g_ZoomEntity[psli_g_zoomInitial - 1]);
    9451}
    9552 
    96 function psli_ViewChangeEnd () {
    97         psli_g_Map.entities.clear();
    98         psli_g_Map.entities.push(psli_g_ZoomEntity[psli_g_Map.getZoom() - 1]);
     53function psli_MapsMouseOut (e) {
     54         document.getElementById("Coordonates").innerHTML = "";
    9955}
    100 
    101 
    102 /**************************************************************************/
    103 // JS Function used by admin script while editing category location
    104 function psli_CopyInitial() {
    105         psli_g_Vertice = new Array();
    106         for (var i = 0; i < psli_g_VerticeInitial.length; i++)
    107         {
    108                 psli_g_Vertice.push(psli_g_VerticeInitial[i]);
    109         }
    110 }
    111 
    112 function psli_InitCategoryMap() {
    113         if (document.getElementById("pslibingmapsentity").value == "--null--")
    114         {
    115                 document.getElementById("pslibingmapsselect").selectedIndex = 0;
    116                 psli_g_MapOptions =
    117                         {credentials: psli_g_BingKey,
    118                          showDashboard:false,
    119                          showMapTypeSelector:false,
    120                          showScalebar:false,
    121                          mapTypeId: Microsoft.Maps.MapTypeId.road,
    122                          center: new Microsoft.Maps.Location(0,0),
    123                          zoom:2
    124                         };
    125         }
    126         else
    127         {
    128                 document.getElementById("pslibingmapsselect").selectedIndex = document.getElementById("pslibingmapsaction").value;
    129                 document.getElementById("pslibingmapsbuttonstart").disabled = false;
    130                 psli_g_MapOptions =
    131                         {credentials: psli_g_BingKey,
    132                          showDashboard:false,
    133                          showMapTypeSelector:false,
    134                          showScalebar:false,
    135                          mapTypeId: Microsoft.Maps.MapTypeId.road,
    136                          center: new Microsoft.Maps.Location(document.getElementById("pslibingmapslat").value, document.getElementById("pslibingmapslon").value),
    137                          zoom: parseInt(document.getElementById("pslibingmapsaction").value)
    138                         };
    139                
    140         }
    141        
    142         psli_g_Map = new Microsoft.Maps.Map(document.getElementById("pslibingmapsmap"), psli_g_MapOptions);
    143         Microsoft.Maps.Events.addHandler(psli_g_Map, "click", psli_MapClick);   
    144 }
    145 
    146 function psli_SaveZone() {
    147         var psli_l_ZoneCoordonates = ""
    148         var psli_l_EntityId = document.getElementById("pslibingmapsentity").value;
    149         if (psli_g_Vertice.length > 0)
    150         {
    151                 var psli_l_LastPoint = new Microsoft.Maps.Location(psli_g_Vertice[0].latitude, psli_g_Vertice[0].longitude);
    152                 psli_g_Vertice.push(psli_l_LastPoint);
    153                 var psli_l_Polygon = new Microsoft.Maps.Polygon(psli_g_Vertice,{fillColor: psli_g_PolygonColor, strokeColor: psli_g_PolygonColor});
    154                 psli_g_Map.entities.clear();
    155                 psli_g_Map.entities.push(psli_l_Polygon);
    156                 for (var i = 0; i < psli_g_Vertice.length ; i++)
    157                 {
    158                         if (i != 0)
    159                                 psli_l_ZoneCoordonates += ",";
    160                         psli_l_ZoneCoordonates += "(" + psli_l_EntityId + ", " + psli_g_Vertice[i].latitude + ", " + psli_g_Vertice[i].longitude + ")";
    161                 }
    162                 psli_l_ZoneCoordonates += ";"
    163         }
    164         else
    165         {
    166                 psli_l_ZoneCoordonates = "delete all";
    167         }
    168         document.getElementById("pslibingmapszone").value = psli_l_ZoneCoordonates;
    169         document.getElementById("pslibingmapsbuttonall").disabled = true;
    170         document.getElementById("pslibingmapsbuttondelete").disabled = true;
    171         document.getElementById("pslibingmapsbuttonsave").disabled = true;
    172         document.getElementById("pslibingmapsbuttoncancel").disabled = true;
    173         document.getElementById("pslibingmapsbuttonstart").disabled = false;   
    174 
    175         psli_g_ZoneDraw = false;       
    176 }
    177 
    178 function psli_CancelZone() {
    179         psli_g_ZoneDraw = false;
    180         psli_CopyInitial();
    181         var psli_l_Polygon = new Microsoft.Maps.Polygon(psli_g_Vertice,{fillColor: psli_g_PolygonColor, strokeColor: psli_g_PolygonColor});
    182         psli_g_Map.entities.clear();
    183         psli_g_Map.entities.push(psli_l_Polygon);
    184         document.getElementById("pslibingmapsbuttonall").disabled = true;
    185         document.getElementById("pslibingmapsbuttondelete").disabled = true;
    186         document.getElementById("pslibingmapsbuttonsave").disabled = true;
    187         document.getElementById("pslibingmapsbuttoncancel").disabled = true;
    188         document.getElementById("pslibingmapsbuttonstart").disabled = false;   
    189        
    190 }
    191 
    192 function psli_StartZone() {
    193         psli_g_ZoneDraw = true;
    194         if (psli_g_VerticeInitial.length > 0)
    195         {
    196                 psli_CopyInitial();
    197                 var psli_l_Polygon = new Microsoft.Maps.Polygon(psli_g_Vertice,{fillColor: psli_g_PolygonColor, strokeColor: psli_g_PolygonColor});
    198                 psli_g_Map.entities.clear();
    199                 psli_g_Map.entities.push(psli_l_Polygon);
    200         }
    201         else
    202         {
    203                 psli_g_Vertice = new Array();
    204                 psli_g_Map.entities.clear();
    205         }
    206         document.getElementById("pslibingmapsbuttonall").disabled = false;
    207         document.getElementById("pslibingmapsbuttondelete").disabled = false;
    208         document.getElementById("pslibingmapsbuttonsave").disabled = false;
    209         document.getElementById("pslibingmapsbuttoncancel").disabled = false;
    210         document.getElementById("pslibingmapsbuttonstart").disabled = true;
    211        
    212 }
    213                                
    214 function psli_DeleteLast() {
    215         if (psli_g_Vertice.length > 0)
    216         {
    217                 psli_g_Vertice.pop();
    218                 var psli_l_Polygon = new Microsoft.Maps.Polygon(psli_g_Vertice,{fillColor: psli_g_PolygonColor, strokeColor: psli_g_PolygonColor});
    219                 psli_g_Map.entities.clear();
    220                 psli_g_Map.entities.push(psli_l_Polygon);
    221         }
    222 }
    223 
    224 function psli_DeleteAll() {
    225         psli_g_Vertice = new Array();
    226         psli_g_Map.entities.clear();
    227 }
    228 
    229 function psli_SetMinimum() {
    230         document.getElementById("pslibingmapszoommin").value = psli_g_Map.getZoom();
    231 }
    232 
    233 function psli_SetMaximum() {
    234         document.getElementById("pslibingmapszoommax").value = psli_g_Map.getZoom();
    235 }
    236 
    237 function psli_SetAction() {
    238         document.getElementById("pslibingmapsselect").selectedIndex = psli_g_Map.getZoom();
    239 }
    240 
    241 function psli_MapClick(e) {
    242         if (e.targetType == "map") {
    243                 if (psli_g_ZoneDraw)
    244                 {       
    245                         var psli_l_Point = new Microsoft.Maps.Point(e.getX(), e.getY());
    246                         var psli_l_Loc = e.target.tryPixelToLocation(psli_l_Point);
    247                         psli_g_Vertice.push(psli_l_Loc);
    248                         var zone = new Microsoft.Maps.Polygon(psli_g_Vertice,{fillColor: psli_g_PolygonColor, strokeColor: psli_g_PolygonColor});
    249                         psli_g_Map.entities.clear();
    250                         psli_g_Map.entities.push(zone);
    251                 }
    252                 else
    253                 {
    254                         var psli_l_Point = new Microsoft.Maps.Point(e.getX(), e.getY());
    255                         var psli_l_Loc = e.target.tryPixelToLocation(psli_l_Point);
    256                        
    257                         document.getElementById("pslibingmapslat").value= psli_l_Loc.latitude;
    258                         document.getElementById("pslibingmapslon").value= psli_l_Loc.longitude;
    259                         document.getElementById("pslibingmapsselect").selectedIndex = psli_g_Map.getZoom();
    260                         var pin = new Microsoft.Maps.Pushpin(psli_l_Loc);
    261                         psli_g_Map.entities.clear();
    262                         psli_g_Map.entities.push(pin);
    263                 }
    264         }
    265 }
    266 
    267 
Note: See TracChangeset for help on using the changeset viewer.