-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
340 lines (254 loc) · 9.56 KB
/
index.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<link rel="stylesheet" href="http://ol3js.org/en/master/css/ol.css" type="text/css">
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script src="http://ol3js.org/en/master/build/ol.js" type="text/javascript"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<script src="src/topojson.min.js"></script>
<style>
.container {
width: 600px;
background-color:#CCCCCC;
display: block;
margin-bottom: 30px;
}
.map {
width: 100%;
height: 375px;
position:relative;
z-index: 1;
}
.buttons {
padding: 10px;
}
.time {
/*float: right;*/
padding-left: 10px;
padding-right: 10px;
font-weight: bold;
color: #C00;
}
</style>
</head>
<body>
<div id="stats" style="float:right;">
Stats
</br>
<input type="button" value="Run google stats" onclick="runGoogleStats()" />
<span id="google-geo-time-avg" class="time">TIME</span>(ms)
<span id="google-geo-time-rep" class="time">REPS</span>
</div>
<div class="container">
<div class="map" id="google">
</div>
<div id="google" class="buttons">
<input type="button" value="Add Geojson" onclick="addGoogleGeoJSON()" />
<span id="google-geo-time" class="time">TIME</span>(ms)
<input type="button" value="Add Topojson" onclick="addGoogleTopoJSON()"/>
<span id="google-topo-time" class="time">TIME</span>(ms)
<input type="button" value="Clear" onclick="clearGoogleJson()"/>
</div>
</div>
<div class="container">
<div class="map" id="leaflet">
</div>
<div id="leaflet" class="buttons">
<input type="button" value="Add Geojson" onclick="addLeafletGeoJSON()" />
<span id="leaflet-geo-time" class="time">TIME</span>(ms)
<input type="button" value="Add Topojson" onclick="addLeafletTopoJSON()" />
<span id="leaflet-topo-time" class="time">TIME</span>(ms)
<input type="button" value="Clear" onclick="clearLeafletJson()"/>
</div>
</div>
<div class="container">
<div class="map" id="openlayers">
</div>
<div id="openlayers" class="buttons">
<input type="button" value="Add Geojson" onclick="addOLGeoJSON()" />
<span id="ol-geo-time" class="time">TIME</span>(ms)
<input type="button" value="Add Topojson" onclick="addOLTopoJSON()" />
<span id="ol-topo-time" class="time">TIME</span>(ms)
<input type="button" value="Clear" onclick="clearOpenLayersJson()"/>
</div>
</div>
<script>
var lat = 41;
var long = -110;
var zoom = 4;
var mapGoogle;
var mapLeaflet;
var mapLeafletLayers = [];
var mapOL;
//data
var simpleCntyWestPromise = $.getJSON("data/simp_cnty_west.geojson"); //same as map.data.loadGeoJson();
var countyPromise = $.getJSON("data/county.topojson"); //same as map.data.loadGeoJson();
function timeExecution(executeFn){
var time1 = window.performance.now();
executeFn();
return Math.round((window.performance.now() - time1) * 100) / 100;
};
function statRunner(executeFn, repetitions){
}
function addGoogleMap() {
var mapOptions = {
zoom: zoom,
center: new google.maps.LatLng(lat, long)
};
mapGoogle = new google.maps.Map(document.getElementById('google'), mapOptions);
};
function addGoogleGeoJSON() {
return simpleCntyWestPromise.then(function(data) {
var executionTime = timeExecution(function(){
mapGoogle.data.addGeoJson(data);
});
$("#google-geo-time").text(executionTime);
return executionTime;
});
}
function addGoogleTopoJSON() {
countyPromise.then(function(data) {
$("#google-topo-time").text(timeExecution(function(){
topojsonobject = topojson.feature(data, data.objects.county)
mapGoogle.data.addGeoJson(topojsonobject);
}));
});
}
function clearGoogleJson(){
mapGoogle.data.setMap(null);
mapGoogle.data = new google.maps.Data();
mapGoogle.data.setMap(mapGoogle);
$("#google span").text("TIME");
};
function runGoogleStats(){
var reps = 100;
var runTimes = [];
function runGoogle(){
addGoogleGeoJSON().then(function(time){
reps--;
if(reps>-1){
runTimes.push(time);
clearGoogleJson();
$("#google-geo-time-rep").text(reps);
if(reps === 0){
$("#google-geo-time-avg").text(runTimes.reduce(function(a, b) {
return a + b
})/runTimes.length);
return;
}
runGoogle();
}
});
}
runGoogle();
}
function addLeafletMap() {
mapLeaflet = L.map('leaflet').setView([lat, long], zoom);
L.tileLayer('http://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png', {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>'
}).addTo(mapLeaflet);
}
function addLeafletGeoJSON() {
//var promise = $.getJSON("data/simp_cnty_west.geojson"); //same as map.data.loadGeoJson();
simpleCntyWestPromise.then(function(data) {
$("#leaflet-geo-time").text(timeExecution(function(){
var leafletLayer = L.geoJson(data);
leafletLayer.addTo(mapLeaflet);
mapLeafletLayers.push(leafletLayer);
}));
});
}
function addLeafletTopoJSON() {
//var promise = $.getJSON("data/county.topojson"); //same as map.data.loadGeoJson();
countyPromise.then(function(data) {
$("#leaflet-topo-time").text(timeExecution(function() {
var geojson = topojson.feature(data, data.objects.county);
var leafletLayer = L.geoJson(geojson);
leafletLayer.addTo(mapLeaflet);
mapLeafletLayers.push(leafletLayer);
}));
});
}
function clearLeafletJson(){
for(var i=0;i<mapLeafletLayers.length;i++){
mapLeaflet.removeLayer(mapLeafletLayers[i]);
}
$("#leaflet span").text("TIME");
};
function addOpenLayersMap() {
var tile = new ol.layer.Tile({
source: new ol.source.Stamen({
layer: 'watercolor'
})
});
var tileLabels = new ol.layer.Tile({
source: new ol.source.Stamen({
layer: 'terrain-labels'
})
});
mapOL = new ol.Map({
layers: [tile, tileLabels],
target: 'openlayers',
view: new ol.View2D({
center: ol.proj.transform([-119.768812, 36.745379], 'EPSG:4326', 'EPSG:3857'),
zoom: 5
})
});
}
function addOLGeoJSON() {
//var promise = $.getJSON("data/simp_cnty_west.geojson"); //same as map.data.loadGeoJson();
simpleCntyWestPromise.then(function(data) {
$("#ol-geo-time").text(timeExecution(function(){
var vectorLayer = new ol.layer.Vector({
source: new ol.source.GeoJSON({
projection: 'EPSG:3857',
object: data
})
})
mapOL.addLayer(vectorLayer);
vectorLayer.set("layerName","geojson");
}));
});
}
function addOLTopoJSON() {
//var promise = $.getJSON("data/county.topojson"); //same as map.data.loadGeoJson();
countyPromise.then(function(data) {
$("#ol-topo-time").text(timeExecution(function(){
var vectorLayer = new ol.layer.Vector({
source: new ol.source.TopoJSON({
projection: 'EPSG:3857',
object: data
//url:"data/township.topo.json"
})
});
mapOL.addLayer(vectorLayer);
vectorLayer.set("layerName","topojson");
}));
});
}
function clearOpenLayersJson(){
mapOL.getLayers().forEach(function(element){
if(element.get("layerName") && element.get("layerName").indexOf("json") > -1)
mapOL.removeLayer(element);
});
//getLayers is marked as experimental, apparently it doesnt work properly yet, we have to call this twice to remove all layers
mapOL.getLayers().forEach(function(element){
if(element.get("layerName") && element.get("layerName").indexOf("json") > -1)
mapOL.removeLayer(element);
});
$("#openlayers span").text("TIME");
};
//init
$(document).ready(function() {
addGoogleMap();
addLeafletMap();
addOpenLayersMap();
});
</script>
</body>
</html>