1 | //Declaring some variables we will be using
|
---|
2 | var gmap_search_state = false;
|
---|
3 |
|
---|
4 | var map;
|
---|
5 | var markerArray = [];
|
---|
6 | var circleArray = [];
|
---|
7 | var polygons_on_map_array = [];
|
---|
8 | var xmlhttp;
|
---|
9 | var targetDiv = "infotop";
|
---|
10 | var selected = false;
|
---|
11 | var overNode;
|
---|
12 | var markerSelected = "";
|
---|
13 | var highlightCircle;
|
---|
14 | var currentMarker;
|
---|
15 |
|
---|
16 |
|
---|
17 |
|
---|
18 | //This function is called from index.php
|
---|
19 | function initialize_map() {
|
---|
20 | //We will only do this function if the browser is compatible
|
---|
21 | if (GBrowserIsCompatible())
|
---|
22 | {
|
---|
23 | //Adding the google map into the div called #mapcanvas
|
---|
24 | map = new GMap2(document.getElementById("mapcanvas"), {googleBarOptions : {style : "new"}});
|
---|
25 | //Center the map on Leiden
|
---|
26 | map.setCenter(new GLatLng(52.162687, 4.493294), 11); // Vars should go to config
|
---|
27 | map.setUIToDefault();
|
---|
28 |
|
---|
29 |
|
---|
30 | /*
|
---|
31 | * Go through the array 'markers' (Declared in index.php) and add a marker for each marker stored in the array
|
---|
32 | * using our addMarker function.
|
---|
33 | * If the latLng of the marker is both 0
|
---|
34 | */
|
---|
35 | for (var i=0; i<markers.length; i++) {
|
---|
36 | var current = markers[i];
|
---|
37 | if(current.latitude[0] > 0 || current.latitude[0] < 0)
|
---|
38 | {
|
---|
39 | addMarker(current, i);
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | GEvent.addListener(map, "click", function() {
|
---|
44 | if(!overNode == true)
|
---|
45 | deSelect();
|
---|
46 | });
|
---|
47 |
|
---|
48 | GEvent.addListener(map, "zoomend", function() {
|
---|
49 | mapZoomed();
|
---|
50 | });
|
---|
51 |
|
---|
52 | suggestMarkers("");
|
---|
53 |
|
---|
54 | new MarkerClusterer(map, markerArray);
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | //This function will contain the displaying and not displaying of nodes on the map
|
---|
59 | function toggleMyKml() {
|
---|
60 |
|
---|
61 | }
|
---|
62 |
|
---|
63 | //This function adds a marker with an object from our 'marker'array defined in index.php
|
---|
64 | function addMarker(current, i) {
|
---|
65 | var latitude = Number(current.latitude[0]);
|
---|
66 | var longitude = Number(current.longitude[0]);
|
---|
67 |
|
---|
68 | var displayIcon;
|
---|
69 | var currentstatus = current.status[0];
|
---|
70 | if(currentstatus == "up")
|
---|
71 | {
|
---|
72 | displayIcon = greenIcon;
|
---|
73 | }
|
---|
74 | else
|
---|
75 | {
|
---|
76 | displayIcon = redIcon;
|
---|
77 | }
|
---|
78 |
|
---|
79 | var marker = new GMarker(new GLatLng(current.latitude[0], current.longitude[0]), {title: current.name[0], icon: displayIcon});
|
---|
80 |
|
---|
81 | //Added mouseover listener that calls on our mouseOver function when the mouse moves over a marker on the map
|
---|
82 | GEvent.addListener(marker, 'mouseover', function() {
|
---|
83 | mouseOverNode(current.id, current.name[0],latitude, longitude);
|
---|
84 | });
|
---|
85 | GEvent.addListener(marker, 'click', function() {
|
---|
86 | currentMarker = marker;
|
---|
87 | highlightCurrentMarker();
|
---|
88 | mouseClickNode(current.id, current.name[0], marker);
|
---|
89 | });
|
---|
90 | GEvent.addListener(marker, 'mouseout', function() {
|
---|
91 | mouseOutNode(current.id, current.name[0]);
|
---|
92 | });
|
---|
93 |
|
---|
94 | markerArray.push(marker);
|
---|
95 | //circleArray.push(circle);
|
---|
96 | return marker;
|
---|
97 | }
|
---|
98 |
|
---|
99 | //Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
|
---|
100 | function mouseClickNode(id, name, marker)
|
---|
101 | {
|
---|
102 | if(selected == true)
|
---|
103 | {
|
---|
104 | deSelect();
|
---|
105 | markerSelected = "";
|
---|
106 | }
|
---|
107 |
|
---|
108 | if(markerSelected == marker)
|
---|
109 | {
|
---|
110 | deSelect();
|
---|
111 | markerSelected = "";
|
---|
112 | }
|
---|
113 | else
|
---|
114 | {
|
---|
115 | selected = true;
|
---|
116 | markerSelected = marker;
|
---|
117 | for(var i=0; i<markers.length; i++)
|
---|
118 | {
|
---|
119 | var currentmarker = markers[i];
|
---|
120 | if(currentmarker.name[0] == marker.getTitle())
|
---|
121 | {
|
---|
122 | if(currentmarker.status[0] == "up")
|
---|
123 | {
|
---|
124 | marker.setImage("../img/sleutelGroenSelected.png");
|
---|
125 | }
|
---|
126 | else
|
---|
127 | {
|
---|
128 | marker.setImage("../img/sleutelRoodSelected.png");
|
---|
129 | }
|
---|
130 |
|
---|
131 | }
|
---|
132 | }
|
---|
133 | loadXMLDoc("inc/node_info.php?type=single&name="+name+"&a="+Math.random());
|
---|
134 | }
|
---|
135 | }
|
---|
136 | //Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
|
---|
137 | function mouseOverNode(id, name, latitude, longitude)
|
---|
138 | {
|
---|
139 | overNode = true;
|
---|
140 | if(!selected == true)
|
---|
141 | {
|
---|
142 |
|
---|
143 | drawCircle(latitude, longitude,0.1, "#6C3", 1, 0.75, "#0F0",.2, 200);
|
---|
144 | polygons_on_map_array.push(polygon);
|
---|
145 | map.addOverlay(polygon);
|
---|
146 |
|
---|
147 | loadXMLDoc("inc/node_info.php?type=single&name="+name+"&a="+Math.random());//Path should be in config
|
---|
148 |
|
---|
149 | /*
|
---|
150 | *Hieronder verdergaan met dekking
|
---|
151 | */
|
---|
152 |
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | function mouseOutNode(id, name)
|
---|
157 | {
|
---|
158 | overNode = false;
|
---|
159 | map.removeOverlay(polygon);
|
---|
160 |
|
---|
161 | }
|
---|
162 |
|
---|
163 | //Our mouseover function for Cluster nodes. 'markers' is an array containing all markers within the cluster
|
---|
164 | function mouseOverCluster(markers)
|
---|
165 | {
|
---|
166 | if(!selected == true)
|
---|
167 | {
|
---|
168 | //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
|
---|
169 | var markerTitles = new Array;
|
---|
170 | var markerLatLngs = new Array;
|
---|
171 |
|
---|
172 | for(var i=0; i<markers.length; i++) {
|
---|
173 |
|
---|
174 | markerTitles.push(markers[i].marker.getTitle());
|
---|
175 | markerLatLngs.push(markers[i].marker.getLatLng() );
|
---|
176 | }
|
---|
177 |
|
---|
178 |
|
---|
179 |
|
---|
180 | for (var i=0; i<markerLatLngs.length; i++)
|
---|
181 | {
|
---|
182 | latLng = String(markerLatLngs[i]);
|
---|
183 |
|
---|
184 | pos = latLng.indexOf(',');
|
---|
185 | pos2 = latLng.length-1;
|
---|
186 |
|
---|
187 | var latitude = Number(latLng.substring(1, pos) );
|
---|
188 | var longitude = Number(latLng.substring(2 + pos, pos2) );
|
---|
189 |
|
---|
190 |
|
---|
191 | drawCircle( latitude, longitude,0.1, "#6C3", 1, 0.75, "#0F0",.2);
|
---|
192 |
|
---|
193 |
|
---|
194 |
|
---|
195 | map.addOverlay(polygon);
|
---|
196 | polygons_on_map_array.push(polygon);
|
---|
197 | }
|
---|
198 |
|
---|
199 | var markerTitleSerialized;
|
---|
200 |
|
---|
201 | //start
|
---|
202 | var a_php = "";
|
---|
203 | var total = 0;
|
---|
204 |
|
---|
205 | for (var i=0; i<markerTitles.length; i++)
|
---|
206 | {
|
---|
207 | ++ total;
|
---|
208 | a_php = a_php + "s:" +
|
---|
209 | String(i).length + ":\"" + String(i) + "\";s:" +
|
---|
210 | String(markerTitles[i]).length + ":\"" + String(markerTitles[i]) + "\";";
|
---|
211 | }
|
---|
212 | a_php = "a:" + total + ":{" + a_php + "}";
|
---|
213 | //end
|
---|
214 |
|
---|
215 | loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"")
|
---|
216 | /*
|
---|
217 | *Hieronder verdergaan met dekking
|
---|
218 | */
|
---|
219 | }
|
---|
220 | }
|
---|
221 |
|
---|
222 | //Our click function for Cluster nodes. 'markers' is an array containing all markers within the cluster
|
---|
223 | function clickCluster(markers)
|
---|
224 | {
|
---|
225 | if(selected == true)
|
---|
226 | deselect();
|
---|
227 |
|
---|
228 | //Let the rest of the program know that something is selected
|
---|
229 | select();
|
---|
230 |
|
---|
231 | //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
|
---|
232 | var markerTitles = new Array;
|
---|
233 | for(var i=0; i<markers.length; i++) {
|
---|
234 | markerTitles.push(markers[i].marker.getTitle());
|
---|
235 |
|
---|
236 | }
|
---|
237 |
|
---|
238 | var markerTitleSerialized;
|
---|
239 |
|
---|
240 | //start
|
---|
241 | var a_php = "";
|
---|
242 | var total = 0;
|
---|
243 |
|
---|
244 | for (var i=0; i<markerTitles.length; i++)
|
---|
245 | {
|
---|
246 | ++ total;
|
---|
247 | a_php = a_php + "s:" +
|
---|
248 | String(i).length + ":\"" + String(i) + "\";s:" +
|
---|
249 | String(markerTitles[i]).length + ":\"" + String(markerTitles[i]) + "\";";
|
---|
250 | }
|
---|
251 | a_php = "a:" + total + ":{" + a_php + "}";
|
---|
252 | //end
|
---|
253 |
|
---|
254 | loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"&sel=selected"+"&a="+Math.random())
|
---|
255 | }
|
---|
256 |
|
---|
257 | function mouseOutCluster(markers)
|
---|
258 | {
|
---|
259 | removeAllPolgygons();
|
---|
260 | }
|
---|
261 |
|
---|
262 | function mapZoomed()
|
---|
263 | {
|
---|
264 | highlightCurrentMarker()
|
---|
265 | if(!markerSelected == "")
|
---|
266 | {
|
---|
267 | markerSelected.setImage("../img/sleutelGroenSelected.png");
|
---|
268 | }
|
---|
269 | }
|
---|
270 |
|
---|
271 | function removeAllPolgygons()
|
---|
272 | {
|
---|
273 | for(var i=0; i<polygons_on_map_array.length; i++)
|
---|
274 | {
|
---|
275 | var currentpolygon = polygons_on_map_array[i];
|
---|
276 | map.removeOverlay(currentpolygon);
|
---|
277 |
|
---|
278 | }
|
---|
279 | polygons_on_map_array.clear();
|
---|
280 | }
|
---|
281 |
|
---|
282 | function select()
|
---|
283 | {
|
---|
284 | selected = true;
|
---|
285 | }
|
---|
286 |
|
---|
287 | function deSelect()
|
---|
288 | {
|
---|
289 | map.removeOverlay(highlightCircle);
|
---|
290 | selected = false;
|
---|
291 | loadXMLDoc("inc/node_info.php");
|
---|
292 | if(!markerSelected == "")
|
---|
293 | {
|
---|
294 | for(var i=0; i<markers.length; i++)
|
---|
295 | {
|
---|
296 | var currentmarker = markers[i];
|
---|
297 | if(currentmarker.name[0] == markerSelected.getTitle())
|
---|
298 | {
|
---|
299 | if(currentmarker.status[0] == "up")
|
---|
300 | {
|
---|
301 | markerSelected.setImage("../img/sleutelGroen.png");
|
---|
302 | }
|
---|
303 | else
|
---|
304 | {
|
---|
305 | markerSelected.setImage("../img/sleutelRood.png");
|
---|
306 | }
|
---|
307 |
|
---|
308 | }
|
---|
309 | }
|
---|
310 | markerSelected = "";
|
---|
311 | }
|
---|
312 |
|
---|
313 | removeAllPolgygons();
|
---|
314 |
|
---|
315 | }
|
---|
316 |
|
---|
317 | function removeOtherSelect()
|
---|
318 | {
|
---|
319 | for(var i=0; i<markerArray.length; i++)
|
---|
320 | {
|
---|
321 | currentmarker = markerArray[i];
|
---|
322 | currentmarker.setImage("../sleutelGroen.png");
|
---|
323 | }
|
---|
324 | return true;
|
---|
325 | }
|
---|
326 |
|
---|
327 | //Code from w3schools. http://www.w3schools.com/dom/dom_http.asp
|
---|
328 | function loadXMLDoc(url, targetDiv)
|
---|
329 | {
|
---|
330 | xmlhttp=null;
|
---|
331 | if (window.XMLHttpRequest)
|
---|
332 | {// code for Firefox, Opera, IE7, etc.
|
---|
333 | xmlhttp=new XMLHttpRequest();
|
---|
334 | }
|
---|
335 | else if (window.ActiveXObject)
|
---|
336 | {// code for IE6, IE5
|
---|
337 | xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
|
---|
338 | }
|
---|
339 | if (xmlhttp!=null)
|
---|
340 | {
|
---|
341 | xmlhttp.onreadystatechange=state_Change();
|
---|
342 | xmlhttp.open("GET",url,true);
|
---|
343 | xmlhttp.send(null);
|
---|
344 | }
|
---|
345 | else
|
---|
346 | {
|
---|
347 | alert("Your browser does not support XMLHTTP.");
|
---|
348 | }
|
---|
349 | }
|
---|
350 |
|
---|
351 | function state_Change()
|
---|
352 | {
|
---|
353 | if (xmlhttp.readyState==4)
|
---|
354 | {// 4 = "loaded"
|
---|
355 | if (xmlhttp.status==200)
|
---|
356 | {// 200 = "OK"
|
---|
357 | document.getElementById(targetDiv).innerHTML=xmlhttp.responseText;
|
---|
358 | }
|
---|
359 | else
|
---|
360 | {
|
---|
361 | alert("Problem retrieving data:" + xmlhttp.statusText);
|
---|
362 | }
|
---|
363 | }
|
---|
364 | }
|
---|
365 |
|
---|
366 | function loadSuggest(url)
|
---|
367 | {
|
---|
368 | xmlhttp=null;
|
---|
369 | if (window.XMLHttpRequest)
|
---|
370 | {// code for Firefox, Opera, IE7, etc.
|
---|
371 | xmlhttp=new XMLHttpRequest();
|
---|
372 | }
|
---|
373 | else if (window.ActiveXObject)
|
---|
374 | {// code for IE6, IE5
|
---|
375 | xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
|
---|
376 | }
|
---|
377 | if (xmlhttp!=null)
|
---|
378 | {
|
---|
379 | xmlhttp.onreadystatechange=state_ChangeSuggest;
|
---|
380 | xmlhttp.open("GET",url,true);
|
---|
381 | xmlhttp.send(null);
|
---|
382 | }
|
---|
383 | else
|
---|
384 | {
|
---|
385 | alert("Your browser does not support XMLHTTP.");
|
---|
386 | }
|
---|
387 | }
|
---|
388 |
|
---|
389 | function state_ChangeSuggest()
|
---|
390 | {
|
---|
391 | if (xmlhttp.readyState==4)
|
---|
392 | {// 4 = "loaded"
|
---|
393 | if (xmlhttp.status==200)
|
---|
394 | {// 200 = "OK"
|
---|
395 | document.getElementById("searchlist").innerHTML=xmlhttp.responseText;
|
---|
396 | }
|
---|
397 | else
|
---|
398 | {
|
---|
399 | alert("Problem retrieving data:" + xmlhttp.statusText);
|
---|
400 | }
|
---|
401 | }
|
---|
402 | }
|
---|
403 |
|
---|
404 | function suggestMarkers(value)
|
---|
405 | {
|
---|
406 | loadSuggest("inc/suggestions.php?value="+value+"&a="+Math.random());
|
---|
407 | }
|
---|
408 |
|
---|
409 | function goToMarker(value)
|
---|
410 | {
|
---|
411 | for(var i=0; i<markerArray.length; i++)
|
---|
412 | {
|
---|
413 | var name = markerArray[i].getTitle();
|
---|
414 |
|
---|
415 | if(name == value)
|
---|
416 | {
|
---|
417 | map.setCenter(markerArray[i].getLatLng(), 15);
|
---|
418 | loadXMLDoc("inc/node_info.php?type=single&name="+value+"&a="+Math.random())
|
---|
419 | }
|
---|
420 | }
|
---|
421 | }
|
---|
422 |
|
---|
423 | function toggleGoogleSearchMap()
|
---|
424 | {
|
---|
425 | if(gmap_search_state)
|
---|
426 | {
|
---|
427 | gmap_search_state = false;
|
---|
428 | }
|
---|
429 | else
|
---|
430 | {
|
---|
431 | gmap_search_state = true;
|
---|
432 | }
|
---|
433 |
|
---|
434 | if(gmap_search_state)
|
---|
435 | {
|
---|
436 | map.enableGoogleBar();
|
---|
437 | }
|
---|
438 |
|
---|
439 | if(!gmap_search_state)
|
---|
440 | {
|
---|
441 | map.disableGoogleBar();
|
---|
442 | }
|
---|
443 | }
|
---|
444 |
|
---|
445 |
|
---|
446 |
|
---|