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

Last change on this file since 7804 was 7802, checked in by janveeden, 16 years ago

Added option to turn the google location search off/on at bottom of map.

File size: 7.7 KB
Line 
1//Declaring some variables we will be using
2var gmap_search_state = false;
3var map;
4var markerArray = new Array();
5var circleArray = new Array();
6var xmlhttp;
7var targetDiv = "infotop";
8var selected = false;
9var overNode;
10var markerSelected;
11var polygons_on_map_array = new Array();
12
13
14//This function is called from index.php
15function initialize_map() {
16 //We will only do this function if the browser is compatible
17 if (GBrowserIsCompatible()) {
18 //Adding the google map into the div called #mapcanvas
19 map = new GMap2(document.getElementById("mapcanvas"), {googleBarOptions : {style : "new",}});
20 //Center the map on Leiden
21 map.setCenter(new GLatLng(52.162687, 4.493294), 11); // Vars should go to config
22 map.setUIToDefault();
23
24
25
26 //Go through the array 'markers' (Declared in index.php) and add a marker for each marker stored in the array using our addMarker function
27 for (var i=0; i<markers.length; i++) {
28 var current = markers[i];
29 var gMarker = addMarker(current, i);
30 }
31
32 GEvent.addListener(map, "click", function() {
33 if(!overNode == true)
34 deSelect();
35 });
36
37 /*
38 * Hier zo circles toevoegen.
39
40 for(var i=0; i<circleArray.length; i++) {
41 map.addOverlay(circleArray[i]);
42 }
43 */
44
45 var markerClusterer = new MarkerClusterer(map, markerArray);
46 }
47}
48
49//This function will contain the displaying and not displaying of nodes on the map
50function toggleMyKml() {
51
52}
53
54//This function adds a marker with an object from our 'marker'array defined in index.php
55function addMarker(current, i) {
56 var id = current.id;
57 var latitude = Number(current.latitude[0]);
58 var longitude = Number(current.longitude[0]);
59 //var circle = drawCircle(latitude, longitude, 2.0, "#6C3", 1, 0.75, "#0F0",.2);
60 var marker = new GMarker(new GLatLng(current.latitude[0], current.longitude[0]), {title: current.name[0], icon: greenIcon});
61
62 //Added mouseover listener that calls on our mouseOver function when the mouse moves over a marker on the map
63 GEvent.addListener(marker, 'mouseover', function() {
64 mouseOverNode(current.id, current.name[0],latitude, longitude);
65 });
66 GEvent.addListener(marker, 'click', function() {
67 mouseClickNode(current.id, current.name[0], marker);
68 });
69 GEvent.addListener(marker, 'mouseout', function() {
70 mouseOutNode(current.id, current.name[0]);
71 });
72
73 markerArray.push(marker);
74 //circleArray.push(circle);
75 return marker;
76}
77
78//Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
79function mouseClickNode(id, name, marker)
80{
81 if(selected == true)
82 deSelect();
83
84 if(markerSelected == marker)
85 {
86 deSelect();
87 markerSelected = "";
88 }
89 else
90 {
91 selected = true;
92
93 markerSelected = marker;
94 marker.setImage("../img/sleutelGroenSelected.png");//Path should be in config
95 loadXMLDoc("inc/node_info.php?type=single&name="+name+""); //Should also be in config
96
97 /*
98 *Hieronder verdergaan met dekking
99 */
100
101 }
102}
103//Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
104function mouseOverNode(id, name, latitude, longitude)
105{
106 overNode = true;
107 if(!selected == true)
108 {
109
110 drawCircle(latitude, longitude, 2.0, "#6C3", 1, 0.75, "#0F0",.2, 200);
111 polygons_on_map_array.push(polygon);
112 map.addOverlay(polygon);
113
114 loadXMLDoc("inc/node_info.php?type=single&name="+name+"");//Path should be in config
115
116 /*
117 *Hieronder verdergaan met dekking
118 */
119
120 }
121}
122
123function mouseOutNode(id, name)
124{
125 overNode = false;
126 map.removeOverlay(polygon);
127
128}
129
130//Our mouseover function for Cluster nodes. 'markers' is an array containing all markers within the cluster
131function mouseOverCluster(markers)
132{
133 if(!selected == true)
134 {
135 //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
136 var markerTitles = new Array;
137 var markerLatLngs = new Array;
138
139 for(var i=0; i<markers.length; i++) {
140
141 markerTitles.push(markers[i].marker.getTitle());
142 markerLatLngs.push(markers[i].marker.getLatLng() );
143 }
144
145
146
147 for (var i=0; i<markerLatLngs.length; i++)
148 {
149 latLng = String(markerLatLngs[i]);
150
151 pos = latLng.indexOf(',');
152 pos2 = latLng.length-1;
153
154 var latitude = Number(latLng.substring(1, pos) );
155 var longitude = Number(latLng.substring(2 + pos, pos2) );
156
157
158 drawCircle( latitude, longitude,2.0, "#6C3", 1, 0.75, "#0F0",.2);
159
160
161
162 map.addOverlay(polygon);
163
164 }
165
166 var markerTitleSerialized;
167
168 //start
169 var a_php = "";
170 var total = 0;
171
172 for (var i=0; i<markerTitles.length; i++)
173 {
174 ++ total;
175 a_php = a_php + "s:" +
176 String(i).length + ":\"" + String(i) + "\";s:" +
177 String(markerTitles[i]).length + ":\"" + String(markerTitles[i]) + "\";";
178 }
179 a_php = "a:" + total + ":{" + a_php + "}";
180 //end
181
182 loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"")
183 /*
184 *Hieronder verdergaan met dekking
185 */
186 }
187}
188
189//Our click function for Cluster nodes. 'markers' is an array containing all markers within the cluster
190function clickCluster(markers)
191{
192 if(selected == true)
193 deselect();
194
195 //Let the rest of the program know that something is selected
196 select();
197
198 //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
199 var markerTitles = new Array;
200 for(var i=0; i<markers.length; i++) {
201 markerTitles.push(markers[i].marker.getTitle());
202
203 }
204
205 var markerTitleSerialized;
206
207 //start
208 var a_php = "";
209 var total = 0;
210
211 for (var i=0; i<markerTitles.length; i++)
212 {
213 ++ total;
214 a_php = a_php + "s:" +
215 String(i).length + ":\"" + String(i) + "\";s:" +
216 String(markerTitles[i]).length + ":\"" + String(markerTitles[i]) + "\";";
217 }
218 a_php = "a:" + total + ":{" + a_php + "}";
219 //end
220
221 loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"&sel=selected")
222}
223
224function mouseOutCluster(markers)
225{
226 map.removeOverlay(polygon);
227 map.removeOverlay(polygon);
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 loadXMLDoc("inc/node_info.php");
251 markerSelected.setImage("../img/sleutelGroen.png");
252
253 for(var i=0; i<polygons_on_map_array.length; i++)
254 {
255 var currentpolygon = polygons_on_map_array[i];
256 map.removeOverlay(polygon);
257 }
258
259}
260
261function removeOtherSelect()
262{
263 for(var i=0; i<markerArray.length; i++)
264 {
265 currentmarker = markerArray[i];
266 currentmarker.setImage("../sleutelGroen.png");
267 }
268 return true;
269}
270
271//Code from w3schools. http://www.w3schools.com/dom/dom_http.asp
272function loadXMLDoc(url)
273{
274xmlhttp=null;
275if (window.XMLHttpRequest)
276 {// code for Firefox, Opera, IE7, etc.
277 xmlhttp=new XMLHttpRequest();
278 }
279else if (window.ActiveXObject)
280 {// code for IE6, IE5
281 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
282 }
283if (xmlhttp!=null)
284 {
285 xmlhttp.onreadystatechange=state_Change;
286 xmlhttp.open("GET",url,true);
287 xmlhttp.send(null);
288 }
289else
290 {
291 alert("Your browser does not support XMLHTTP.");
292 }
293}
294
295function state_Change()
296{
297if (xmlhttp.readyState==4)
298 {// 4 = "loaded"
299 if (xmlhttp.status==200)
300 {// 200 = "OK"
301 document.getElementById(targetDiv).innerHTML=xmlhttp.responseText;
302 }
303 else
304 {
305 alert("Problem retrieving data:" + xmlhttp.statusText);
306 }
307 }
308}
309
310function toggleGoogleSearchMap()
311{
312 if(gmap_search_state)
313 {
314 gmap_search_state = false;
315 }
316 else
317 {
318 gmap_search_state = true;
319 }
320
321 if(gmap_search_state)
322 {
323 map.enableGoogleBar();
324 }
325
326 if(!gmap_search_state)
327 {
328 map.disableGoogleBar();
329 }
330}
331
332
333
334
335
Note: See TracBrowser for help on using the repository browser.