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