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 |
|
---|
9 | //This function is called from index.php
|
---|
10 | function initialize_map() {
|
---|
11 | //We will only do this function if the browser is compatible
|
---|
12 | if (GBrowserIsCompatible()) {
|
---|
13 | //Adding the google map into the div called #mapcanvas
|
---|
14 | map = new GMap2(document.getElementById("mapcanvas"));
|
---|
15 | //Center the map on Leiden
|
---|
16 | map.setCenter(new GLatLng(52.162687, 4.493294), 11);
|
---|
17 | map.setUIToDefault();
|
---|
18 |
|
---|
19 | //Go through the array 'markers' (Declared in index.php) and add a marker for each marker stored in the array using our addMarker function
|
---|
20 | for (var i=0; i<markers.length; i++) {
|
---|
21 | var current = markers[i];
|
---|
22 | var marker = addMarker(current, i);
|
---|
23 | marker_hash[current.id] = {marker : marker};
|
---|
24 | }
|
---|
25 |
|
---|
26 | var markerClusterer = new MarkerClusterer(map, markerArray);
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | //This function will contain the displaying and not displaying of nodes on the map
|
---|
31 | function toggleMyKml() {
|
---|
32 |
|
---|
33 | }
|
---|
34 |
|
---|
35 | //This function adds a marker with an object from our 'marker'array defined in index.php
|
---|
36 | function addMarker(current, i) {
|
---|
37 | var id = current.id;
|
---|
38 | var marker = new GMarker(new GLatLng(current.latitude[0], current.longitude[0]), {title: current.name[0]});
|
---|
39 | //Added mouseover listener that calls on our mouseOver function when the mouse moves over a marker on the map
|
---|
40 | GEvent.addListener(marker, 'mouseover', function() {
|
---|
41 | mouseOver(current.id, current.name[0]);
|
---|
42 | });
|
---|
43 | markerArray[i] = marker;
|
---|
44 | return marker;
|
---|
45 | }
|
---|
46 |
|
---|
47 | //Our mouseover function for single nodes. Gives the ID(our own given ID) and the name of the node.
|
---|
48 | function mouseOver(id, name)
|
---|
49 | {
|
---|
50 | //this.obj = document.getElementById("infotop");
|
---|
51 | loadXMLDoc("inc/node_info.php?type=single")
|
---|
52 | //We will replace this function with a httprequest to a php file in the future
|
---|
53 |
|
---|
54 |
|
---|
55 | /*
|
---|
56 | *Hieronder verdergaan met dekking
|
---|
57 | */
|
---|
58 | }
|
---|
59 |
|
---|
60 | //Our mouseover function for Cluster nodes. 'markers' is an array containing all markers within the cluster
|
---|
61 | function mouseOverCluster(markers)
|
---|
62 | {
|
---|
63 | //Make 'markers' array (containing gmarkers) into an array containing only the titles(names) of the markers
|
---|
64 | var markerTitles = new Array;
|
---|
65 | for(var i=0; i<markers.length; i++) {
|
---|
66 | markerTitles.push(markers[i].marker.getTitle());
|
---|
67 | }
|
---|
68 |
|
---|
69 | var markerTitleSerialized;
|
---|
70 |
|
---|
71 | //start
|
---|
72 | var a_php = "";
|
---|
73 | var total = 0;
|
---|
74 |
|
---|
75 | for (var i=0; i<markerTitles.length; i++)
|
---|
76 | {
|
---|
77 | ++ total;
|
---|
78 | a_php = a_php + "s:" +
|
---|
79 | String(i).length + ":\"" + String(i) + "\";s:" +
|
---|
80 | String(markerTitles[i]).length + ":\"" + String(markerTitles[i]) + "\";";
|
---|
81 | }
|
---|
82 | a_php = "a:" + total + ":{" + a_php + "}";
|
---|
83 | //end
|
---|
84 |
|
---|
85 | loadXMLDoc("inc/node_info.php?type=cluster&markers="+a_php+"")
|
---|
86 | /*
|
---|
87 | *Hieronder verdergaan met dekking
|
---|
88 | */
|
---|
89 | }
|
---|
90 |
|
---|
91 | //Our click function for Cluster nodes. 'markers' is an array containing all markers within the cluster
|
---|
92 | function clickCluster(markers)
|
---|
93 | {
|
---|
94 |
|
---|
95 | }
|
---|
96 |
|
---|
97 |
|
---|
98 | //Code from w3schools. http://www.w3schools.com/dom/dom_http.asp
|
---|
99 | function loadXMLDoc(url)
|
---|
100 | {
|
---|
101 | xmlhttp=null;
|
---|
102 | if (window.XMLHttpRequest)
|
---|
103 | {// code for Firefox, Opera, IE7, etc.
|
---|
104 | xmlhttp=new XMLHttpRequest();
|
---|
105 | }
|
---|
106 | else if (window.ActiveXObject)
|
---|
107 | {// code for IE6, IE5
|
---|
108 | xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
|
---|
109 | }
|
---|
110 | if (xmlhttp!=null)
|
---|
111 | {
|
---|
112 | xmlhttp.onreadystatechange=state_Change;
|
---|
113 | xmlhttp.open("GET",url,true);
|
---|
114 | xmlhttp.send(null);
|
---|
115 | }
|
---|
116 | else
|
---|
117 | {
|
---|
118 | alert("Your browser does not support XMLHTTP.");
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | function state_Change()
|
---|
123 | {
|
---|
124 | if (xmlhttp.readyState==4)
|
---|
125 | {// 4 = "loaded"
|
---|
126 | if (xmlhttp.status==200)
|
---|
127 | {// 200 = "OK"
|
---|
128 | document.getElementById(targetDiv).innerHTML=xmlhttp.responseText;
|
---|
129 | }
|
---|
130 | else
|
---|
131 | {
|
---|
132 | alert("Problem retrieving data:" + xmlhttp.statusText);
|
---|
133 | }
|
---|
134 | }
|
---|
135 | }
|
---|