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
Line 
1//Declaring some variables we will be using
2var map;
3var toggleState = 1;
4var marker_hash = {};
5var markerArray = new Array();
6var xmlhttp;
7var targetDiv = "infotop";
8var selected = false;
9var overNode;
10var markerSelected;
11
12
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();
22
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];
27 var gMarker = addMarker(current, i);
28 }
29
30 GEvent.addListener(map, "click", function() {
31 if(!overNode == true)
32 deSelect();
33 });
34
35 /*
36 * Hier zo circles toevoegen.
37 */
38
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;
51 var marker = new GMarker(new GLatLng(current.latitude[0], current.longitude[0]), {title: current.name[0], icon: greenIcon});
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() {
54 //mouseOverNode(current.id, current.name[0],52.118860692234, 4.5015095076528);
55 mouseOverNode(current.id, current.name[0],current.latitude[0], current.longitude[0]);
56 });
57 GEvent.addListener(marker, 'click', function() {
58 mouseClickNode(current.id, current.name[0], marker);
59 });
60 GEvent.addListener(marker, 'mouseout', function() {
61 mouseOutNode(current.id, current.name[0]);
62 });
63
64 markerArray.push(marker);
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.
69function mouseClickNode(id, name, marker)
70{
71 if(selected == true)
72 deSelect();
73
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+"");
86
87 /*
88 *Hieronder verdergaan met dekking
89 */
90
91 map.removeOverlay(polygon);
92 }
93}
94//Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
95function mouseOverNode(id, name, lat, longitude)
96{
97 overNode = true;
98 if(!selected == true)
99 {
100 loadXMLDoc("inc/node_info.php?type=single&name="+name+"");
101
102 //alert(long);
103 /*
104 *Hieronder verdergaan met dekking
105 */
106 drawCircle(lat, longitude, 2.0, "#6C3", 1, 0.75, "#0F0",.2);
107 }
108}
109
110function mouseOutNode(id, name)
111{
112 overNode = false;
113 map.removeOverlay(polygon);
114
115}
116
117//Our mouseover function for Cluster nodes. 'markers' is an array containing all markers within the cluster
118function mouseOverCluster(markers)
119{
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
157 //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
158 var markerTitles = new Array;
159 for(var i=0; i<markers.length; i++) {
160 markerTitles.push(markers[i].marker.getTitle());
161 }
162
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
179 loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"&sel=selected")
180}
181
182function select()
183{
184 selected = true;
185}
186
187function deSelect()
188{
189 selected = false;
190 loadXMLDoc("inc/node_info.php");
191 markerSelected.setImage("../img/sleutelGroen.png");
192
193}
194
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
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}
243
244
245
246
247
Note: See TracBrowser for help on using the repository browser.