forked from ncx-co/offline_map_poc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
64 lines (57 loc) · 1.96 KB
/
main.js
File metadata and controls
64 lines (57 loc) · 1.96 KB
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
var FILESYSTEM;
function getMapIDs() {
/*
* Return a list of mapIDs or null
*/
var mapboxIDs = (localStorage["MAPBOX_IDS"] || "").split(",");
if (mapboxIDs[0] == "") { return null; } //no ids
else { return mapboxIDs; }
}
function createMapOptions(clear) {
return {
'clear': clear,
'fileSystem': FILESYSTEM,
'mapIDs': getMapIDs()
};
}
$(document).ready(function() {
//Some bookkeeping code for mapbox id
$("#mapbox_id")
.val(localStorage["MAPBOX_IDS"])
.off("change")
.on("change", function() { localStorage["MAPBOX_IDS"] = $(this).val(); });
//Real page setup on phonegap initialization
$(document).off("deviceready").on("deviceready", function() {
window.requestFileSystem(
LocalFileSystem.PERSISTENT, 0,
function(fs) { //success
FILESYSTEM = fs; //set global - sloppy, I know
mapUtils.reloadMap(createMapOptions(false));
},
function() { alert("Failure accessing filesystem!"); } //filesystem failure
);
$("#clear").off("click").on("click", function() {
fileUtils.rmDir(
FILESYSTEM,
'tiles',
function(){
mapUtils.reloadMap(createMapOptions(true));
alert("Tiles cleared successfully");
}
);
});
$("#download").off("click").on("click", function() {
var mapboxIDs = getMapIDs();
if (mapboxIDs == null) { alert("Enter a MapBox Map ID"); return; } //no ids
fileUtils.bulkDownload(
tileUtils.pyramid(mapboxIDs, 38.255, -85.73, {}), //tile urls
'tiles',
$("#progress_modal"),
function() {
alert("Download successful!");
mapUtils.reloadMap(createMapOptions(false));
}
);
});
});
});