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

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

Fixed map(GMarker constructor) and renamed variable long to longitude.

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