-
Notifications
You must be signed in to change notification settings - Fork 6
/
schools.html
181 lines (157 loc) · 4.65 KB
/
schools.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html>
<html>
<head>
<title>GP Clustering</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
#panel {
position: absolute;
top: 5px;
left: 50%;
margin-left: -180px;
z-index: 5;
background-color: #fff;
padding: 5px;
border: 1px solid #999;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type = "text/javascript" language = "javascript">
var map;
var markers = [];
var count = 0;
var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/schools_maps.png';
var iconClustersBase = "http://maps.google.com/mapfiles/kml/paddle/";
var mVar = 0.1;
var infoWindows = [];
function initialize() {
var centerPoint = new google.maps.LatLng(-35.351057, 149.055559);
var mapOptions = {
zoom: 12,
center: centerPoint,
// mapTypeId: google.maps.MapTypeId.TERRAIN
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
loadLocations();
}
function loadLocations(){
alert("loading data..");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.OpenTextFile("C:\\Users\\Titicaca\\Documents\\GitHub\\GP-Clustering\\dataset\\actschools.txt",1);
var s = "";
count = 0;
// alert(count);
skiprows(1, file);
while(!file.AtEndOfStream){
count++;
// alert(count);
s = file.ReadLine();
// alert(s);
// var items = s.split(/[\s]+/);
var items = s.split("\t");
// alert(items[1] + "," + items[0]);
// var x = parseFloat(items[6]) + parseFloat(items[7])/100;
// var y = - (parseFloat(items[8]) + parseFloat(items[9])/100);
var x = parseFloat(items[1])
var y = parseFloat(items[0])
// alert(x + "," + y);
var location = new google.maps.LatLng(x,y);
var myinfowindow = new google.maps.InfoWindow({
content: "point id: " + (count - 1) + "<br />" + "School Name: " + items[2] + "<br />" + "Address: " + items[3] + ", " + items[4] + "<br />" + "Post code: " + items[5]
});
var marker = new google.maps.Marker({
position: location,
map: map,
icon: iconBase,
clickable: true,
infowindow: myinfowindow
});
google.maps.event.addListener(marker, 'click', function() {
this.infowindow.open(map, this);
});
markers.push(marker);
}
alert("data loaded..\n" + "Count:" + count);
}
function skiprows(numRows, file){
for (var i = 0; i < numRows; i ++){
if(!file.AtEndOfStream)
file.ReadLine();
}
}
function loadClusters(){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.OpenTextFile("C:\\Users\\Titicaca\\Documents\\GitHub\\GP-Clustering\\results\\schools_Var="+ mVar + "0.txt",1);
count = 0;
clusterNum = 0;
clusters = [];
while(!file.AtEndOfStream){
count++;
s = file.ReadLine();
clusterIndex = parseInt(s);
if(clusterNum < clusterIndex)
clusterNum = clusterIndex;
clusters.push(clusterIndex);
}
alert("the Number of Clusters: " + clusterNum);
return clusters;
}
// Sets the map on all markers in the array.
function setAllMap(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
function showMarkers() {
alert("The number of points:" + markers.length);
for (var i = 0; i < markers.length; i++) {
markers[i].setIcon(iconBase);
}
setAllMap(map);
}
function showClusters() {
clusters = loadClusters();
var iconClusters = [];
for (var i = 0; i < 36; i ++){
if(i < 10)
iconClusters.push(iconClustersBase + i + ".png");
else
iconClusters.push(iconClustersBase + String.fromCharCode(65 + (i-10)) + ".png");
}
for (var i = 0; i < markers.length; i++) {
markers[i].setIcon(iconClusters[clusters[i]%iconClusters.length]);
}
}
function clearMarkers() {
setAllMap(null);
}
function changeFunc() {
var selectBox = document.getElementById("selectBox");
var selectedValue = selectBox.options[selectBox.selectedIndex].value;
mVar = selectedValue;
// alert("The Current Cutting Level Variance is : " + mVar);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="panel">
<input onclick="showMarkers();" type=button value="Show All Markers">
<input onclick="showClusters();" type=button value="GPClustering">
<select id="selectBox" onchange="changeFunc();">
<option value="0.1">Variance = 0.1</option>
<option value="0.2">Variance = 0.2</option>
<option value="0.3">Variance = 0.3</option>
<option value="0.4">Variance = 0.4</option>
</select>
<input onclick="clearMarkers();" type=button value="Clear Markers">
</div>
<div id="map-canvas"></div>
<p>GP Clustering for School Dataset.</p>
</body>
</html>