source: trunk/src/map/inc/nodemapWL.js@ 7828

Last change on this file since 7828 was 7827, checked in by janveeden, 15 years ago

Gebruiker and beheerder view are now different. Beheerder view shows all info, gebruiker only a bit of info. Fixed typo in kmlHandler.php. Added a Math.random to calls to node_info.php to prevent unwanted caching.

File size: 9.1 KB
Line 
1//Declaring some variables we will be using
2var gmap_search_state = false;
3
4var map;
5var markerArray = [];
6var circleArray = [];
7var polygons_on_map_array = [];
8var xmlhttp;
9var targetDiv = "infotop";
10var selected = false;
11var overNode;
12var markerSelected = "";
13
14
15
16//This function is called from index.php
17function initialize_map() {
18 //We will only do this function if the browser is compatible
19 if (GBrowserIsCompatible()) {
20 //Adding the google map into the div called #mapcanvas
21 map = new GMap2(document.getElementById("mapcanvas"), {googleBarOptions : {style : "new"}});
22 //Center the map on Leiden
23 map.setCenter(new GLatLng(52.162687, 4.493294), 11); // Vars should go to config
24 map.setUIToDefault();
25
26
27 /*
28 * Go through the array 'markers' (Declared in index.php) and add a marker for each marker stored in the array
29 * using our addMarker function.
30 * If the latLng of the marker is both 0
31 */
32 for (var i=0; i<markers.length; i++) {
33 var current = markers[i];
34 if(current.latitude[0] > 0 || current.latitude[0] < 0)
35 {
36 addMarker(current, i);
37 }
38 }
39
40 GEvent.addListener(map, "click", function() {
41 if(!overNode == true)
42 deSelect();
43 });
44
45 GEvent.addListener(map, "zoomend", function() {
46 mapZoomed();
47 });
48
49 suggestMarkers("");
50 var markerClusterer = new MarkerClusterer(map, markerArray);
51
52 }
53}
54
55//This function will contain the displaying and not displaying of nodes on the map
56function toggleMyKml() {
57
58}
59
60//This function adds a marker with an object from our 'marker'array defined in index.php
61function addMarker(current, i) {
62 var latitude = Number(current.latitude[0]);
63 var longitude = Number(current.longitude[0]);
64 //var circle = drawCircle(latitude, longitude, 2.0, "#6C3", 1, 0.75, "#0F0",.2);
65 var marker = new GMarker(new GLatLng(current.latitude[0], current.longitude[0]), {title: current.name[0], icon: greenIcon});
66
67 //Added mouseover listener that calls on our mouseOver function when the mouse moves over a marker on the map
68 GEvent.addListener(marker, 'mouseover', function() {
69 mouseOverNode(current.id, current.name[0],latitude, longitude);
70 });
71 GEvent.addListener(marker, 'click', function() {
72 mouseClickNode(current.id, current.name[0], marker);
73 });
74 GEvent.addListener(marker, 'mouseout', function() {
75 mouseOutNode(current.id, current.name[0]);
76 });
77
78 markerArray.push(marker);
79 //circleArray.push(circle);
80 return marker;
81}
82
83//Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
84function mouseClickNode(id, name, marker)
85{
86 if(selected == true)
87 {
88 deSelect();
89 markerSelected = "";
90 }
91
92 if(markerSelected == marker)
93 {
94 deSelect();
95 markerSelected = "";
96 }
97 else
98 {
99 selected = true;
100 markerSelected = marker;
101 marker.setImage("../img/sleutelGroenSelected.png");//Path should be in config
102 loadXMLDoc("inc/node_info.php?type=single&name="+name+"&a="+Math.random()); //Should also be in config
103 }
104}
105//Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
106function mouseOverNode(id, name, latitude, longitude)
107{
108 overNode = true;
109 if(!selected == true)
110 {
111
112 drawCircle(latitude, longitude,0.1, "#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+"&a="+Math.random());//Path should be in config
117
118 /*
119 *Hieronder verdergaan met dekking
120 */
121
122 }
123}
124
125function 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
133function 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,0.1, "#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
192function 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"+"&a="+Math.random())
224}
225
226function mouseOutCluster(markers)
227{
228 removeAllPolgygons();
229}
230
231function mapZoomed()
232{
233 if(!markerSelected == "")
234 {
235 markerSelected.setImage("../img/sleutelGroenSelected.png");
236 }
237}
238
239function removeAllPolgygons()
240{
241 for(var i=0; i<polygons_on_map_array.length; i++)
242 {
243 var currentpolygon = polygons_on_map_array[i];
244 map.removeOverlay(currentpolygon);
245
246 }
247 polygons_on_map_array.clear();
248}
249
250function select()
251{
252 selected = true;
253}
254
255function deSelect()
256{
257 selected = false;
258 loadXMLDoc("inc/node_info.php");
259 if(!markerSelected == "")
260 {
261 markerSelected.setImage("../img/sleutelGroen.png");
262 markerSelected = "";
263 }
264
265 removeAllPolgygons();
266
267}
268
269function removeOtherSelect()
270{
271 for(var i=0; i<markerArray.length; i++)
272 {
273 currentmarker = markerArray[i];
274 currentmarker.setImage("../sleutelGroen.png");
275 }
276 return true;
277}
278
279//Code from w3schools. http://www.w3schools.com/dom/dom_http.asp
280function loadXMLDoc(url, targetDiv)
281{
282xmlhttp=null;
283if (window.XMLHttpRequest)
284 {// code for Firefox, Opera, IE7, etc.
285 xmlhttp=new XMLHttpRequest();
286 }
287else if (window.ActiveXObject)
288 {// code for IE6, IE5
289 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
290 }
291if (xmlhttp!=null)
292 {
293 xmlhttp.onreadystatechange=state_Change();
294 xmlhttp.open("GET",url,true);
295 xmlhttp.send(null);
296 }
297else
298 {
299 alert("Your browser does not support XMLHTTP.");
300 }
301}
302
303function state_Change()
304{
305if (xmlhttp.readyState==4)
306 {// 4 = "loaded"
307 if (xmlhttp.status==200)
308 {// 200 = "OK"
309 document.getElementById(targetDiv).innerHTML=xmlhttp.responseText;
310 }
311 else
312 {
313 alert("Problem retrieving data:" + xmlhttp.statusText);
314 }
315 }
316}
317
318function loadSuggest(url)
319{
320xmlhttp=null;
321if (window.XMLHttpRequest)
322 {// code for Firefox, Opera, IE7, etc.
323 xmlhttp=new XMLHttpRequest();
324 }
325else if (window.ActiveXObject)
326 {// code for IE6, IE5
327 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
328 }
329if (xmlhttp!=null)
330 {
331 xmlhttp.onreadystatechange=state_ChangeSuggest;
332 xmlhttp.open("GET",url,true);
333 xmlhttp.send(null);
334 }
335else
336 {
337 alert("Your browser does not support XMLHTTP.");
338 }
339}
340
341function state_ChangeSuggest()
342{
343if (xmlhttp.readyState==4)
344 {// 4 = "loaded"
345 if (xmlhttp.status==200)
346 {// 200 = "OK"
347 document.getElementById("searchlist").innerHTML=xmlhttp.responseText;
348 }
349 else
350 {
351 alert("Problem retrieving data:" + xmlhttp.statusText);
352 }
353 }
354}
355
356function suggestMarkers(value)
357{
358 loadSuggest("inc/suggestions.php?value="+value+"&a="+Math.random());
359}
360
361function goToMarker(value)
362{
363 for(var i=0; i<markerArray.length; i++)
364 {
365 var name = markerArray[i].getTitle();
366
367 if(name == value)
368 {
369 map.setCenter(markerArray[i].getLatLng(), 15);
370 loadXMLDoc("inc/node_info.php?type=single&name="+value+"&a="+Math.random())
371 }
372 }
373}
374
375function toggleGoogleSearchMap()
376{
377 if(gmap_search_state)
378 {
379 gmap_search_state = false;
380 }
381 else
382 {
383 gmap_search_state = true;
384 }
385
386 if(gmap_search_state)
387 {
388 map.enableGoogleBar();
389 }
390
391 if(!gmap_search_state)
392 {
393 map.disableGoogleBar();
394 }
395}
396
397
398
Note: See TracBrowser for help on using the repository browser.