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

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

Removed location search toggle by accident. Now its back there again.

File size: 8.6 KB
RevLine 
[7722]1//Declaring some variables we will be using
[7802]2var gmap_search_state = false;
[7809]3
[7694]4var map;
[7732]5var markerArray = new Array();
[7793]6var circleArray = new Array();
[7734]7var xmlhttp;
8var targetDiv = "infotop";
[7786]9var selected = false;
[7756]10var overNode;
[7809]11var markerSelected = "";
[7800]12var polygons_on_map_array = new Array();
[7665]13
[7778]14
[7734]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
[7801]20 map = new GMap2(document.getElementById("mapcanvas"), {googleBarOptions : {style : "new",}});
[7734]21 //Center the map on Leiden
[7801]22 map.setCenter(new GLatLng(52.162687, 4.493294), 11); // Vars should go to config
[7734]23 map.setUIToDefault();
[7802]24
[7778]25
[7734]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];
[7767]30 var gMarker = addMarker(current, i);
[7734]31 }
[7694]32
[7756]33 GEvent.addListener(map, "click", function() {
34 if(!overNode == true)
35 deSelect();
36 });
37
[7767]38 /*
39 * Hier zo circles toevoegen.
[7796]40
[7793]41 for(var i=0; i<circleArray.length; i++) {
42 map.addOverlay(circleArray[i]);
43 }
[7796]44 */
[7767]45
[7734]46 var markerClusterer = new MarkerClusterer(map, markerArray);
[7809]47 suggestMarkers("");
[7734]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;
[7793]59 var latitude = Number(current.latitude[0]);
60 var longitude = Number(current.longitude[0]);
[7796]61 //var circle = drawCircle(latitude, longitude, 2.0, "#6C3", 1, 0.75, "#0F0",.2);
[7783]62 var marker = new GMarker(new GLatLng(current.latitude[0], current.longitude[0]), {title: current.name[0], icon: greenIcon});
[7793]63
[7734]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() {
[7796]66 mouseOverNode(current.id, current.name[0],latitude, longitude);
[7734]67 });
[7756]68 GEvent.addListener(marker, 'click', function() {
[7786]69 mouseClickNode(current.id, current.name[0], marker);
[7756]70 });
71 GEvent.addListener(marker, 'mouseout', function() {
72 mouseOutNode(current.id, current.name[0]);
73 });
74
[7786]75 markerArray.push(marker);
[7796]76 //circleArray.push(circle);
[7734]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.
[7786]81function mouseClickNode(id, name, marker)
82{
83 if(selected == true)
84 deSelect();
[7778]85
[7786]86 if(markerSelected == marker)
87 {
88 deSelect();
89 markerSelected = "";
90 }
91 else
92 {
93 selected = true;
94
95 markerSelected = marker;
[7801]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
[7756]98
[7786]99 /*
100 *Hieronder verdergaan met dekking
101 */
102
103 }
[7734]104}
[7756]105//Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
[7796]106function mouseOverNode(id, name, latitude, longitude)
[7756]107{
[7786]108 overNode = true;
[7756]109 if(!selected == true)
110 {
[7798]111
[7814]112 drawCircle(latitude, longitude,0.1, "#6C3", 1, 0.75, "#0F0",.2, 200);
[7800]113 polygons_on_map_array.push(polygon);
[7796]114 map.addOverlay(polygon);
[7798]115
[7801]116 loadXMLDoc("inc/node_info.php?type=single&name="+name+"");//Path should be in config
[7782]117
[7756]118 /*
119 *Hieronder verdergaan met dekking
120 */
[7793]121
[7756]122 }
123}
[7734]124
[7756]125function mouseOutNode(id, name)
126{
127 overNode = false;
[7778]128 map.removeOverlay(polygon);
129
[7756]130}
131
[7734]132//Our mouseover function for Cluster nodes. 'markers' is an array containing all markers within the cluster
133function mouseOverCluster(markers)
134{
[7756]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;
[7809]139 var markerLatLngs = new Array;
[7798]140
[7756]141 for(var i=0; i<markers.length; i++) {
[7798]142
[7756]143 markerTitles.push(markers[i].marker.getTitle());
[7809]144 markerLatLngs.push(markers[i].marker.getLatLng() );
[7756]145 }
146
[7798]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
[7814]160 drawCircle( latitude, longitude,0.1, "#6C3", 1, 0.75, "#0F0",.2);
[7798]161
162
[7814]163
[7798]164 map.addOverlay(polygon);
[7809]165 polygons_on_map_array.push(polygon);
[7798]166 }
167
[7756]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)
[7793]193{
194 if(selected == true)
195 deselect();
196
[7756]197 //Let the rest of the program know that something is selected
198 select();
199
[7736]200 //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
[7734]201 var markerTitles = new Array;
202 for(var i=0; i<markers.length; i++) {
[7809]203 markerTitles.push(markers[i].marker.getTitle());
[7798]204
[7722]205 }
[7733]206
[7735]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
[7756]223 loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"&sel=selected")
[7734]224}
[7665]225
[7798]226function mouseOutCluster(markers)
[7809]227{
[7813]228 removeAllPolgygons();
[7812]229}
230
231function removeAllPolgygons()
232{
233 for(var i=0; i<polygons_on_map_array.length; i++)
234 {
235 var currentpolygon = polygons_on_map_array[i];
236 map.removeOverlay(currentpolygon);
[7798]237
238 }
[7812]239 polygons_on_map_array.clear();
[7798]240}
241
[7756]242function select()
[7738]243{
[7756]244 selected = true;
[7738]245}
[7734]246
[7756]247function deSelect()
248{
[7809]249 selected = false;
[7786]250
[7809]251 loadXMLDoc("inc/node_info.php");
252 if(!markerSelected == "")
253 markerSelected.setImage("../img/sleutelGroen.png");
254
[7812]255 removeAllPolgygons();
[7800]256
[7756]257}
[7738]258
[7786]259function removeOtherSelect()
260{
261 for(var i=0; i<markerArray.length; i++)
262 {
263 currentmarker = markerArray[i];
264 currentmarker.setImage("../sleutelGroen.png");
265 }
266 return true;
267}
268
[7734]269//Code from w3schools. http://www.w3schools.com/dom/dom_http.asp
[7805]270function loadXMLDoc(url, targetDiv)
[7734]271{
272xmlhttp=null;
273if (window.XMLHttpRequest)
274 {// code for Firefox, Opera, IE7, etc.
275 xmlhttp=new XMLHttpRequest();
276 }
277else if (window.ActiveXObject)
278 {// code for IE6, IE5
279 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
280 }
281if (xmlhttp!=null)
282 {
[7805]283 xmlhttp.onreadystatechange=state_Change();
[7734]284 xmlhttp.open("GET",url,true);
285 xmlhttp.send(null);
286 }
287else
288 {
289 alert("Your browser does not support XMLHTTP.");
290 }
291}
292
293function state_Change()
294{
295if (xmlhttp.readyState==4)
296 {// 4 = "loaded"
297 if (xmlhttp.status==200)
298 {// 200 = "OK"
299 document.getElementById(targetDiv).innerHTML=xmlhttp.responseText;
300 }
301 else
302 {
303 alert("Problem retrieving data:" + xmlhttp.statusText);
304 }
305 }
306}
[7778]307
[7805]308function loadSuggest(url)
309{
310xmlhttp=null;
311if (window.XMLHttpRequest)
312 {// code for Firefox, Opera, IE7, etc.
313 xmlhttp=new XMLHttpRequest();
314 }
315else if (window.ActiveXObject)
316 {// code for IE6, IE5
317 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
318 }
319if (xmlhttp!=null)
320 {
321 xmlhttp.onreadystatechange=state_ChangeSuggest;
322 xmlhttp.open("GET",url,true);
323 xmlhttp.send(null);
324 }
325else
326 {
327 alert("Your browser does not support XMLHTTP.");
328 }
329}
330
331function state_ChangeSuggest()
332{
333if (xmlhttp.readyState==4)
334 {// 4 = "loaded"
335 if (xmlhttp.status==200)
336 {// 200 = "OK"
337 document.getElementById("searchlist").innerHTML=xmlhttp.responseText;
338 }
339 else
340 {
341 alert("Problem retrieving data:" + xmlhttp.statusText);
342 }
343 }
344}
345
346function suggestMarkers(value)
347{
348 loadSuggest("inc/suggestions.php?value="+value);
349}
[7778]350
[7816]351function toggleGoogleSearchMap()
352{
353 if(gmap_search_state)
354 {
355 gmap_search_state = false;
356 }
357 else
358 {
359 gmap_search_state = true;
360 }
361
362 if(gmap_search_state)
363 {
364 map.enableGoogleBar();
365 }
366
367 if(!gmap_search_state)
368 {
369 map.disableGoogleBar();
370 }
371}
[7778]372
[7801]373
[7816]374
Note: See TracBrowser for help on using the repository browser.