| 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 | mouseClickNode(current.id, current.name[0], marker);
|
|---|
| 87 | });
|
|---|
| 88 | GEvent.addListener(marker, 'mouseout', function() {
|
|---|
| 89 | mouseOutNode(current.id, current.name[0]);
|
|---|
| 90 | });
|
|---|
| 91 |
|
|---|
| 92 | markerArray.push(marker);
|
|---|
| 93 | //circleArray.push(circle);
|
|---|
| 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.
|
|---|
| 98 | function mouseClickNode(id, name, marker)
|
|---|
| 99 | {
|
|---|
| 100 | if(selected == true)
|
|---|
| 101 | {
|
|---|
| 102 | deSelect();
|
|---|
| 103 | markerSelected = "";
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | if(markerSelected == marker)
|
|---|
| 107 | {
|
|---|
| 108 | deSelect();
|
|---|
| 109 | markerSelected = "";
|
|---|
| 110 | }
|
|---|
| 111 | else
|
|---|
| 112 | {
|
|---|
| 113 | selected = true;
|
|---|
| 114 | markerSelected = marker;
|
|---|
| 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());
|
|---|
| 132 | }
|
|---|
| 133 | }
|
|---|
| 134 | //Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
|
|---|
| 135 | function mouseOverNode(id, name, latitude, longitude)
|
|---|
| 136 | {
|
|---|
| 137 | overNode = true;
|
|---|
| 138 | if(!selected == true)
|
|---|
| 139 | {
|
|---|
| 140 |
|
|---|
| 141 | drawCircle(latitude, longitude,0.1, "#6C3", 1, 0.75, "#0F0",.2, 200);
|
|---|
| 142 | polygons_on_map_array.push(polygon);
|
|---|
| 143 | map.addOverlay(polygon);
|
|---|
| 144 |
|
|---|
| 145 | loadXMLDoc("inc/node_info.php?type=single&name="+name+"&a="+Math.random());//Path should be in config
|
|---|
| 146 |
|
|---|
| 147 | /*
|
|---|
| 148 | *Hieronder verdergaan met dekking
|
|---|
| 149 | */
|
|---|
| 150 |
|
|---|
| 151 | }
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | function mouseOutNode(id, name)
|
|---|
| 155 | {
|
|---|
| 156 | overNode = false;
|
|---|
| 157 | map.removeOverlay(polygon);
|
|---|
| 158 |
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | //Our mouseover function for Cluster nodes. 'markers' is an array containing all markers within the cluster
|
|---|
| 162 | function mouseOverCluster(markers)
|
|---|
| 163 | {
|
|---|
| 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;
|
|---|
| 168 | var markerLatLngs = new Array;
|
|---|
| 169 |
|
|---|
| 170 | for(var i=0; i<markers.length; i++) {
|
|---|
| 171 |
|
|---|
| 172 | markerTitles.push(markers[i].marker.getTitle());
|
|---|
| 173 | markerLatLngs.push(markers[i].marker.getLatLng() );
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 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 |
|
|---|
| 189 | drawCircle( latitude, longitude,0.1, "#6C3", 1, 0.75, "#0F0",.2);
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 | map.addOverlay(polygon);
|
|---|
| 194 | polygons_on_map_array.push(polygon);
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 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)
|
|---|
| 222 | {
|
|---|
| 223 | if(selected == true)
|
|---|
| 224 | deselect();
|
|---|
| 225 |
|
|---|
| 226 | //Let the rest of the program know that something is selected
|
|---|
| 227 | select();
|
|---|
| 228 |
|
|---|
| 229 | //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
|
|---|
| 230 | var markerTitles = new Array;
|
|---|
| 231 | for(var i=0; i<markers.length; i++) {
|
|---|
| 232 | markerTitles.push(markers[i].marker.getTitle());
|
|---|
| 233 |
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 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 |
|
|---|
| 252 | loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"&sel=selected"+"&a="+Math.random())
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | function mouseOutCluster(markers)
|
|---|
| 256 | {
|
|---|
| 257 | removeAllPolgygons();
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | function mapZoomed()
|
|---|
| 261 | {
|
|---|
| 262 |
|
|---|
| 263 | if(!markerSelected == "")
|
|---|
| 264 | {
|
|---|
| 265 | markerSelected.setImage("../img/sleutelGroenSelected.png");
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | if (highlightCircle) {
|
|---|
| 269 | map.removeOverlay(highlightCircle);
|
|---|
| 270 | }
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 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);
|
|---|
| 279 |
|
|---|
| 280 | }
|
|---|
| 281 | polygons_on_map_array.clear();
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | function select()
|
|---|
| 285 | {
|
|---|
| 286 | selected = true;
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | function deSelect()
|
|---|
| 290 | {
|
|---|
| 291 | map.removeOverlay(highlightCircle);
|
|---|
| 292 | selected = false;
|
|---|
| 293 | loadXMLDoc("inc/node_info.php");
|
|---|
| 294 | if(!markerSelected == "")
|
|---|
| 295 | {
|
|---|
| 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 | }
|
|---|
| 312 | markerSelected = "";
|
|---|
| 313 | }
|
|---|
| 314 |
|
|---|
| 315 | removeAllPolgygons();
|
|---|
| 316 |
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 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 |
|
|---|
| 329 | //Code from w3schools. http://www.w3schools.com/dom/dom_http.asp
|
|---|
| 330 | function loadXMLDoc(url, targetDiv)
|
|---|
| 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 | {
|
|---|
| 343 | xmlhttp.onreadystatechange=state_Change();
|
|---|
| 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 | }
|
|---|
| 367 |
|
|---|
| 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 | {
|
|---|
| 408 | loadSuggest("inc/suggestions.php?value="+value+"&a="+Math.random());
|
|---|
| 409 | }
|
|---|
| 410 |
|
|---|
| 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);
|
|---|
| 420 | loadXMLDoc("inc/node_info.php?type=single&name="+value+"&a="+Math.random())
|
|---|
| 421 | }
|
|---|
| 422 | }
|
|---|
| 423 | }
|
|---|
| 424 |
|
|---|
| 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 | }
|
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|