1 | //Declaring some variables we will be using
|
---|
2 | var gmap_search_state = false;
|
---|
3 |
|
---|
4 | var map;
|
---|
5 | var markerArray = new Array();
|
---|
6 | var circleArray = new Array();
|
---|
7 | var xmlhttp;
|
---|
8 | var targetDiv = "infotop";
|
---|
9 | var selected = false;
|
---|
10 | var overNode;
|
---|
11 | var markerSelected = "";
|
---|
12 | var polygons_on_map_array = new Array();
|
---|
13 |
|
---|
14 |
|
---|
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
|
---|
20 | map = new GMap2(document.getElementById("mapcanvas"), {googleBarOptions : {style : "new",}});
|
---|
21 | //Center the map on Leiden
|
---|
22 | map.setCenter(new GLatLng(52.162687, 4.493294), 11); // Vars should go to config
|
---|
23 | map.setUIToDefault();
|
---|
24 |
|
---|
25 |
|
---|
26 |
|
---|
27 | //Go through the array 'markers' (Declared in index.php) and add a marker for each marker stored in the array using our addMarker function
|
---|
28 | for (var i=0; i<markers.length; i++) {
|
---|
29 | var current = markers[i];
|
---|
30 | var gMarker = addMarker(current, i);
|
---|
31 | }
|
---|
32 |
|
---|
33 | GEvent.addListener(map, "click", function() {
|
---|
34 | if(!overNode == true)
|
---|
35 | deSelect();
|
---|
36 | });
|
---|
37 |
|
---|
38 | /*
|
---|
39 | * Hier zo circles toevoegen.
|
---|
40 |
|
---|
41 | for(var i=0; i<circleArray.length; i++) {
|
---|
42 | map.addOverlay(circleArray[i]);
|
---|
43 | }
|
---|
44 | */
|
---|
45 |
|
---|
46 | var markerClusterer = new MarkerClusterer(map, markerArray);
|
---|
47 | suggestMarkers("");
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | //This function will contain the displaying and not displaying of nodes on the map
|
---|
52 | function toggleMyKml() {
|
---|
53 |
|
---|
54 | }
|
---|
55 |
|
---|
56 | //This function adds a marker with an object from our 'marker'array defined in index.php
|
---|
57 | function addMarker(current, i) {
|
---|
58 | var id = current.id;
|
---|
59 | var latitude = Number(current.latitude[0]);
|
---|
60 | var longitude = Number(current.longitude[0]);
|
---|
61 | //var circle = drawCircle(latitude, longitude, 2.0, "#6C3", 1, 0.75, "#0F0",.2);
|
---|
62 | var marker = new GMarker(new GLatLng(current.latitude[0], current.longitude[0]), {title: current.name[0], icon: greenIcon});
|
---|
63 |
|
---|
64 | //Added mouseover listener that calls on our mouseOver function when the mouse moves over a marker on the map
|
---|
65 | GEvent.addListener(marker, 'mouseover', function() {
|
---|
66 | mouseOverNode(current.id, current.name[0],latitude, longitude);
|
---|
67 | });
|
---|
68 | GEvent.addListener(marker, 'click', function() {
|
---|
69 | mouseClickNode(current.id, current.name[0], marker);
|
---|
70 | });
|
---|
71 | GEvent.addListener(marker, 'mouseout', function() {
|
---|
72 | mouseOutNode(current.id, current.name[0]);
|
---|
73 | });
|
---|
74 |
|
---|
75 | markerArray.push(marker);
|
---|
76 | //circleArray.push(circle);
|
---|
77 | return marker;
|
---|
78 | }
|
---|
79 |
|
---|
80 | //Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
|
---|
81 | function mouseClickNode(id, name, marker)
|
---|
82 | {
|
---|
83 | if(selected == true)
|
---|
84 | deSelect();
|
---|
85 |
|
---|
86 | if(markerSelected == marker)
|
---|
87 | {
|
---|
88 | deSelect();
|
---|
89 | markerSelected = "";
|
---|
90 | }
|
---|
91 | else
|
---|
92 | {
|
---|
93 | selected = true;
|
---|
94 |
|
---|
95 | markerSelected = marker;
|
---|
96 | marker.setImage("../img/sleutelGroenSelected.png");//Path should be in config
|
---|
97 | loadXMLDoc("inc/node_info.php?type=single&name="+name+""); //Should also be in config
|
---|
98 |
|
---|
99 | /*
|
---|
100 | *Hieronder verdergaan met dekking
|
---|
101 | */
|
---|
102 |
|
---|
103 | }
|
---|
104 | }
|
---|
105 | //Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
|
---|
106 | function mouseOverNode(id, name, latitude, longitude)
|
---|
107 | {
|
---|
108 | overNode = true;
|
---|
109 | if(!selected == true)
|
---|
110 | {
|
---|
111 |
|
---|
112 | drawCircle(latitude, longitude, 2.0, "#6C3", 1, 0.75, "#0F0",.2, 200);
|
---|
113 | polygons_on_map_array.push(polygon);
|
---|
114 | map.addOverlay(polygon);
|
---|
115 |
|
---|
116 | loadXMLDoc("inc/node_info.php?type=single&name="+name+"");//Path should be in config
|
---|
117 |
|
---|
118 | /*
|
---|
119 | *Hieronder verdergaan met dekking
|
---|
120 | */
|
---|
121 |
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | function mouseOutNode(id, name)
|
---|
126 | {
|
---|
127 | overNode = false;
|
---|
128 | map.removeOverlay(polygon);
|
---|
129 |
|
---|
130 | }
|
---|
131 |
|
---|
132 | //Our mouseover function for Cluster nodes. 'markers' is an array containing all markers within the cluster
|
---|
133 | function mouseOverCluster(markers)
|
---|
134 | {
|
---|
135 | if(!selected == true)
|
---|
136 | {
|
---|
137 | //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
|
---|
138 | var markerTitles = new Array;
|
---|
139 | var markerLatLngs = new Array;
|
---|
140 |
|
---|
141 | for(var i=0; i<markers.length; i++) {
|
---|
142 |
|
---|
143 | markerTitles.push(markers[i].marker.getTitle());
|
---|
144 | markerLatLngs.push(markers[i].marker.getLatLng() );
|
---|
145 | }
|
---|
146 |
|
---|
147 |
|
---|
148 |
|
---|
149 | for (var i=0; i<markerLatLngs.length; i++)
|
---|
150 | {
|
---|
151 | latLng = String(markerLatLngs[i]);
|
---|
152 |
|
---|
153 | pos = latLng.indexOf(',');
|
---|
154 | pos2 = latLng.length-1;
|
---|
155 |
|
---|
156 | var latitude = Number(latLng.substring(1, pos) );
|
---|
157 | var longitude = Number(latLng.substring(2 + pos, pos2) );
|
---|
158 |
|
---|
159 |
|
---|
160 | drawCircle( latitude, longitude,2.0, "#6C3", 1, 0.75, "#0F0",.2);
|
---|
161 |
|
---|
162 |
|
---|
163 |
|
---|
164 | map.addOverlay(polygon);
|
---|
165 | polygons_on_map_array.push(polygon);
|
---|
166 | }
|
---|
167 |
|
---|
168 | var markerTitleSerialized;
|
---|
169 |
|
---|
170 | //start
|
---|
171 | var a_php = "";
|
---|
172 | var total = 0;
|
---|
173 |
|
---|
174 | for (var i=0; i<markerTitles.length; i++)
|
---|
175 | {
|
---|
176 | ++ total;
|
---|
177 | a_php = a_php + "s:" +
|
---|
178 | String(i).length + ":\"" + String(i) + "\";s:" +
|
---|
179 | String(markerTitles[i]).length + ":\"" + String(markerTitles[i]) + "\";";
|
---|
180 | }
|
---|
181 | a_php = "a:" + total + ":{" + a_php + "}";
|
---|
182 | //end
|
---|
183 |
|
---|
184 | loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"")
|
---|
185 | /*
|
---|
186 | *Hieronder verdergaan met dekking
|
---|
187 | */
|
---|
188 | }
|
---|
189 | }
|
---|
190 |
|
---|
191 | //Our click function for Cluster nodes. 'markers' is an array containing all markers within the cluster
|
---|
192 | function clickCluster(markers)
|
---|
193 | {
|
---|
194 | if(selected == true)
|
---|
195 | deselect();
|
---|
196 |
|
---|
197 | //Let the rest of the program know that something is selected
|
---|
198 | select();
|
---|
199 |
|
---|
200 | //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
|
---|
201 | var markerTitles = new Array;
|
---|
202 | for(var i=0; i<markers.length; i++) {
|
---|
203 | markerTitles.push(markers[i].marker.getTitle());
|
---|
204 |
|
---|
205 | }
|
---|
206 |
|
---|
207 | var markerTitleSerialized;
|
---|
208 |
|
---|
209 | //start
|
---|
210 | var a_php = "";
|
---|
211 | var total = 0;
|
---|
212 |
|
---|
213 | for (var i=0; i<markerTitles.length; i++)
|
---|
214 | {
|
---|
215 | ++ total;
|
---|
216 | a_php = a_php + "s:" +
|
---|
217 | String(i).length + ":\"" + String(i) + "\";s:" +
|
---|
218 | String(markerTitles[i]).length + ":\"" + String(markerTitles[i]) + "\";";
|
---|
219 | }
|
---|
220 | a_php = "a:" + total + ":{" + a_php + "}";
|
---|
221 | //end
|
---|
222 |
|
---|
223 | loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"&sel=selected")
|
---|
224 | }
|
---|
225 |
|
---|
226 | function mouseOutCluster(markers)
|
---|
227 | {
|
---|
228 | removeAllPolygons();
|
---|
229 | }
|
---|
230 |
|
---|
231 | function removeAllPolgygons()
|
---|
232 | {
|
---|
233 | for(var i=0; i<polygons_on_map_array.length; i++)
|
---|
234 | {
|
---|
235 | var currentpolygon = polygons_on_map_array[i];
|
---|
236 | map.removeOverlay(currentpolygon);
|
---|
237 |
|
---|
238 | }
|
---|
239 | polygons_on_map_array.clear();
|
---|
240 | }
|
---|
241 |
|
---|
242 | function select()
|
---|
243 | {
|
---|
244 | selected = true;
|
---|
245 | }
|
---|
246 |
|
---|
247 | function deSelect()
|
---|
248 | {
|
---|
249 | selected = false;
|
---|
250 |
|
---|
251 | loadXMLDoc("inc/node_info.php");
|
---|
252 | if(!markerSelected == "")
|
---|
253 | markerSelected.setImage("../img/sleutelGroen.png");
|
---|
254 |
|
---|
255 | removeAllPolgygons();
|
---|
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, targetDiv)
|
---|
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 | function loadSuggest(url)
|
---|
309 | {
|
---|
310 | xmlhttp=null;
|
---|
311 | if (window.XMLHttpRequest)
|
---|
312 | {// code for Firefox, Opera, IE7, etc.
|
---|
313 | xmlhttp=new XMLHttpRequest();
|
---|
314 | }
|
---|
315 | else if (window.ActiveXObject)
|
---|
316 | {// code for IE6, IE5
|
---|
317 | xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
|
---|
318 | }
|
---|
319 | if (xmlhttp!=null)
|
---|
320 | {
|
---|
321 | xmlhttp.onreadystatechange=state_ChangeSuggest;
|
---|
322 | xmlhttp.open("GET",url,true);
|
---|
323 | xmlhttp.send(null);
|
---|
324 | }
|
---|
325 | else
|
---|
326 | {
|
---|
327 | alert("Your browser does not support XMLHTTP.");
|
---|
328 | }
|
---|
329 | }
|
---|
330 |
|
---|
331 | function state_ChangeSuggest()
|
---|
332 | {
|
---|
333 | if (xmlhttp.readyState==4)
|
---|
334 | {// 4 = "loaded"
|
---|
335 | if (xmlhttp.status==200)
|
---|
336 | {// 200 = "OK"
|
---|
337 | document.getElementById("searchlist").innerHTML=xmlhttp.responseText;
|
---|
338 | }
|
---|
339 | else
|
---|
340 | {
|
---|
341 | alert("Problem retrieving data:" + xmlhttp.statusText);
|
---|
342 | }
|
---|
343 | }
|
---|
344 | }
|
---|
345 |
|
---|
346 | function suggestMarkers(value)
|
---|
347 | {
|
---|
348 | loadSuggest("inc/suggestions.php?value="+value);
|
---|
349 | }
|
---|
350 |
|
---|
351 |
|
---|
352 |
|
---|