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