[7722] | 1 | //Declaring some variables we will be using
|
---|
[7802] | 2 | var gmap_search_state = false;
|
---|
[7809] | 3 |
|
---|
[7694] | 4 | var map;
|
---|
[7825] | 5 | var markerArray = [];
|
---|
| 6 | var circleArray = [];
|
---|
| 7 | var polygons_on_map_array = [];
|
---|
[7734] | 8 | var xmlhttp;
|
---|
| 9 | var targetDiv = "infotop";
|
---|
[7786] | 10 | var selected = false;
|
---|
[7756] | 11 | var overNode;
|
---|
[7809] | 12 | var markerSelected = "";
|
---|
[7832] | 13 | var highlightCircle;
|
---|
| 14 | var currentMarker;
|
---|
[7665] | 15 |
|
---|
[7778] | 16 |
|
---|
[7825] | 17 |
|
---|
[7734] | 18 | //This function is called from index.php
|
---|
| 19 | function 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
|
---|
| 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) {
|
---|
[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] | 98 | function 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] | 135 | function 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] | 154 | function 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
|
---|
| 162 | function 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
|
---|
| 221 | function 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] | 255 | function mouseOutCluster(markers)
|
---|
[7809] | 256 | {
|
---|
[7813] | 257 | removeAllPolgygons();
|
---|
[7812] | 258 | }
|
---|
| 259 |
|
---|
[7824] | 260 | function mapZoomed()
|
---|
| 261 | {
|
---|
[7835] | 262 |
|
---|
[7825] | 263 | if(!markerSelected == "")
|
---|
| 264 | {
|
---|
| 265 | markerSelected.setImage("../img/sleutelGroenSelected.png");
|
---|
| 266 | }
|
---|
[7835] | 267 |
|
---|
| 268 | if (highlightCircle) {
|
---|
| 269 | map.removeOverlay(highlightCircle);
|
---|
| 270 | }
|
---|
[7824] | 271 | }
|
---|
| 272 |
|
---|
[7812] | 273 | function removeAllPolgygons()
|
---|
| 274 | {
|
---|
| 275 | for(var i=0; i<polygons_on_map_array.length; i++)
|
---|
| 276 | {
|
---|
| 277 | var currentpolygon = polygons_on_map_array[i];
|
---|
| 278 | map.removeOverlay(currentpolygon);
|
---|
[7798] | 279 |
|
---|
| 280 | }
|
---|
[7812] | 281 | polygons_on_map_array.clear();
|
---|
[7798] | 282 | }
|
---|
| 283 |
|
---|
[7756] | 284 | function select()
|
---|
[7738] | 285 | {
|
---|
[7756] | 286 | selected = true;
|
---|
[7738] | 287 | }
|
---|
[7734] | 288 |
|
---|
[7756] | 289 | function deSelect()
|
---|
| 290 | {
|
---|
[7832] | 291 | map.removeOverlay(highlightCircle);
|
---|
[7809] | 292 | selected = false;
|
---|
| 293 | loadXMLDoc("inc/node_info.php");
|
---|
| 294 | if(!markerSelected == "")
|
---|
[7824] | 295 | {
|
---|
[7830] | 296 | for(var i=0; i<markers.length; i++)
|
---|
| 297 | {
|
---|
| 298 | var currentmarker = markers[i];
|
---|
| 299 | if(currentmarker.name[0] == markerSelected.getTitle())
|
---|
| 300 | {
|
---|
| 301 | if(currentmarker.status[0] == "up")
|
---|
| 302 | {
|
---|
| 303 | markerSelected.setImage("../img/sleutelGroen.png");
|
---|
| 304 | }
|
---|
| 305 | else
|
---|
| 306 | {
|
---|
| 307 | markerSelected.setImage("../img/sleutelRood.png");
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
[7824] | 312 | markerSelected = "";
|
---|
| 313 | }
|
---|
[7809] | 314 |
|
---|
[7812] | 315 | removeAllPolgygons();
|
---|
[7800] | 316 |
|
---|
[7756] | 317 | }
|
---|
[7738] | 318 |
|
---|
[7786] | 319 | function removeOtherSelect()
|
---|
| 320 | {
|
---|
| 321 | for(var i=0; i<markerArray.length; i++)
|
---|
| 322 | {
|
---|
| 323 | currentmarker = markerArray[i];
|
---|
| 324 | currentmarker.setImage("../sleutelGroen.png");
|
---|
| 325 | }
|
---|
| 326 | return true;
|
---|
| 327 | }
|
---|
| 328 |
|
---|
[7734] | 329 | //Code from w3schools. http://www.w3schools.com/dom/dom_http.asp
|
---|
[7805] | 330 | function loadXMLDoc(url, targetDiv)
|
---|
[7734] | 331 | {
|
---|
| 332 | xmlhttp=null;
|
---|
| 333 | if (window.XMLHttpRequest)
|
---|
| 334 | {// code for Firefox, Opera, IE7, etc.
|
---|
| 335 | xmlhttp=new XMLHttpRequest();
|
---|
| 336 | }
|
---|
| 337 | else if (window.ActiveXObject)
|
---|
| 338 | {// code for IE6, IE5
|
---|
| 339 | xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
|
---|
| 340 | }
|
---|
| 341 | if (xmlhttp!=null)
|
---|
| 342 | {
|
---|
[7805] | 343 | xmlhttp.onreadystatechange=state_Change();
|
---|
[7734] | 344 | xmlhttp.open("GET",url,true);
|
---|
| 345 | xmlhttp.send(null);
|
---|
| 346 | }
|
---|
| 347 | else
|
---|
| 348 | {
|
---|
| 349 | alert("Your browser does not support XMLHTTP.");
|
---|
| 350 | }
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | function state_Change()
|
---|
| 354 | {
|
---|
| 355 | if (xmlhttp.readyState==4)
|
---|
| 356 | {// 4 = "loaded"
|
---|
| 357 | if (xmlhttp.status==200)
|
---|
| 358 | {// 200 = "OK"
|
---|
| 359 | document.getElementById(targetDiv).innerHTML=xmlhttp.responseText;
|
---|
| 360 | }
|
---|
| 361 | else
|
---|
| 362 | {
|
---|
| 363 | alert("Problem retrieving data:" + xmlhttp.statusText);
|
---|
| 364 | }
|
---|
| 365 | }
|
---|
| 366 | }
|
---|
[7778] | 367 |
|
---|
[7805] | 368 | function loadSuggest(url)
|
---|
| 369 | {
|
---|
| 370 | xmlhttp=null;
|
---|
| 371 | if (window.XMLHttpRequest)
|
---|
| 372 | {// code for Firefox, Opera, IE7, etc.
|
---|
| 373 | xmlhttp=new XMLHttpRequest();
|
---|
| 374 | }
|
---|
| 375 | else if (window.ActiveXObject)
|
---|
| 376 | {// code for IE6, IE5
|
---|
| 377 | xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
|
---|
| 378 | }
|
---|
| 379 | if (xmlhttp!=null)
|
---|
| 380 | {
|
---|
| 381 | xmlhttp.onreadystatechange=state_ChangeSuggest;
|
---|
| 382 | xmlhttp.open("GET",url,true);
|
---|
| 383 | xmlhttp.send(null);
|
---|
| 384 | }
|
---|
| 385 | else
|
---|
| 386 | {
|
---|
| 387 | alert("Your browser does not support XMLHTTP.");
|
---|
| 388 | }
|
---|
| 389 | }
|
---|
| 390 |
|
---|
| 391 | function state_ChangeSuggest()
|
---|
| 392 | {
|
---|
| 393 | if (xmlhttp.readyState==4)
|
---|
| 394 | {// 4 = "loaded"
|
---|
| 395 | if (xmlhttp.status==200)
|
---|
| 396 | {// 200 = "OK"
|
---|
| 397 | document.getElementById("searchlist").innerHTML=xmlhttp.responseText;
|
---|
| 398 | }
|
---|
| 399 | else
|
---|
| 400 | {
|
---|
| 401 | alert("Problem retrieving data:" + xmlhttp.statusText);
|
---|
| 402 | }
|
---|
| 403 | }
|
---|
| 404 | }
|
---|
| 405 |
|
---|
| 406 | function suggestMarkers(value)
|
---|
| 407 | {
|
---|
[7827] | 408 | loadSuggest("inc/suggestions.php?value="+value+"&a="+Math.random());
|
---|
[7805] | 409 | }
|
---|
[7778] | 410 |
|
---|
[7820] | 411 | function goToMarker(value)
|
---|
| 412 | {
|
---|
| 413 | for(var i=0; i<markerArray.length; i++)
|
---|
| 414 | {
|
---|
| 415 | var name = markerArray[i].getTitle();
|
---|
| 416 |
|
---|
| 417 | if(name == value)
|
---|
| 418 | {
|
---|
| 419 | map.setCenter(markerArray[i].getLatLng(), 15);
|
---|
[7827] | 420 | loadXMLDoc("inc/node_info.php?type=single&name="+value+"&a="+Math.random())
|
---|
[7820] | 421 | }
|
---|
| 422 | }
|
---|
| 423 | }
|
---|
| 424 |
|
---|
[7816] | 425 | function toggleGoogleSearchMap()
|
---|
| 426 | {
|
---|
| 427 | if(gmap_search_state)
|
---|
| 428 | {
|
---|
| 429 | gmap_search_state = false;
|
---|
| 430 | }
|
---|
| 431 | else
|
---|
| 432 | {
|
---|
| 433 | gmap_search_state = true;
|
---|
| 434 | }
|
---|
| 435 |
|
---|
| 436 | if(gmap_search_state)
|
---|
| 437 | {
|
---|
| 438 | map.enableGoogleBar();
|
---|
| 439 | }
|
---|
| 440 |
|
---|
| 441 | if(!gmap_search_state)
|
---|
| 442 | {
|
---|
| 443 | map.disableGoogleBar();
|
---|
| 444 | }
|
---|
| 445 | }
|
---|
[7778] | 446 |
|
---|
[7801] | 447 |
|
---|
[7816] | 448 |
|
---|