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

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