forked from allartk/leaflet.offline
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
115 lines (109 loc) · 4.07 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
<!DOCTYPE html>
<html>
<head>
<title>Example github pages</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.1.0/dist/leaflet.css"/>
<script src="https://unpkg.com/leaflet@1.1.0/dist/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/localforage/1.4.3/localforage.min.js"
type="text/javascript"></script>
<script src="dist/bundle.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css"
integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid" style="max-width:1200px">
<a class="navbar-brand" href="https://github.com/allartk/leaflet.offline">Leaflet.offline</a>
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="">Example</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/allartk/leaflet.offline/blob/master/docs/api.md">Api</a>
</li>
</ul>
</div>
</nav>
<div class="container-fluid" style="max-width:1200px">
<div class="row">
<div class="col-md-12">
<h1>Leaflet.offline example</h1>
</div>
<div class="col-md-7">
<div id="map" style="height: 75vh"></div>
</div>
<div class="col-md-5">
<p>Progress: <span id="progress"></span> / <span id="total"></span></p>
<p>Current storage: <span id="storage"></span> files
<button class="btn btn-danger" id="remove_tiles">
<i class="fa fa-trash" aria-hidden="true" title="Remove tiles"></i>
</button>
</p>
</div>
</div>
</div>
<script type="text/javascript">
var map = L.map('map');
//offline baselayer, will use offline source if available
var baseLayer = L.tileLayer.offline('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data {attribution.OpenStreetMap}',
subdomains: 'abc',
minZoom: 13,
})
.addTo(map);
//add buttons to save tiles in area viewed
var control = L.control.savetiles(baseLayer, {
'zoomlevels': [13, 16], //optional zoomlevels to save, default current zoomlevel
'confirm': function (layer, succescallback) {
if (window.confirm('Save ' + layer._tilesforSave.length)) {
succescallback();
}
},
'confirmRemoval': function (layer, successCallback) {
if (window.confirm('Remove all the tiles?')) {
successCallback();
}
},
'saveText': '<i class="fa fa-download" aria-hidden="true" title="Save tiles"></i>',
'rmText': '<i class="fa fa-trash" aria-hidden="true" title="Remove tiles"></i>'
});
control.addTo(map);
document.getElementById('remove_tiles')
.addEventListener('click', function (e) {
control._rmTiles();
});
baseLayer.on('storagesize', function (e) {
document.getElementById('storage').innerHTML = e.storagesize;
});
//events while saving a tile layer
var progress;
baseLayer.on('savestart', function (e) {
progress = 0;
document.getElementById('total').innerHTML = e._tilesforSave.length;
});
baseLayer.on('savetileend', function (e) {
progress++;
document.getElementById('progress').innerHTML = progress;
});
baseLayer.on('loadend', function (e) {
alert('Saved all tiles');
});
baseLayer.on('tilesremoved', function (e) {
alert('Removed all tiles');
});
map.setView({
lat: 51.985,
lng: 5
}, 18);
//layer switcher control
L.control.layers({
'osm (offline)': baseLayer
})
.addTo(map);
</script>
</body>
</html>