forked from h5bp/html5-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
346 lines (309 loc) · 14 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
341
342
343
344
345
346
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Offline Maps</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<!-- <link type="text/css" rel="stylesheet" href="css/main.css"> -->
<link type="text/css" rel="stylesheet" href="css/jquery-ui.css" />
<link type="text/css" rel="stylesheet" href="css/960/min/960.css" />
<link type="text/css" rel="stylesheet" href="css/960/min/960_16_col.css" />
<link type="text/css" rel="stylesheet" href="css/normalize.min.css" />
<link type="text/css" rel="stylesheet" href="css/prettify.min.css" />
<link type="text/css" rel="stylesheet" href="css/style.css" />
<script src="js/vendor/modernizr-2.6.2.min.js"></script>
</head>
<body>
<!--[if lt IE 7]>
<p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
<![endif]-->
<!-- Add your site or application content here -->
<header class="dark">
<div class="container_16">
<h3>Offline Maps</h3>
<label for="latval">Lat:</label>
<input type="text" readonly value="0" name="latval" id="latval"/>
<label for="lonval">Lon:</label>
<input type="text" readonly value="0" name="lonval" id="lonval"/>
<button name="store" id="store">Store tiles</button>
<label for="offline">Off-line:</label>
<input name="offline" id="offline" value="Off-line" type="checkbox">
<!--<button name="developer" id="developer">Developer</button>-->
</div>
</header>
<div class="container_16">
<article class="grid_16">
<div class="item rounded dark">
<div id="map_canvas" class="map rounded"> </div>
</div>
</article>
</div>
<!--<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>-->
<script type="text/javascript" src="js/vendor/maps.api.js"></script><!-- obtained by https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false -->
<script type="text/javascript" src="js/vendor/jquery-1.8.2.js"></script>
<script type="text/javascript" src="js/vendor/jquery-ui-1.9.0.custom.js"></script>
<script type="text/javascript" src="js/vendor/underscore-1.4.2.js"></script>
<script type="text/javascript" src="js/vendor/backbone-0.9.2.js"></script>
<script type="text/javascript" src="js/vendor/prettify.min.js"></script>
<script type="text/javascript" src="js/vendor/jquery.ui.map.js"></script>
<script type="text/javascript" src="js/vendor/jquery.ui.map.services.js"></script>
<script type="text/javascript" src="js/vendor/jquery.ui.map.overlays.js"></script>
<script type="text/javascript" src="js/vendor/jquery.ui.map.extensions.js"></script>
<script type="text/javascript" src="js/vendor/IDBStore.js"></script>
<script src="js/plugins.js"></script>
<script src="js/main.js"></script>
<script src="js/demo.js"></script>
<script type="text/javascript">
$(function() {
// Create/open database
tileStore = new IDBStore({
dbName: 'tiles',
storeName: 'tiles',
keyPath: 'tileid',
dbVersion: 1,
autoIncrement: true
});
var road = true;
var getAndStoreTile = function (tileUrl) {
// Create XHR
var xhr = new XMLHttpRequest();
xhr.open("GET", tileUrl, true);
// Set the responseType to blob
xhr.responseType = "blob";
xhr.addEventListener("load", function () {
if (xhr.status === 200) {
console.log("Image retrieved");
// Blob as response
var blob = xhr.response;
console.log("Blob:" + blob);
// Put the received blob into IndexedDB
putTileIntoDb(blob);
}
}, false);
// Send XHR
xhr.send();
};
var putTileIntoDb = function (blob) {
console.log("Putting tile into IndexedDB");
tileStore.put(blob,
function(result) {
window.localStorage.setItem("spotId", result);
console.log("Put request successful, key = " + result);
},
function(result) {
console.log("Error during put request!");
}
);
};
var getTileUrl = function(lastLatStr, lastLonStr) {
var lastLatStr = window.localStorage.getItem("lastLat");
var lastLonStr = window.localStorage.getItem("lastLon");
return "http://maps.googleapis.com/maps/api/staticmap?center=" + lastLatStr + "," + lastLonStr + "&zoom=16&size=256x256&sensor=false";
};
var focusOnLocation = function(latStr, lonStr) {
$('#latval').val(latStr);
$('#lonval').val(lonStr);
window.localStorage.setItem("lastLat", latStr);
window.localStorage.setItem("lastLon", lonStr);
};
demo.add(function() {
$('#map_canvas').gmap({
// 'disableDefaultUI':false,
'panControl':true,
'zoomControl':true,
'mapTypeControl':true,
'scaleControl':true,
'callback': function() {
var self = this;
self.getCurrentPosition(function(position, status) {
var ok = (status === 'OK');
// var lastLatStr = ok ? position.coords.latitude : window.localStorage.getItem("lastLat");
// var lastLonStr = ok ? position.coords.longitude : window.localStorage.getItem("lastLon");
var lastLatStr = 37.774924229819774;
var lastLonStr = -122.41941298834325;
self.set('clientPosition', new google.maps.LatLng(lastLatStr, lastLonStr));
self.addMarker({'position': self.get('clientPosition'), 'bounds': true});
self.addShape('Circle', { 'strokeWeight': 0, 'fillColor': "#008595", 'fillOpacity': 0.25, 'center': self.get('clientPosition'), 'radius': 15, clickable: false });
});
}
});
var map = $('#map_canvas').gmap('get', 'map');
$(map).addEventListener('dblclick', function(event) {
var ll = event.latLng;
var latStr = ll.lat();
var lonStr = ll.lng();
focusOnLocation(latStr, lonStr);
$('#map_canvas').gmap('addMarker', {
'bounds':true,
'position': new google.maps.LatLng(latStr,lonStr),
'animation': google.maps.Animation.DROP
}/*,
function(pmap, marker) {
$('#map_canvas').gmap('addInfoWindow', { 'position': marker.getPosition(), 'content': 'Selected site' }/*,
function() {
$(marker).click(function() {
var pos = marker.getPosition();
focusOnLocation(pos.coords.latitude, pos.coords.longitude);
pmap.panTo(pos);
});
}
);
}*/
);
//this.panTo(ll);
}, false);
}).load();
var overlay;
SiteOverlay.prototype = new google.maps.OverlayView();
function initializeOverlay(latCoord, longCoord) {
latCoord = 37.774924229819774;
longCoord = -122.41941298834325;
var myLatLng = new google.maps.LatLng(37.774924229819774, -122.41941298834325);
var dx = 0.00225;
var dy = 0.00275;
var swBound = new google.maps.LatLng(latCoord - dx, longCoord - dy);
var neBound = new google.maps.LatLng(latCoord + dx, longCoord + dy);
var bounds = new google.maps.LatLngBounds(swBound, neBound);
var map = $('#map_canvas').gmap('get', 'map');
// Photograph courtesy of the U.S. Geological Survey
overlay = new SiteOverlay(bounds, map);
overlay.setMap(map);
}
function SiteOverlay(bounds, map) {
// Now initialize all properties.
this.bounds_ = bounds;
this.map_ = map;
// We define a property to hold the image's
// div. We'll actually create this div
// upon receipt of the add() method so we'll
// leave it null for now.
this.div_ = null;
// Explicitly call setMap on this overlay
//this.setMap(map);
}
SiteOverlay.prototype.onAdd = function() {
// Note: an overlay's receipt of add() indicates that
// the map's panes are now available for attaching
// the overlay to the map via the DOM.
// Create the DIV and set some basic attributes.
var div = document.createElement('div');
div.style.border = 'none';
div.style.borderWidth = '0px';
div.style.position = 'absolute';
console.log("Getting tile from IndexedDB");
// var spotId = window.localStorage.getItem("spotId");
// tileStore.get(spotId,
// function(result) {
console.log("Get request successful!");
// var imgFile = result;
// console.log("Got tile!" + imgFile);
// Get window.URL object
// var URL = window.URL || window.webkitURL;
// Create and revoke ObjectURL
//var imgURL = URL.createObjectURL(imgFile);
var imgURL = "images/precache/staticmap_ff_z16_s2.png";
if (road)
imgURL = "images/precache/staticmap_ff_z16_s2_2.png";
// Create an IMG element and attach it to the DIV.
var img = document.createElement('img');
// Set img src to ObjectURL
img.src = imgURL;
img.style.width = '100%';
img.style.height = '100%';
div.appendChild(img);
// Set the overlay's div_ property to this DIV
this.div_ = div;
// We add an overlay to a map via one of the map's panes.
// We'll add this overlay to the overlayImage pane.
var panes = this.getPanes();
panes.overlayImage.appendChild(this.div_);
// Revoking ObjectURL
//URL.revokeObjectURL(imgURL);
// },
// function(result) {
// console.log("Error during get request!");
// }
// );
};
SiteOverlay.prototype.onRemove = function() {
this.div_.parentNode.removeChild(this.div_);
};
SiteOverlay.prototype.draw = function() {
// Size and position the overlay. We use a southwest and northeast
// position of the overlay to peg it to the correct position and size.
// We need to retrieve the projection from this overlay to do this.
var overlayProjection = this.getProjection();
// Retrieve the southwest and northeast coordinates of this overlay
// in latlngs and convert them to pixels coordinates.
// We'll use these coordinates to resize the DIV.
var sw = overlayProjection.fromLatLngToDivPixel(this.bounds_.getSouthWest());
var ne = overlayProjection.fromLatLngToDivPixel(this.bounds_.getNorthEast());
// Resize the image's DIV to fit the indicated dimensions.
var div = this.div_;
div.style.left = sw.x + 'px';
div.style.top = ne.y + 'px';
div.style.width = (ne.x - sw.x) + 'px';
div.style.height = (sw.y - ne.y) + 'px';
};
$('#store').click(function() {
getAndStoreTile(getTileUrl());
});
$('#offline').click(function(event) {
if (this.div_) {
if (this.div_.style.visibility == 'hidden') {
this.div_.style.visibility = 'visible';
} else {
this.div_.style.visibility = 'hidden';
}
} else {
var lastLatStr = window.localStorage.getItem("lastLat");
var lastLonStr = window.localStorage.getItem("lastLon");
initializeOverlay(lastLatStr, lastLonStr);
road = !road;
//addOverlay();
}
});
// "Cheating"
$('#developer').click(function() {
var browserStr = "ff";
//var browserStr = "cr";
var fileNames = [];
var fileNameFullPaths = [];
for(var i = 16; i <= 16; ++i) {
for(var j = 1; j <= 2; ++j) {
var filename = "staticmap_" + browserStr + "_z" + i + "_s" + j + ".png";
fileNames.push(filename);
var fullfilename = "images/precache/" + filename;
fileNameFullPaths.push(fullfilename);
alert("Loading file: " + fullfilename);
// Create XHR
var xhr = new XMLHttpRequest();
xhr.open("GET", fullfilename, true);
// Set the responseType to blob
xhr.responseType = "blob";
xhr.addEventListener("load", function () {
if (xhr.status === 200) {
console.log("Image retrieved");
// Blob as response
var blob = xhr.response;
console.log("Blob:" + blob);
// Put the received blob into IndexedDB
putTileIntoDb(blob);
}
}, false);
// Send XHR
xhr.send();
}
}
});
});
</script>
</body>
</html>