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

Last change on this file since 7866 was 7847, checked in by Pieter Naber, 16 years ago

Laatste aanpassingen!

File size: 10.5 KB
RevLine 
[7722]1//Declaring some variables we will be using
[7802]2var gmap_search_state = false;
[7809]3
[7694]4var map;
[7825]5var markerArray = [];
6var circleArray = [];
[7847]7var totalCircleArray = [];
[7825]8var polygons_on_map_array = [];
[7734]9var xmlhttp;
10var targetDiv = "infotop";
[7786]11var selected = false;
[7756]12var overNode;
[7809]13var markerSelected = "";
[7832]14var highlightCircle;
15var currentMarker;
[7847]16var toggleCircles = false;
[7665]17
[7847]18// This function is called from index.php
[7734]19function initialize_map() {
[7847]20 // We will only do this function if the browser is compatible
21 if (GBrowserIsCompatible()) {
22 // Adding the google map into the div called #mapcanvas
23 map = new GMap2(document.getElementById("mapcanvas"), {
24 googleBarOptions : {
25 style : "new"
26 }
27 });
28 // Center the map on Leiden
29 map.setCenter(new GLatLng(52.162687, 4.493294), 11); // Vars should
30 // go to config
31 map.setUIToDefault();
[7802]32
[7847]33 /*
34 * Go through the array 'markers' (Declared in index.php) and add a
35 * marker for each marker stored in the array using our addMarker
36 * function. If the latLng of the marker is both 0
37 */
38 for ( var i = 0; i < markers.length; i++) {
[7830]39 var current = markers[i];
[7847]40 if (current.latitude[0] > 0 || current.latitude[0] < 0) {
[7830]41 addMarker(current, i);
42 }
[7823]43 }
[7847]44
[7830]45 GEvent.addListener(map, "click", function() {
[7847]46 if (!overNode == true)
[7830]47 deSelect();
48 });
[7847]49
[7830]50 GEvent.addListener(map, "zoomend", function() {
51 mapZoomed();
52 });
[7847]53
[7830]54 suggestMarkers("");
[7847]55
[7830]56 new MarkerClusterer(map, markerArray);
[7734]57 }
[7847]58}
[7734]59
[7847]60// This function will contain the displaying and not displaying of nodes on the
61// map
[7734]62function toggleMyKml() {
63
64}
65
[7847]66// This function adds a marker with an object from our 'marker'array defined in
67// index.php
[7734]68function addMarker(current, i) {
[7793]69 var latitude = Number(current.latitude[0]);
70 var longitude = Number(current.longitude[0]);
[7847]71
[7830]72 var displayIcon;
73 var currentstatus = current.status[0];
[7847]74 if (currentstatus == "up") {
[7830]75 displayIcon = greenIcon;
[7847]76 } else {
[7830]77 displayIcon = redIcon;
78 }
[7847]79
80 var marker = new GMarker(new GLatLng(current.latitude[0],
81 current.longitude[0]), {
82 title : current.name[0],
83 icon : displayIcon
84 });
85
86 // Added mouseover listener that calls on our mouseOver function when the
87 // mouse moves over a marker on the map
[7734]88 GEvent.addListener(marker, 'mouseover', function() {
[7847]89 mouseOverNode(current.id, current.name[0], latitude, longitude);
[7734]90 });
[7756]91 GEvent.addListener(marker, 'click', function() {
[7847]92 mouseClickNode(current.id, current.name[0], marker);
[7756]93 });
94 GEvent.addListener(marker, 'mouseout', function() {
[7847]95 mouseOutNode(current.id, current.name[0]);
[7756]96 });
[7847]97
[7786]98 markerArray.push(marker);
[7847]99 // circleArray.push(circle);
[7734]100 return marker;
101}
102
[7847]103// Our mouseover function for single nodes. Gives the ID(our own given ID) and
104// the name of the node.
105function mouseClickNode(id, name, marker) {
106 if (selected == true) {
[7786]107 deSelect();
[7824]108 markerSelected = "";
109 }
[7847]110
111 if (markerSelected == marker) {
[7786]112 deSelect();
113 markerSelected = "";
[7847]114 } else {
[7786]115 selected = true;
116 markerSelected = marker;
[7847]117 for ( var i = 0; i < markers.length; i++) {
118 var currentmarker = markers[i];
119 if (currentmarker.name[0] == marker.getTitle()) {
120 if (currentmarker.status[0] == "up") {
[7830]121 marker.setImage("../img/sleutelGroenSelected.png");
[7847]122 } else {
[7830]123 marker.setImage("../img/sleutelRoodSelected.png");
124 }
[7847]125
[7830]126 }
127 }
[7847]128 loadXMLDoc("inc/node_info.php?type=single&name=" + name + "&a="
129 + Math.random());
[7786]130 }
[7734]131}
[7847]132// Our mouseover function for single nodes. Gives the ID(our own given ID) and
133// the name of the node.
134function mouseOverNode(id, name, latitude, longitude) {
[7786]135 overNode = true;
[7847]136 if (!selected == true) {
137
138 drawCircle(latitude, longitude, 0.1, "#6C3", 1, 0.75, "#0F0", .2, 200);
[7800]139 polygons_on_map_array.push(polygon);
[7796]140 map.addOverlay(polygon);
[7782]141
[7847]142 loadXMLDoc("inc/node_info.php?type=single&name=" + name + "&a="
143 + Math.random());// Path should be in config
144
[7756]145 /*
[7847]146 * Hieronder verdergaan met dekking
147 */
148
149 }
[7756]150}
[7734]151
[7847]152function mouseOutNode(id, name) {
[7756]153 overNode = false;
[7778]154 map.removeOverlay(polygon);
155
[7756]156}
157
[7847]158// Our mouseover function for Cluster nodes. 'markers' is an array containing
159// all markers within the cluster
160function mouseOverCluster(markers) {
161 if (!selected == true) {
162 // Make 'markers' array (containing gmarkers) into an array containing
163 // only the titles(names) of the markers
[7756]164 var markerTitles = new Array;
[7809]165 var markerLatLngs = new Array;
[7847]166
167 for ( var i = 0; i < markers.length; i++) {
[7756]168 markerTitles.push(markers[i].marker.getTitle());
[7847]169 markerLatLngs.push(markers[i].marker.getLatLng());
[7756]170 }
171
172 var markerTitleSerialized;
173
[7847]174 // start
[7756]175 var a_php = "";
176 var total = 0;
177
[7847]178 for ( var i = 0; i < markerTitles.length; i++) {
179 ++total;
180 a_php = a_php + "s:" + String(i).length + ":\"" + String(i)
181 + "\";s:" + String(markerTitles[i]).length + ":\""
182 + String(markerTitles[i]) + "\";";
[7756]183 }
184 a_php = "a:" + total + ":{" + a_php + "}";
[7847]185 // end
[7756]186
[7847]187 loadXMLDoc("inc/node_info.php?type=cluster&markers=" + a_php + "&rand="
188 + Math.random());
[7756]189 /*
[7847]190 * Hieronder verdergaan met dekking
191 */
192
193 for ( var i = 0; i < markerLatLngs.length; i++) {
194 latLng = String(markerLatLngs[i]);
195
196 pos = latLng.indexOf(',');
197 pos2 = latLng.length - 1;
198
199 var latitude = Number(latLng.substring(1, pos));
200 var longitude = Number(latLng.substring(2 + pos, pos2));
201
202 drawCircle(latitude, longitude, 0.1, "#6C3", 1, 0.75, "#0F0", .2);
203
204 map.addOverlay(polygon);
205 polygons_on_map_array.push(polygon);
206 }
[7756]207 }
208}
209
[7847]210// Our click function for Cluster nodes. 'markers' is an array containing all
211// markers within the cluster
212function clickCluster(markers) {
213 if (selected == true)
[7793]214 deselect();
[7847]215
216 // Let the rest of the program know that something is selected
[7756]217 select();
218
[7847]219 // Make 'markers' array (containing gmarkers) into an array containing only
220 // the titles(names) of the markers
[7734]221 var markerTitles = new Array;
[7847]222 for ( var i = 0; i < markers.length; i++) {
[7809]223 markerTitles.push(markers[i].marker.getTitle());
[7847]224
[7722]225 }
[7847]226
[7735]227 var markerTitleSerialized;
[7847]228
229 // start
[7735]230 var a_php = "";
[7847]231 var total = 0;
232
233 for ( var i = 0; i < markerTitles.length; i++) {
234 ++total;
235 a_php = a_php + "s:" + String(i).length + ":\"" + String(i) + "\";s:"
236 + String(markerTitles[i]).length + ":\""
237 + String(markerTitles[i]) + "\";";
238 }
239 a_php = "a:" + total + ":{" + a_php + "}";
240 // end
241
242 loadXMLDoc("inc/node_info.php?type=cluster&markers=" + a_php
243 + "&sel=selected" + "&a=" + Math.random())
[7734]244}
[7665]245
[7847]246function mouseOutCluster(markers) {
[7813]247 removeAllPolgygons();
[7812]248}
249
[7847]250function mapZoomed() {
[7835]251
[7847]252 if (!markerSelected == "") {
[7825]253 markerSelected.setImage("../img/sleutelGroenSelected.png");
254 }
[7847]255
[7835]256 if (highlightCircle) {
257 map.removeOverlay(highlightCircle);
[7847]258 }
[7824]259}
260
[7847]261function removeAllPolgygons() {
262 for ( var i = 0; i < polygons_on_map_array.length; i++) {
[7812]263 var currentpolygon = polygons_on_map_array[i];
264 map.removeOverlay(currentpolygon);
[7847]265
[7798]266 }
[7812]267 polygons_on_map_array.clear();
[7798]268}
269
[7847]270function select() {
[7756]271 selected = true;
[7738]272}
[7734]273
[7847]274function deSelect() {
[7832]275 map.removeOverlay(highlightCircle);
[7809]276 selected = false;
277 loadXMLDoc("inc/node_info.php");
[7847]278 if (!markerSelected == "") {
279 for ( var i = 0; i < markers.length; i++) {
280 var currentmarker = markers[i];
281 if (currentmarker.name[0] == markerSelected.getTitle()) {
282 if (currentmarker.status[0] == "up") {
[7830]283 markerSelected.setImage("../img/sleutelGroen.png");
[7847]284 } else {
[7830]285 markerSelected.setImage("../img/sleutelRood.png");
286 }
[7847]287
[7830]288 }
289 }
[7824]290 markerSelected = "";
291 }
[7847]292
[7812]293 removeAllPolgygons();
[7847]294
[7756]295}
[7738]296
[7847]297function removeOtherSelect() {
298 for ( var i = 0; i < markerArray.length; i++) {
[7786]299 currentmarker = markerArray[i];
300 currentmarker.setImage("../sleutelGroen.png");
301 }
302 return true;
303}
304
[7847]305// Code from w3schools. http://www.w3schools.com/dom/dom_http.asp
306function loadXMLDoc(url, targetDiv) {
307 xmlhttp = null;
308 if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc.
309 xmlhttp = new XMLHttpRequest();
310 } else if (window.ActiveXObject) {// code for IE6, IE5
311 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
312 }
313 if (xmlhttp != null) {
314 xmlhttp.onreadystatechange = state_Change();
315 xmlhttp.open("GET", url, true);
316 xmlhttp.send(null);
317 } else {
318 alert("Your browser does not support XMLHTTP.");
319 }
[7734]320}
321
[7847]322function state_Change() {
323 if (xmlhttp.readyState == 4) {// 4 = "loaded"
324 if (xmlhttp.status == 200) {// 200 = "OK"
325 document.getElementById(targetDiv).innerHTML = xmlhttp.responseText;
326 } else {
327 alert("Problem retrieving data:" + xmlhttp.statusText);
328 }
329 }
[7734]330}
[7778]331
[7847]332function loadSuggest(url) {
333 xmlhttp = null;
334 if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc.
335 xmlhttp = new XMLHttpRequest();
336 } else if (window.ActiveXObject) {// code for IE6, IE5
337 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
338 }
339 if (xmlhttp != null) {
340 xmlhttp.onreadystatechange = state_ChangeSuggest;
341 xmlhttp.open("GET", url, true);
342 xmlhttp.send(null);
343 } else {
344 alert("Your browser does not support XMLHTTP.");
345 }
[7805]346}
347
[7847]348function state_ChangeSuggest() {
349 if (xmlhttp.readyState == 4) {// 4 = "loaded"
350 if (xmlhttp.status == 200) {// 200 = "OK"
351 document.getElementById("searchlist").innerHTML = xmlhttp.responseText;
352 } else {
353 alert("Problem retrieving data:" + xmlhttp.statusText);
354 }
355 }
[7805]356}
357
[7847]358function suggestMarkers(value) {
359 loadSuggest("inc/suggestions.php?value=" + value + "&a=" + Math.random());
[7805]360}
[7778]361
[7847]362function goToMarker(value) {
363 for ( var i = 0; i < markerArray.length; i++) {
[7820]364 var name = markerArray[i].getTitle();
[7847]365
366 if (name == value) {
[7820]367 map.setCenter(markerArray[i].getLatLng(), 15);
[7847]368 loadXMLDoc("inc/node_info.php?type=single&name=" + value + "&a="
369 + Math.random())
[7820]370 }
371 }
372}
373
[7847]374function toggleGoogleSearchMap() {
375 if (gmap_search_state) {
[7816]376 gmap_search_state = false;
[7847]377 } else {
[7816]378 gmap_search_state = true;
379 }
[7847]380
381 if (gmap_search_state) {
[7816]382 map.enableGoogleBar();
383 }
[7847]384
385 if (!gmap_search_state) {
[7816]386 map.disableGoogleBar();
387 }
388}
[7778]389
[7847]390function toggleAllCircles() {
391 toggleCircles = !toggleCircles;
[7801]392
[7847]393 if (toggleCircles == true) {
394 for ( var i = 0; i < markers.length; i++) {
395 var current = markers[i];
396 if (current.latitude[0] > 0 || current.latitude[0] < 0) {
397 drawCircle(Number(current.latitude[0]), Number(current.longitude[0]), 0.1, "#6C3", 1, 0.75, "#0F0", .2);
[7816]398
[7847]399 map.addOverlay(polygon);
400 totalCircleArray.push(polygon);
401 }
402 }
403 } else {
404 for ( var i = 0; i < totalCircleArray.length; i++) {
405 var currentpolygon = totalCircleArray[i];
406 map.removeOverlay(currentpolygon);
407
408 }
409 totalCircleArray.clear();
410 }
411}
Note: See TracBrowser for help on using the repository browser.