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
RevLine 
[7722]1//Declaring some variables we will be using
[7802]2var gmap_search_state = false;
[7694]3var map;
[7732]4var markerArray = new Array();
[7793]5var circleArray = new Array();
[7734]6var xmlhttp;
7var targetDiv = "infotop";
[7786]8var selected = false;
[7756]9var overNode;
[7786]10var markerSelected;
[7800]11var polygons_on_map_array = new Array();
[7665]12
[7778]13
[7734]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
[7801]19 map = new GMap2(document.getElementById("mapcanvas"), {googleBarOptions : {style : "new",}});
[7734]20 //Center the map on Leiden
[7801]21 map.setCenter(new GLatLng(52.162687, 4.493294), 11); // Vars should go to config
[7734]22 map.setUIToDefault();
[7802]23
[7778]24
[7734]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];
[7767]29 var gMarker = addMarker(current, i);
[7734]30 }
[7694]31
[7756]32 GEvent.addListener(map, "click", function() {
33 if(!overNode == true)
34 deSelect();
35 });
36
[7767]37 /*
38 * Hier zo circles toevoegen.
[7796]39
[7793]40 for(var i=0; i<circleArray.length; i++) {
41 map.addOverlay(circleArray[i]);
42 }
[7796]43 */
[7767]44
[7734]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;
[7793]57 var latitude = Number(current.latitude[0]);
58 var longitude = Number(current.longitude[0]);
[7796]59 //var circle = drawCircle(latitude, longitude, 2.0, "#6C3", 1, 0.75, "#0F0",.2);
[7783]60 var marker = new GMarker(new GLatLng(current.latitude[0], current.longitude[0]), {title: current.name[0], icon: greenIcon});
[7793]61
[7734]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() {
[7796]64 mouseOverNode(current.id, current.name[0],latitude, longitude);
[7734]65 });
[7756]66 GEvent.addListener(marker, 'click', function() {
[7786]67 mouseClickNode(current.id, current.name[0], marker);
[7756]68 });
69 GEvent.addListener(marker, 'mouseout', function() {
70 mouseOutNode(current.id, current.name[0]);
71 });
72
[7786]73 markerArray.push(marker);
[7796]74 //circleArray.push(circle);
[7734]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.
[7786]79function mouseClickNode(id, name, marker)
80{
81 if(selected == true)
82 deSelect();
[7778]83
[7786]84 if(markerSelected == marker)
85 {
86 deSelect();
87 markerSelected = "";
88 }
89 else
90 {
91 selected = true;
92
93 markerSelected = marker;
[7801]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
[7756]96
[7786]97 /*
98 *Hieronder verdergaan met dekking
99 */
100
101 }
[7734]102}
[7756]103//Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
[7796]104function mouseOverNode(id, name, latitude, longitude)
[7756]105{
[7786]106 overNode = true;
[7756]107 if(!selected == true)
108 {
[7798]109
110 drawCircle(latitude, longitude, 2.0, "#6C3", 1, 0.75, "#0F0",.2, 200);
[7800]111 polygons_on_map_array.push(polygon);
[7796]112 map.addOverlay(polygon);
[7798]113
[7801]114 loadXMLDoc("inc/node_info.php?type=single&name="+name+"");//Path should be in config
[7782]115
[7756]116 /*
117 *Hieronder verdergaan met dekking
118 */
[7793]119
[7756]120 }
121}
[7734]122
[7756]123function mouseOutNode(id, name)
124{
125 overNode = false;
[7778]126 map.removeOverlay(polygon);
127
[7756]128}
129
[7734]130//Our mouseover function for Cluster nodes. 'markers' is an array containing all markers within the cluster
131function mouseOverCluster(markers)
132{
[7756]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;
[7798]137 var markerLatLngs = new Array;
138
[7756]139 for(var i=0; i<markers.length; i++) {
[7798]140
[7756]141 markerTitles.push(markers[i].marker.getTitle());
[7798]142 markerLatLngs.push(markers[i].marker.getLatLng() );
[7756]143 }
144
[7798]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
[7756]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)
[7793]191{
192 if(selected == true)
193 deselect();
194
[7756]195 //Let the rest of the program know that something is selected
196 select();
197
[7736]198 //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
[7734]199 var markerTitles = new Array;
200 for(var i=0; i<markers.length; i++) {
201 markerTitles.push(markers[i].marker.getTitle());
[7798]202
[7722]203 }
[7733]204
[7735]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
[7756]221 loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"&sel=selected")
[7734]222}
[7665]223
[7798]224function mouseOutCluster(markers)
[7800]225{
[7798]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
[7756]242function select()
[7738]243{
[7756]244 selected = true;
[7738]245}
[7734]246
[7756]247function deSelect()
248{
249 selected = false;
250 loadXMLDoc("inc/node_info.php");
[7786]251 markerSelected.setImage("../img/sleutelGroen.png");
252
[7800]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
[7756]259}
[7738]260
[7786]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
[7734]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}
[7778]309
[7802]310function toggleGoogleSearchMap()
[7801]311{
[7802]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 }
[7801]330}
[7778]331
332
333
[7801]334
335
Note: See TracBrowser for help on using the repository browser.