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

Last change on this file since 7797 was 7796, checked in by ddboer, 16 years ago

Single node, mouse over range area now works

File size: 6.4 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();
[7793]6var circleArray = new Array();
[7734]7var xmlhttp;
8var targetDiv = "infotop";
[7786]9var selected = false;
[7756]10var overNode;
[7786]11var markerSelected;
[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
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();
[7778]23
[7734]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];
[7767]28 var gMarker = addMarker(current, i);
[7734]29 }
[7694]30
[7756]31 GEvent.addListener(map, "click", function() {
32 if(!overNode == true)
33 deSelect();
34 });
35
[7767]36 /*
37 * Hier zo circles toevoegen.
[7796]38
[7793]39 for(var i=0; i<circleArray.length; i++) {
40 map.addOverlay(circleArray[i]);
41 }
[7796]42 */
[7767]43
[7734]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
49function toggleMyKml() {
50
51}
52
53//This function adds a marker with an object from our 'marker'array defined in index.php
54function addMarker(current, i) {
55 var id = current.id;
[7793]56 var latitude = Number(current.latitude[0]);
57 var longitude = Number(current.longitude[0]);
[7796]58 //var circle = drawCircle(latitude, longitude, 2.0, "#6C3", 1, 0.75, "#0F0",.2);
[7783]59 var marker = new GMarker(new GLatLng(current.latitude[0], current.longitude[0]), {title: current.name[0], icon: greenIcon});
[7793]60
[7734]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() {
[7796]63 mouseOverNode(current.id, current.name[0],latitude, longitude);
[7734]64 });
[7756]65 GEvent.addListener(marker, 'click', function() {
[7786]66 mouseClickNode(current.id, current.name[0], marker);
[7756]67 });
68 GEvent.addListener(marker, 'mouseout', function() {
69 mouseOutNode(current.id, current.name[0]);
70 });
71
[7786]72 markerArray.push(marker);
[7796]73 //circleArray.push(circle);
[7734]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.
[7786]78function mouseClickNode(id, name, marker)
79{
80 if(selected == true)
81 deSelect();
[7778]82
[7786]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+"");
[7756]95
[7786]96 /*
97 *Hieronder verdergaan met dekking
98 */
99
100 map.removeOverlay(polygon);
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 {
[7796]109 drawCircle(latitude, longitude, 2.0, "#6C3", 1, 0.75, "#0F0",.2);
110 map.addOverlay(polygon);
[7782]111 loadXMLDoc("inc/node_info.php?type=single&name="+name+"");
112
[7756]113 /*
114 *Hieronder verdergaan met dekking
115 */
[7793]116
[7756]117 }
118}
[7734]119
[7756]120function mouseOutNode(id, name)
121{
122 overNode = false;
[7778]123 map.removeOverlay(polygon);
124
[7756]125}
126
[7734]127//Our mouseover function for Cluster nodes. 'markers' is an array containing all markers within the cluster
128function mouseOverCluster(markers)
129{
[7756]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
162function clickCluster(markers)
[7793]163{
164 if(selected == true)
165 deselect();
166
[7756]167 //Let the rest of the program know that something is selected
168 select();
169
[7736]170 //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
[7734]171 var markerTitles = new Array;
172 for(var i=0; i<markers.length; i++) {
173 markerTitles.push(markers[i].marker.getTitle());
[7722]174 }
[7733]175
[7735]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
[7756]192 loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"&sel=selected")
[7734]193}
[7665]194
[7756]195function select()
[7738]196{
[7756]197 selected = true;
[7738]198}
[7734]199
[7756]200function deSelect()
201{
202 selected = false;
203 loadXMLDoc("inc/node_info.php");
[7786]204 markerSelected.setImage("../img/sleutelGroen.png");
205
[7756]206}
[7738]207
[7786]208function 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
[7734]218//Code from w3schools. http://www.w3schools.com/dom/dom_http.asp
219function loadXMLDoc(url)
220{
221xmlhttp=null;
222if (window.XMLHttpRequest)
223 {// code for Firefox, Opera, IE7, etc.
224 xmlhttp=new XMLHttpRequest();
225 }
226else if (window.ActiveXObject)
227 {// code for IE6, IE5
228 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
229 }
230if (xmlhttp!=null)
231 {
232 xmlhttp.onreadystatechange=state_Change;
233 xmlhttp.open("GET",url,true);
234 xmlhttp.send(null);
235 }
236else
237 {
238 alert("Your browser does not support XMLHTTP.");
239 }
240}
241
242function state_Change()
243{
244if (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}
[7778]256
257
258
259
260
Note: See TracBrowser for help on using the repository browser.