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

Last change on this file since 7781 was 7779, checked in by ddboer, 16 years ago

-Custom icons
-New icons,with shadow and other features created with this site:

http://www.powerhut.co.uk/googlemaps/custom_markers.php

-Added iconstyle.js

File size: 5.6 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]), greenIcon, false, {title: current.name[0]}) ;
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 map.removeOverlay(polygon);
76 loadXMLDoc("inc/node_info.php?type=single");
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, long)
87{
88 if(!selected == true)
89 {
90 overNode = true;
91
92
93 //alert(long);
94
95 loadXMLDoc("inc/node_info.php?type=single&name="+name+"");
96 /*
97 *Hieronder verdergaan met dekking
98 */
99 drawCircle(lat, long, 2.0, "#6C3", 1, 0.75, "#0F0",.2);
100
101
102
103
104
105
106
107
108
109 }
110}
111
112function mouseOutNode(id, name)
113{
114 overNode = false;
115 map.removeOverlay(polygon);
116
117}
118
119//Our mouseover function for Cluster nodes. 'markers' is an array containing all markers within the cluster
120function mouseOverCluster(markers)
121{
122 if(!selected == true)
123 {
124 //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
125 var markerTitles = new Array;
126 for(var i=0; i<markers.length; i++) {
127 markerTitles.push(markers[i].marker.getTitle());
128 }
129
130 var markerTitleSerialized;
131
132 //start
133 var a_php = "";
134 var total = 0;
135
136 for (var i=0; i<markerTitles.length; i++)
137 {
138 ++ total;
139 a_php = a_php + "s:" +
140 String(i).length + ":\"" + String(i) + "\";s:" +
141 String(markerTitles[i]).length + ":\"" + String(markerTitles[i]) + "\";";
142 }
143 a_php = "a:" + total + ":{" + a_php + "}";
144 //end
145
146 loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"")
147 /*
148 *Hieronder verdergaan met dekking
149 */
150 }
151}
152
153//Our click function for Cluster nodes. 'markers' is an array containing all markers within the cluster
154function clickCluster(markers)
155{
156 //Let the rest of the program know that something is selected
157 select();
158
159 //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
160 var markerTitles = new Array;
161 for(var i=0; i<markers.length; i++) {
162 markerTitles.push(markers[i].marker.getTitle());
163 }
164
165 var markerTitleSerialized;
166
167 //start
168 var a_php = "";
169 var total = 0;
170
171 for (var i=0; i<markerTitles.length; i++)
172 {
173 ++ total;
174 a_php = a_php + "s:" +
175 String(i).length + ":\"" + String(i) + "\";s:" +
176 String(markerTitles[i]).length + ":\"" + String(markerTitles[i]) + "\";";
177 }
178 a_php = "a:" + total + ":{" + a_php + "}";
179 //end
180
181 loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"&sel=selected")
182}
183
184function select()
185{
186 selected = true;
187}
188
189function deSelect()
190{
191 selected = false;
192 loadXMLDoc("inc/node_info.php");
193}
194
195//Code from w3schools. http://www.w3schools.com/dom/dom_http.asp
196function loadXMLDoc(url)
197{
198xmlhttp=null;
199if (window.XMLHttpRequest)
200 {// code for Firefox, Opera, IE7, etc.
201 xmlhttp=new XMLHttpRequest();
202 }
203else if (window.ActiveXObject)
204 {// code for IE6, IE5
205 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
206 }
207if (xmlhttp!=null)
208 {
209 xmlhttp.onreadystatechange=state_Change;
210 xmlhttp.open("GET",url,true);
211 xmlhttp.send(null);
212 }
213else
214 {
215 alert("Your browser does not support XMLHTTP.");
216 }
217}
218
219function state_Change()
220{
221if (xmlhttp.readyState==4)
222 {// 4 = "loaded"
223 if (xmlhttp.status==200)
224 {// 200 = "OK"
225 document.getElementById(targetDiv).innerHTML=xmlhttp.responseText;
226 }
227 else
228 {
229 alert("Problem retrieving data:" + xmlhttp.statusText);
230 }
231 }
232}
233
234
235
236
237
Note: See TracBrowser for help on using the repository browser.