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

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

Fixed removing all polygons from map on deselect.

File size: 8.4 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 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
52function toggleMyKml() {
53
54}
55
56//This function adds a marker with an object from our 'marker'array defined in index.php
57function 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.
81function 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.
106function 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
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,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
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")
224}
225
226function mouseOutCluster(markers)
227{
228
229 //TODO DELETE ALL CIRCLES
230
231 /*
232 for (var i=0; i<markers.length; i++) {
233
234 map.removeOverlay(polygon[i]);
235
236 }
237 */
238
239
240}
241
242function select()
243{
244 selected = true;
245}
246
247function deSelect()
248{
249 selected = false;
250
251 loadXMLDoc("inc/node_info.php");
252 if(!markerSelected == "")
253 markerSelected.setImage("../img/sleutelGroen.png");
254
255 for(var i=0; i<polygons_on_map_array.length; i++)
256 {
257 var currentpolygon = polygons_on_map_array[i];
258 map.removeOverlay(currentpolygon);
259 }
260
261}
262
263function removeOtherSelect()
264{
265 for(var i=0; i<markerArray.length; i++)
266 {
267 currentmarker = markerArray[i];
268 currentmarker.setImage("../sleutelGroen.png");
269 }
270 return true;
271}
272
273//Code from w3schools. http://www.w3schools.com/dom/dom_http.asp
274function loadXMLDoc(url, targetDiv)
275{
276xmlhttp=null;
277if (window.XMLHttpRequest)
278 {// code for Firefox, Opera, IE7, etc.
279 xmlhttp=new XMLHttpRequest();
280 }
281else if (window.ActiveXObject)
282 {// code for IE6, IE5
283 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
284 }
285if (xmlhttp!=null)
286 {
287 xmlhttp.onreadystatechange=state_Change();
288 xmlhttp.open("GET",url,true);
289 xmlhttp.send(null);
290 }
291else
292 {
293 alert("Your browser does not support XMLHTTP.");
294 }
295}
296
297function state_Change()
298{
299if (xmlhttp.readyState==4)
300 {// 4 = "loaded"
301 if (xmlhttp.status==200)
302 {// 200 = "OK"
303 document.getElementById(targetDiv).innerHTML=xmlhttp.responseText;
304 }
305 else
306 {
307 alert("Problem retrieving data:" + xmlhttp.statusText);
308 }
309 }
310}
311
312function loadSuggest(url)
313{
314xmlhttp=null;
315if (window.XMLHttpRequest)
316 {// code for Firefox, Opera, IE7, etc.
317 xmlhttp=new XMLHttpRequest();
318 }
319else if (window.ActiveXObject)
320 {// code for IE6, IE5
321 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
322 }
323if (xmlhttp!=null)
324 {
325 xmlhttp.onreadystatechange=state_ChangeSuggest;
326 xmlhttp.open("GET",url,true);
327 xmlhttp.send(null);
328 }
329else
330 {
331 alert("Your browser does not support XMLHTTP.");
332 }
333}
334
335function state_ChangeSuggest()
336{
337if (xmlhttp.readyState==4)
338 {// 4 = "loaded"
339 if (xmlhttp.status==200)
340 {// 200 = "OK"
341 document.getElementById("searchlist").innerHTML=xmlhttp.responseText;
342 }
343 else
344 {
345 alert("Problem retrieving data:" + xmlhttp.statusText);
346 }
347 }
348}
349
350function suggestMarkers(value)
351{
352 loadSuggest("inc/suggestions.php?value="+value);
353}
354
355
356
Note: See TracBrowser for help on using the repository browser.