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