1 | /* |
---|
2 | Plugin Name: Psli-BingMaps |
---|
3 | Author: psli |
---|
4 | Description: Maintenance function for plugin "Psli-BingMaps" |
---|
5 | */ |
---|
6 | |
---|
7 | // Global data |
---|
8 | var psli_g_PolygonColor = new Microsoft.Maps.Color(100,20,0,20); |
---|
9 | var psli_g_VerticeInitial = new Array(); |
---|
10 | var psli_g_ZoomEntity = new Array(); |
---|
11 | var psli_g_Vertice; |
---|
12 | var psli_g_ZoneDraw; |
---|
13 | var psli_g_Map; |
---|
14 | var psli_g_BingKey; |
---|
15 | var psli_g_MapOptions; |
---|
16 | var psli_g_MapCenter; |
---|
17 | var psli_g_zoomInitial; |
---|
18 | |
---|
19 | // Data for guest |
---|
20 | for (var i = 0; i < 20; i++) |
---|
21 | psli_g_ZoomEntity.push(new Microsoft.Maps.EntityCollection()); |
---|
22 | |
---|
23 | /**************************************************************************/ |
---|
24 | // JS Function used by admin script while editing category location |
---|
25 | function psli_MapsMouseOut (e) { |
---|
26 | document.getElementById("Coordonates").innerHTML = ""; |
---|
27 | } |
---|
28 | |
---|
29 | function psli_InitGuestMap() |
---|
30 | { |
---|
31 | psli_g_MapOptions = { |
---|
32 | credentials: psli_g_BingKey, |
---|
33 | showDashboard:false, |
---|
34 | showMapTypeSelector:false, |
---|
35 | showScalebar:false, |
---|
36 | mapTypeId: Microsoft.Maps.MapTypeId.road, |
---|
37 | center: psli_g_MapCenter, |
---|
38 | zoom: psli_g_zoomInitial |
---|
39 | }; |
---|
40 | |
---|
41 | psli_g_Map = new Microsoft.Maps.Map(document.getElementById("myMap"), psli_g_MapOptions); |
---|
42 | Microsoft.Maps.Events.addHandler(psli_g_Map, "viewchangeend", psli_ViewChangeEnd); |
---|
43 | psli_g_Map.entities.clear(); |
---|
44 | psli_g_Map.entities.push(psli_g_ZoomEntity[psli_g_zoomInitial - 1]); |
---|
45 | } |
---|
46 | |
---|
47 | function psli_ViewChangeEnd () { |
---|
48 | psli_g_Map.entities.clear(); |
---|
49 | psli_g_Map.entities.push(psli_g_ZoomEntity[psli_g_Map.getZoom() - 1]); |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | /**************************************************************************/ |
---|
54 | // JS Function used by admin script while editing category location |
---|
55 | function psli_CopyInitial() { |
---|
56 | psli_g_Vertice = new Array(); |
---|
57 | for (var i = 0; i < psli_g_VerticeInitial.length; i++) |
---|
58 | { |
---|
59 | psli_g_Vertice.push(psli_g_VerticeInitial[i]); |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | function psli_InitCategoryMap() { |
---|
64 | if (document.getElementById("pslibingmapsentity").value == "--null--") |
---|
65 | { |
---|
66 | document.getElementById("pslibingmapsselect").selectedIndex = 0; |
---|
67 | psli_g_MapOptions = |
---|
68 | {credentials: psli_g_BingKey, |
---|
69 | showDashboard:false, |
---|
70 | showMapTypeSelector:false, |
---|
71 | showScalebar:false, |
---|
72 | mapTypeId: Microsoft.Maps.MapTypeId.road, |
---|
73 | center: new Microsoft.Maps.Location(0,0), |
---|
74 | zoom:2 |
---|
75 | }; |
---|
76 | } |
---|
77 | else |
---|
78 | { |
---|
79 | document.getElementById("pslibingmapsselect").selectedIndex = document.getElementById("pslibingmapsaction").value; |
---|
80 | document.getElementById("pslibingmapsbuttonstart").disabled = false; |
---|
81 | psli_g_MapOptions = |
---|
82 | {credentials: psli_g_BingKey, |
---|
83 | showDashboard:false, |
---|
84 | showMapTypeSelector:false, |
---|
85 | showScalebar:false, |
---|
86 | mapTypeId: Microsoft.Maps.MapTypeId.road, |
---|
87 | center: new Microsoft.Maps.Location(document.getElementById("pslibingmapslat").value, document.getElementById("pslibingmapslon").value), |
---|
88 | zoom: parseInt(document.getElementById("pslibingmapsaction").value) |
---|
89 | }; |
---|
90 | |
---|
91 | } |
---|
92 | |
---|
93 | psli_g_Map = new Microsoft.Maps.Map(document.getElementById("pslibingmapsmap"), psli_g_MapOptions); |
---|
94 | Microsoft.Maps.Events.addHandler(psli_g_Map, "click", psli_MapClick); |
---|
95 | } |
---|
96 | |
---|
97 | function psli_SaveZone() { |
---|
98 | var psli_l_ZoneCoordonates = "" |
---|
99 | var psli_l_EntityId = document.getElementById("pslibingmapsentity").value; |
---|
100 | if (psli_g_Vertice.length > 0) |
---|
101 | { |
---|
102 | var psli_l_LastPoint = new Microsoft.Maps.Location(psli_g_Vertice[0].latitude, psli_g_Vertice[0].longitude); |
---|
103 | psli_g_Vertice.push(psli_l_LastPoint); |
---|
104 | var psli_l_Polygon = new Microsoft.Maps.Polygon(psli_g_Vertice,{fillColor: psli_g_PolygonColor, strokeColor: psli_g_PolygonColor}); |
---|
105 | psli_g_Map.entities.clear(); |
---|
106 | psli_g_Map.entities.push(psli_l_Polygon); |
---|
107 | for (var i = 0; i < psli_g_Vertice.length ; i++) |
---|
108 | { |
---|
109 | if (i != 0) |
---|
110 | psli_l_ZoneCoordonates += ","; |
---|
111 | psli_l_ZoneCoordonates += "(" + psli_l_EntityId + ", " + psli_g_Vertice[i].latitude + ", " + psli_g_Vertice[i].longitude + ")"; |
---|
112 | } |
---|
113 | psli_l_ZoneCoordonates += ";" |
---|
114 | } |
---|
115 | else |
---|
116 | { |
---|
117 | psli_l_ZoneCoordonates = "delete all"; |
---|
118 | } |
---|
119 | document.getElementById("pslibingmapszone").value = psli_l_ZoneCoordonates; |
---|
120 | document.getElementById("pslibingmapsbuttonall").disabled = true; |
---|
121 | document.getElementById("pslibingmapsbuttondelete").disabled = true; |
---|
122 | document.getElementById("pslibingmapsbuttonsave").disabled = true; |
---|
123 | document.getElementById("pslibingmapsbuttoncancel").disabled = true; |
---|
124 | document.getElementById("pslibingmapsbuttonstart").disabled = false; |
---|
125 | |
---|
126 | psli_g_ZoneDraw = false; |
---|
127 | } |
---|
128 | |
---|
129 | function psli_CancelZone() { |
---|
130 | psli_g_ZoneDraw = false; |
---|
131 | psli_CopyInitial(); |
---|
132 | var psli_l_Polygon = new Microsoft.Maps.Polygon(psli_g_Vertice,{fillColor: psli_g_PolygonColor, strokeColor: psli_g_PolygonColor}); |
---|
133 | psli_g_Map.entities.clear(); |
---|
134 | psli_g_Map.entities.push(psli_l_Polygon); |
---|
135 | document.getElementById("pslibingmapsbuttonall").disabled = true; |
---|
136 | document.getElementById("pslibingmapsbuttondelete").disabled = true; |
---|
137 | document.getElementById("pslibingmapsbuttonsave").disabled = true; |
---|
138 | document.getElementById("pslibingmapsbuttoncancel").disabled = true; |
---|
139 | document.getElementById("pslibingmapsbuttonstart").disabled = false; |
---|
140 | |
---|
141 | } |
---|
142 | |
---|
143 | function psli_StartZone() { |
---|
144 | psli_g_ZoneDraw = true; |
---|
145 | if (psli_g_VerticeInitial.length > 0) |
---|
146 | { |
---|
147 | psli_CopyInitial(); |
---|
148 | var psli_l_Polygon = new Microsoft.Maps.Polygon(psli_g_Vertice,{fillColor: psli_g_PolygonColor, strokeColor: psli_g_PolygonColor}); |
---|
149 | psli_g_Map.entities.clear(); |
---|
150 | psli_g_Map.entities.push(psli_l_Polygon); |
---|
151 | } |
---|
152 | else |
---|
153 | { |
---|
154 | psli_g_Vertice = new Array(); |
---|
155 | psli_g_Map.entities.clear(); |
---|
156 | } |
---|
157 | document.getElementById("pslibingmapsbuttonall").disabled = false; |
---|
158 | document.getElementById("pslibingmapsbuttondelete").disabled = false; |
---|
159 | document.getElementById("pslibingmapsbuttonsave").disabled = false; |
---|
160 | document.getElementById("pslibingmapsbuttoncancel").disabled = false; |
---|
161 | document.getElementById("pslibingmapsbuttonstart").disabled = true; |
---|
162 | |
---|
163 | } |
---|
164 | |
---|
165 | function psli_DeleteLast() { |
---|
166 | if (psli_g_Vertice.length > 0) |
---|
167 | { |
---|
168 | psli_g_Vertice.pop(); |
---|
169 | var psli_l_Polygon = new Microsoft.Maps.Polygon(psli_g_Vertice,{fillColor: psli_g_PolygonColor, strokeColor: psli_g_PolygonColor}); |
---|
170 | psli_g_Map.entities.clear(); |
---|
171 | psli_g_Map.entities.push(psli_l_Polygon); |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | function psli_DeleteAll() { |
---|
176 | psli_g_Vertice = new Array(); |
---|
177 | psli_g_Map.entities.clear(); |
---|
178 | } |
---|
179 | |
---|
180 | function psli_SetMinimum() { |
---|
181 | document.getElementById("pslibingmapszoommin").value = psli_g_Map.getZoom(); |
---|
182 | } |
---|
183 | |
---|
184 | function psli_SetMaximum() { |
---|
185 | document.getElementById("pslibingmapszoommax").value = psli_g_Map.getZoom(); |
---|
186 | } |
---|
187 | |
---|
188 | function psli_SetAction() { |
---|
189 | document.getElementById("pslibingmapsselect").selectedIndex = psli_g_Map.getZoom(); |
---|
190 | } |
---|
191 | |
---|
192 | function psli_MapClick(e) { |
---|
193 | if (e.targetType == "map") { |
---|
194 | if (psli_g_ZoneDraw) |
---|
195 | { |
---|
196 | var psli_l_Point = new Microsoft.Maps.Point(e.getX(), e.getY()); |
---|
197 | var psli_l_Loc = e.target.tryPixelToLocation(psli_l_Point); |
---|
198 | psli_g_Vertice.push(psli_l_Loc); |
---|
199 | var zone = new Microsoft.Maps.Polygon(psli_g_Vertice,{fillColor: psli_g_PolygonColor, strokeColor: psli_g_PolygonColor}); |
---|
200 | psli_g_Map.entities.clear(); |
---|
201 | psli_g_Map.entities.push(zone); |
---|
202 | } |
---|
203 | else |
---|
204 | { |
---|
205 | var psli_l_Point = new Microsoft.Maps.Point(e.getX(), e.getY()); |
---|
206 | var psli_l_Loc = e.target.tryPixelToLocation(psli_l_Point); |
---|
207 | |
---|
208 | document.getElementById("pslibingmapslat").value= psli_l_Loc.latitude; |
---|
209 | document.getElementById("pslibingmapslon").value= psli_l_Loc.longitude; |
---|
210 | document.getElementById("pslibingmapsselect").selectedIndex = psli_g_Map.getZoom(); |
---|
211 | var pin = new Microsoft.Maps.Pushpin(psli_l_Loc); |
---|
212 | psli_g_Map.entities.clear(); |
---|
213 | psli_g_Map.entities.push(pin); |
---|
214 | } |
---|
215 | } |
---|
216 | } |
---|
217 | |
---|
218 | |
---|