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

Last change on this file since 7795 was 7793, checked in by janveeden, 16 years ago

David: Fixed the lat long issue. Typecast to number was need. Your circles are now on map. Please fix them to the background, and make the hiding at start.

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