source: trunk/src/map/inc/nodemapWL.js@ 7833

Last change on this file since 7833 was 7833, checked in by ddboer, 15 years ago

Clusters now get a red highlight behind them

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