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