1 | //Declaring some variables we will be using
|
---|
2 | var map;
|
---|
3 | var toggleState = 1;
|
---|
4 | var marker_hash = {};
|
---|
5 | var markerArray = new Array();
|
---|
6 | var circleArray = new Array();
|
---|
7 | var xmlhttp;
|
---|
8 | var targetDiv = "infotop";
|
---|
9 | var selected = false;
|
---|
10 | var overNode;
|
---|
11 | var markerSelected;
|
---|
12 |
|
---|
13 |
|
---|
14 | //This function is called from index.php
|
---|
15 | function 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 |
|
---|
44 | var markerClusterer = new MarkerClusterer(map, markerArray);
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | //This function will contain the displaying and not displaying of nodes on the map
|
---|
49 | function toggleMyKml() {
|
---|
50 |
|
---|
51 | }
|
---|
52 |
|
---|
53 | //This function adds a marker with an object from our 'marker'array defined in index.php
|
---|
54 | function addMarker(current, i) {
|
---|
55 | var id = current.id;
|
---|
56 | var latitude = Number(current.latitude[0]);
|
---|
57 | var longitude = Number(current.longitude[0]);
|
---|
58 | //var circle = drawCircle(latitude, longitude, 2.0, "#6C3", 1, 0.75, "#0F0",.2);
|
---|
59 | var marker = new GMarker(new GLatLng(current.latitude[0], current.longitude[0]), {title: current.name[0], icon: greenIcon});
|
---|
60 |
|
---|
61 | //Added mouseover listener that calls on our mouseOver function when the mouse moves over a marker on the map
|
---|
62 | GEvent.addListener(marker, 'mouseover', function() {
|
---|
63 | mouseOverNode(current.id, current.name[0],latitude, longitude);
|
---|
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.
|
---|
78 | function 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.
|
---|
104 | function mouseOverNode(id, name, latitude, longitude)
|
---|
105 | {
|
---|
106 | overNode = true;
|
---|
107 | if(!selected == true)
|
---|
108 | {
|
---|
109 | drawCircle(latitude, longitude, 2.0, "#6C3", 1, 0.75, "#0F0",.2);
|
---|
110 | map.addOverlay(polygon);
|
---|
111 | loadXMLDoc("inc/node_info.php?type=single&name="+name+"");
|
---|
112 |
|
---|
113 | /*
|
---|
114 | *Hieronder verdergaan met dekking
|
---|
115 | */
|
---|
116 |
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | function mouseOutNode(id, name)
|
---|
121 | {
|
---|
122 | overNode = false;
|
---|
123 | map.removeOverlay(polygon);
|
---|
124 |
|
---|
125 | }
|
---|
126 |
|
---|
127 | //Our mouseover function for Cluster nodes. 'markers' is an array containing all markers within the cluster
|
---|
128 | function mouseOverCluster(markers)
|
---|
129 | {
|
---|
130 | if(!selected == true)
|
---|
131 | {
|
---|
132 | //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
|
---|
133 | var markerTitles = new Array;
|
---|
134 | for(var i=0; i<markers.length; i++) {
|
---|
135 | markerTitles.push(markers[i].marker.getTitle());
|
---|
136 | }
|
---|
137 |
|
---|
138 | var markerTitleSerialized;
|
---|
139 |
|
---|
140 | //start
|
---|
141 | var a_php = "";
|
---|
142 | var total = 0;
|
---|
143 |
|
---|
144 | for (var i=0; i<markerTitles.length; i++)
|
---|
145 | {
|
---|
146 | ++ total;
|
---|
147 | a_php = a_php + "s:" +
|
---|
148 | String(i).length + ":\"" + String(i) + "\";s:" +
|
---|
149 | String(markerTitles[i]).length + ":\"" + String(markerTitles[i]) + "\";";
|
---|
150 | }
|
---|
151 | a_php = "a:" + total + ":{" + a_php + "}";
|
---|
152 | //end
|
---|
153 |
|
---|
154 | loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"")
|
---|
155 | /*
|
---|
156 | *Hieronder verdergaan met dekking
|
---|
157 | */
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | //Our click function for Cluster nodes. 'markers' is an array containing all markers within the cluster
|
---|
162 | function clickCluster(markers)
|
---|
163 | {
|
---|
164 | if(selected == true)
|
---|
165 | deselect();
|
---|
166 |
|
---|
167 | //Let the rest of the program know that something is selected
|
---|
168 | select();
|
---|
169 |
|
---|
170 | //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
|
---|
171 | var markerTitles = new Array;
|
---|
172 | for(var i=0; i<markers.length; i++) {
|
---|
173 | markerTitles.push(markers[i].marker.getTitle());
|
---|
174 | }
|
---|
175 |
|
---|
176 | var markerTitleSerialized;
|
---|
177 |
|
---|
178 | //start
|
---|
179 | var a_php = "";
|
---|
180 | var total = 0;
|
---|
181 |
|
---|
182 | for (var i=0; i<markerTitles.length; i++)
|
---|
183 | {
|
---|
184 | ++ total;
|
---|
185 | a_php = a_php + "s:" +
|
---|
186 | String(i).length + ":\"" + String(i) + "\";s:" +
|
---|
187 | String(markerTitles[i]).length + ":\"" + String(markerTitles[i]) + "\";";
|
---|
188 | }
|
---|
189 | a_php = "a:" + total + ":{" + a_php + "}";
|
---|
190 | //end
|
---|
191 |
|
---|
192 | loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"&sel=selected")
|
---|
193 | }
|
---|
194 |
|
---|
195 | function select()
|
---|
196 | {
|
---|
197 | selected = true;
|
---|
198 | }
|
---|
199 |
|
---|
200 | function deSelect()
|
---|
201 | {
|
---|
202 | selected = false;
|
---|
203 | loadXMLDoc("inc/node_info.php");
|
---|
204 | markerSelected.setImage("../img/sleutelGroen.png");
|
---|
205 |
|
---|
206 | }
|
---|
207 |
|
---|
208 | function removeOtherSelect()
|
---|
209 | {
|
---|
210 | for(var i=0; i<markerArray.length; i++)
|
---|
211 | {
|
---|
212 | currentmarker = markerArray[i];
|
---|
213 | currentmarker.setImage("../sleutelGroen.png");
|
---|
214 | }
|
---|
215 | return true;
|
---|
216 | }
|
---|
217 |
|
---|
218 | //Code from w3schools. http://www.w3schools.com/dom/dom_http.asp
|
---|
219 | function loadXMLDoc(url)
|
---|
220 | {
|
---|
221 | xmlhttp=null;
|
---|
222 | if (window.XMLHttpRequest)
|
---|
223 | {// code for Firefox, Opera, IE7, etc.
|
---|
224 | xmlhttp=new XMLHttpRequest();
|
---|
225 | }
|
---|
226 | else if (window.ActiveXObject)
|
---|
227 | {// code for IE6, IE5
|
---|
228 | xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
|
---|
229 | }
|
---|
230 | if (xmlhttp!=null)
|
---|
231 | {
|
---|
232 | xmlhttp.onreadystatechange=state_Change;
|
---|
233 | xmlhttp.open("GET",url,true);
|
---|
234 | xmlhttp.send(null);
|
---|
235 | }
|
---|
236 | else
|
---|
237 | {
|
---|
238 | alert("Your browser does not support XMLHTTP.");
|
---|
239 | }
|
---|
240 | }
|
---|
241 |
|
---|
242 | function state_Change()
|
---|
243 | {
|
---|
244 | if (xmlhttp.readyState==4)
|
---|
245 | {// 4 = "loaded"
|
---|
246 | if (xmlhttp.status==200)
|
---|
247 | {// 200 = "OK"
|
---|
248 | document.getElementById(targetDiv).innerHTML=xmlhttp.responseText;
|
---|
249 | }
|
---|
250 | else
|
---|
251 | {
|
---|
252 | alert("Problem retrieving data:" + xmlhttp.statusText);
|
---|
253 | }
|
---|
254 | }
|
---|
255 | }
|
---|
256 |
|
---|
257 |
|
---|
258 |
|
---|
259 |
|
---|
260 |
|
---|