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

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

array containing all polygons on map is cleared on deselect now.

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 polygons_on_map_array.clear();
260 }
261
262}
263
264function removeOtherSelect()
265{
266 for(var i=0; i<markerArray.length; i++)
267 {
268 currentmarker = markerArray[i];
269 currentmarker.setImage("../sleutelGroen.png");
270 }
271 return true;
272}
273
274//Code from w3schools. http://www.w3schools.com/dom/dom_http.asp
275function loadXMLDoc(url, targetDiv)
276{
277xmlhttp=null;
278if (window.XMLHttpRequest)
279 {// code for Firefox, Opera, IE7, etc.
280 xmlhttp=new XMLHttpRequest();
281 }
282else if (window.ActiveXObject)
283 {// code for IE6, IE5
284 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
285 }
286if (xmlhttp!=null)
287 {
288 xmlhttp.onreadystatechange=state_Change();
289 xmlhttp.open("GET",url,true);
290 xmlhttp.send(null);
291 }
292else
293 {
294 alert("Your browser does not support XMLHTTP.");
295 }
296}
297
298function state_Change()
299{
300if (xmlhttp.readyState==4)
301 {// 4 = "loaded"
302 if (xmlhttp.status==200)
303 {// 200 = "OK"
304 document.getElementById(targetDiv).innerHTML=xmlhttp.responseText;
305 }
306 else
307 {
308 alert("Problem retrieving data:" + xmlhttp.statusText);
309 }
310 }
311}
312
313function loadSuggest(url)
314{
315xmlhttp=null;
316if (window.XMLHttpRequest)
317 {// code for Firefox, Opera, IE7, etc.
318 xmlhttp=new XMLHttpRequest();
319 }
320else if (window.ActiveXObject)
321 {// code for IE6, IE5
322 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
323 }
324if (xmlhttp!=null)
325 {
326 xmlhttp.onreadystatechange=state_ChangeSuggest;
327 xmlhttp.open("GET",url,true);
328 xmlhttp.send(null);
329 }
330else
331 {
332 alert("Your browser does not support XMLHTTP.");
333 }
334}
335
336function state_ChangeSuggest()
337{
338if (xmlhttp.readyState==4)
339 {// 4 = "loaded"
340 if (xmlhttp.status==200)
341 {// 200 = "OK"
342 document.getElementById("searchlist").innerHTML=xmlhttp.responseText;
343 }
344 else
345 {
346 alert("Problem retrieving data:" + xmlhttp.statusText);
347 }
348 }
349}
350
351function suggestMarkers(value)
352{
353 loadSuggest("inc/suggestions.php?value="+value);
354}
355
356
357
Note: See TracBrowser for help on using the repository browser.