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

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

Selecting individual markers works like a sunshine. Clusternodes selecting still has to be fixed. (changing icons etc.)

File size: 6.1 KB
RevLine 
[7722]1//Declaring some variables we will be using
[7694]2var map;
3var toggleState = 1;
[7722]4var marker_hash = {};
[7732]5var markerArray = new Array();
[7734]6var xmlhttp;
7var targetDiv = "infotop";
[7786]8var selected = false;
[7756]9var overNode;
[7786]10var markerSelected;
[7665]11
[7778]12
[7734]13//This function is called from index.php
14function initialize_map() {
15 //We will only do this function if the browser is compatible
16 if (GBrowserIsCompatible()) {
17 //Adding the google map into the div called #mapcanvas
18 map = new GMap2(document.getElementById("mapcanvas"));
19 //Center the map on Leiden
20 map.setCenter(new GLatLng(52.162687, 4.493294), 11);
21 map.setUIToDefault();
[7778]22
[7734]23
24 //Go through the array 'markers' (Declared in index.php) and add a marker for each marker stored in the array using our addMarker function
25 for (var i=0; i<markers.length; i++) {
26 var current = markers[i];
[7767]27 var gMarker = addMarker(current, i);
[7734]28 }
[7694]29
[7756]30 GEvent.addListener(map, "click", function() {
31 if(!overNode == true)
32 deSelect();
33 });
34
[7767]35 /*
36 * Hier zo circles toevoegen.
37 */
38
[7734]39 var markerClusterer = new MarkerClusterer(map, markerArray);
40 }
41}
42
43//This function will contain the displaying and not displaying of nodes on the map
44function toggleMyKml() {
45
46}
47
48//This function adds a marker with an object from our 'marker'array defined in index.php
49function addMarker(current, i) {
50 var id = current.id;
[7783]51 var marker = new GMarker(new GLatLng(current.latitude[0], current.longitude[0]), {title: current.name[0], icon: greenIcon});
[7734]52 //Added mouseover listener that calls on our mouseOver function when the mouse moves over a marker on the map
53 GEvent.addListener(marker, 'mouseover', function() {
[7779]54 //mouseOverNode(current.id, current.name[0],52.118860692234, 4.5015095076528);
55 mouseOverNode(current.id, current.name[0],current.latitude[0], current.longitude[0]);
[7734]56 });
[7756]57 GEvent.addListener(marker, 'click', function() {
[7786]58 mouseClickNode(current.id, current.name[0], marker);
[7756]59 });
60 GEvent.addListener(marker, 'mouseout', function() {
61 mouseOutNode(current.id, current.name[0]);
62 });
63
[7786]64 markerArray.push(marker);
[7734]65 return marker;
66}
67
68//Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
[7786]69function mouseClickNode(id, name, marker)
70{
71 if(selected == true)
72 deSelect();
[7778]73
[7786]74 if(markerSelected == marker)
75 {
76 deSelect();
77 markerSelected = "";
78 }
79 else
80 {
81 selected = true;
82
83 markerSelected = marker;
84 marker.setImage("../img/sleutelGroenSelected.png");
85 loadXMLDoc("inc/node_info.php?type=single&name="+name+"");
[7756]86
[7786]87 /*
88 *Hieronder verdergaan met dekking
89 */
90
91 map.removeOverlay(polygon);
92 }
[7734]93}
[7756]94//Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
[7782]95function mouseOverNode(id, name, lat, longitude)
[7756]96{
[7786]97 overNode = true;
[7756]98 if(!selected == true)
99 {
[7782]100 loadXMLDoc("inc/node_info.php?type=single&name="+name+"");
101
[7779]102 //alert(long);
[7756]103 /*
104 *Hieronder verdergaan met dekking
105 */
[7782]106 drawCircle(lat, longitude, 2.0, "#6C3", 1, 0.75, "#0F0",.2);
[7756]107 }
108}
[7734]109
[7756]110function mouseOutNode(id, name)
111{
112 overNode = false;
[7778]113 map.removeOverlay(polygon);
114
[7756]115}
116
[7734]117//Our mouseover function for Cluster nodes. 'markers' is an array containing all markers within the cluster
118function mouseOverCluster(markers)
119{
[7756]120 if(!selected == true)
121 {
122 //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
123 var markerTitles = new Array;
124 for(var i=0; i<markers.length; i++) {
125 markerTitles.push(markers[i].marker.getTitle());
126 }
127
128 var markerTitleSerialized;
129
130 //start
131 var a_php = "";
132 var total = 0;
133
134 for (var i=0; i<markerTitles.length; i++)
135 {
136 ++ total;
137 a_php = a_php + "s:" +
138 String(i).length + ":\"" + String(i) + "\";s:" +
139 String(markerTitles[i]).length + ":\"" + String(markerTitles[i]) + "\";";
140 }
141 a_php = "a:" + total + ":{" + a_php + "}";
142 //end
143
144 loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"")
145 /*
146 *Hieronder verdergaan met dekking
147 */
148 }
149}
150
151//Our click function for Cluster nodes. 'markers' is an array containing all markers within the cluster
152function clickCluster(markers)
153{
154 //Let the rest of the program know that something is selected
155 select();
156
[7736]157 //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
[7734]158 var markerTitles = new Array;
159 for(var i=0; i<markers.length; i++) {
160 markerTitles.push(markers[i].marker.getTitle());
[7722]161 }
[7733]162
[7735]163 var markerTitleSerialized;
164
165 //start
166 var a_php = "";
167 var total = 0;
168
169 for (var i=0; i<markerTitles.length; i++)
170 {
171 ++ total;
172 a_php = a_php + "s:" +
173 String(i).length + ":\"" + String(i) + "\";s:" +
174 String(markerTitles[i]).length + ":\"" + String(markerTitles[i]) + "\";";
175 }
176 a_php = "a:" + total + ":{" + a_php + "}";
177 //end
178
[7756]179 loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"&sel=selected")
[7734]180}
[7665]181
[7756]182function select()
[7738]183{
[7756]184 selected = true;
[7738]185}
[7734]186
[7756]187function deSelect()
188{
189 selected = false;
190 loadXMLDoc("inc/node_info.php");
[7786]191 markerSelected.setImage("../img/sleutelGroen.png");
192
[7756]193}
[7738]194
[7786]195function removeOtherSelect()
196{
197 for(var i=0; i<markerArray.length; i++)
198 {
199 currentmarker = markerArray[i];
200 currentmarker.setImage("../sleutelGroen.png");
201 }
202 return true;
203}
204
[7734]205//Code from w3schools. http://www.w3schools.com/dom/dom_http.asp
206function loadXMLDoc(url)
207{
208xmlhttp=null;
209if (window.XMLHttpRequest)
210 {// code for Firefox, Opera, IE7, etc.
211 xmlhttp=new XMLHttpRequest();
212 }
213else if (window.ActiveXObject)
214 {// code for IE6, IE5
215 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
216 }
217if (xmlhttp!=null)
218 {
219 xmlhttp.onreadystatechange=state_Change;
220 xmlhttp.open("GET",url,true);
221 xmlhttp.send(null);
222 }
223else
224 {
225 alert("Your browser does not support XMLHTTP.");
226 }
227}
228
229function state_Change()
230{
231if (xmlhttp.readyState==4)
232 {// 4 = "loaded"
233 if (xmlhttp.status==200)
234 {// 200 = "OK"
235 document.getElementById(targetDiv).innerHTML=xmlhttp.responseText;
236 }
237 else
238 {
239 alert("Problem retrieving data:" + xmlhttp.statusText);
240 }
241 }
242}
[7778]243
244
245
246
247
Note: See TracBrowser for help on using the repository browser.