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

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

The famous markers placed in the sea were giving problems on giving info. Fixed now.

File size: 9.0 KB
Line 
1//Declaring some variables we will be using
2var gmap_search_state = false;
3
4var map;
5var markerArray = new Array();
6var circleArray = new Array();
7var xmlhttp;
8var targetDiv = "infotop";
9var selected = false;
10var overNode;
11var markerSelected = "";
12var polygons_on_map_array = new Array();
13
14
15//This function is called from index.php
16function 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
28 * using our addMarker function.
29 * If the latLng of the marker is both 0
30 */
31 for (var i=0; i<markers.length; i++) {
32 var current = markers[i];
33 if(current.latitude[0] > 0 || current.latitude[0] < 0)
34 {
35 var gMarker = addMarker(current, i);
36 }
37 }
38
39 GEvent.addListener(map, "click", function() {
40 if(!overNode == true)
41 deSelect();
42 });
43
44 /*
45 * Hier zo circles toevoegen.
46
47 for(var i=0; i<circleArray.length; i++) {
48 map.addOverlay(circleArray[i]);
49 }
50 */
51
52 var markerClusterer = new MarkerClusterer(map, markerArray);
53 suggestMarkers("");
54 }
55}
56
57//This function will contain the displaying and not displaying of nodes on the map
58function toggleMyKml() {
59
60}
61
62//This function adds a marker with an object from our 'marker'array defined in index.php
63function addMarker(current, i) {
64 var id = current.id;
65 var latitude = Number(current.latitude[0]);
66 var longitude = Number(current.longitude[0]);
67 //var circle = drawCircle(latitude, longitude, 2.0, "#6C3", 1, 0.75, "#0F0",.2);
68 var marker = new GMarker(new GLatLng(current.latitude[0], current.longitude[0]), {title: current.name[0], icon: greenIcon});
69
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() {
72 mouseOverNode(current.id, current.name[0],latitude, longitude);
73 });
74 GEvent.addListener(marker, 'click', function() {
75 mouseClickNode(current.id, current.name[0], marker);
76 });
77 GEvent.addListener(marker, 'mouseout', function() {
78 mouseOutNode(current.id, current.name[0]);
79 });
80
81 markerArray.push(marker);
82 //circleArray.push(circle);
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.
87function mouseClickNode(id, name, marker)
88{
89 if(selected == true)
90 deSelect();
91
92 if(markerSelected == marker)
93 {
94 deSelect();
95 markerSelected = "";
96 }
97 else
98 {
99 selected = true;
100
101 markerSelected = marker;
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
104
105 /*
106 *Hieronder verdergaan met dekking
107 */
108
109 }
110}
111//Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
112function mouseOverNode(id, name, latitude, longitude)
113{
114 overNode = true;
115 if(!selected == true)
116 {
117
118 drawCircle(latitude, longitude,0.1, "#6C3", 1, 0.75, "#0F0",.2, 200);
119 polygons_on_map_array.push(polygon);
120 map.addOverlay(polygon);
121
122 loadXMLDoc("inc/node_info.php?type=single&name="+name+"");//Path should be in config
123
124 /*
125 *Hieronder verdergaan met dekking
126 */
127
128 }
129}
130
131function mouseOutNode(id, name)
132{
133 overNode = false;
134 map.removeOverlay(polygon);
135
136}
137
138//Our mouseover function for Cluster nodes. 'markers' is an array containing all markers within the cluster
139function mouseOverCluster(markers)
140{
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;
145 var markerLatLngs = new Array;
146
147 for(var i=0; i<markers.length; i++) {
148
149 markerTitles.push(markers[i].marker.getTitle());
150 markerLatLngs.push(markers[i].marker.getLatLng() );
151 }
152
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
166 drawCircle( latitude, longitude,0.1, "#6C3", 1, 0.75, "#0F0",.2);
167
168
169
170 map.addOverlay(polygon);
171 polygons_on_map_array.push(polygon);
172 }
173
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
198function clickCluster(markers)
199{
200 if(selected == true)
201 deselect();
202
203 //Let the rest of the program know that something is selected
204 select();
205
206 //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
207 var markerTitles = new Array;
208 for(var i=0; i<markers.length; i++) {
209 markerTitles.push(markers[i].marker.getTitle());
210
211 }
212
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
229 loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"&sel=selected")
230}
231
232function mouseOutCluster(markers)
233{
234 removeAllPolgygons();
235}
236
237function 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);
243
244 }
245 polygons_on_map_array.clear();
246}
247
248function select()
249{
250 selected = true;
251}
252
253function deSelect()
254{
255 selected = false;
256
257 loadXMLDoc("inc/node_info.php");
258 if(!markerSelected == "")
259 markerSelected.setImage("../img/sleutelGroen.png");
260
261 removeAllPolgygons();
262
263}
264
265function 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
275//Code from w3schools. http://www.w3schools.com/dom/dom_http.asp
276function loadXMLDoc(url, targetDiv)
277{
278xmlhttp=null;
279if (window.XMLHttpRequest)
280 {// code for Firefox, Opera, IE7, etc.
281 xmlhttp=new XMLHttpRequest();
282 }
283else if (window.ActiveXObject)
284 {// code for IE6, IE5
285 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
286 }
287if (xmlhttp!=null)
288 {
289 xmlhttp.onreadystatechange=state_Change();
290 xmlhttp.open("GET",url,true);
291 xmlhttp.send(null);
292 }
293else
294 {
295 alert("Your browser does not support XMLHTTP.");
296 }
297}
298
299function state_Change()
300{
301if (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}
313
314function loadSuggest(url)
315{
316xmlhttp=null;
317if (window.XMLHttpRequest)
318 {// code for Firefox, Opera, IE7, etc.
319 xmlhttp=new XMLHttpRequest();
320 }
321else if (window.ActiveXObject)
322 {// code for IE6, IE5
323 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
324 }
325if (xmlhttp!=null)
326 {
327 xmlhttp.onreadystatechange=state_ChangeSuggest;
328 xmlhttp.open("GET",url,true);
329 xmlhttp.send(null);
330 }
331else
332 {
333 alert("Your browser does not support XMLHTTP.");
334 }
335}
336
337function state_ChangeSuggest()
338{
339if (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
352function suggestMarkers(value)
353{
354 loadSuggest("inc/suggestions.php?value="+value);
355}
356
357function 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);
366 loadXMLDoc("inc/node_info.php?type=single&name="+value+"")
367 }
368 }
369}
370
371function 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}
392
393
394
Note: See TracBrowser for help on using the repository browser.