This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
/
demo.html
88 lines (73 loc) · 2.69 KB
/
demo.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
<!DOCTYPE html>
<html>
<head>
<title>Leaflet PouchDB Tiles example</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.4.0/dist/leaflet.css" />
</head>
<body>
<div id="map" style="width: 600px; height: 400px"></div>
<button onclick="seed()">Seed world from Z=0 until Z=4</div>
<script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet-src.js"></script>
<script src="https://unpkg.com/pouchdb@^7.0.0/dist/pouchdb.js"></script>
<script src="L.TileLayer.PouchDBCached.js"></script>
<script>
// var map = L.map('map').setView([63.41784,10.40359], 5);
var map = L.map('map').setView([40,-100], 4);
var layer = L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}.png', {
maxZoom: 18,
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>',
id: 'examples.map-i875mjb7',
useCache: true,
crossOrigin: true
});
// Listen to cache hits and misses and spam the console
// The cache hits and misses are only from this layer, not from the WMS layer.
layer.on('tilecachehit',function(ev){
console.log('Cache hit: ', ev.url);
});
layer.on('tilecachemiss',function(ev){
console.log('Cache miss: ', ev.url);
});
layer.on('tilecacheerror',function(ev){
console.log('Cache error: ', ev.tile, ev.error);
});
layer.addTo(map);
var wmsLayer = L.tileLayer.wms("https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi", {
layers: 'nexrad-n0r-900913',
format: 'image/png',
transparent: true,
attribution: "Weather data © 2012 IEM Nexrad",
useCache: true,
cacheMaxAge: 30 * 1000, // 30 seconds
crossOrigin: true
});
wmsLayer.addTo(map);
wmsLayer.on('tilecachehit',function(ev){
console.log('Cache hit: ', ev.url);
});
wmsLayer.on('tilecachemiss',function(ev){
console.log('Cache miss: ', ev.url);
});
wmsLayer.on('tilecacheerror',function(ev){
console.log('Cache error: ', ev.tile, ev.error);
});
// Seed the base layer, for the whole world, for zoom levels 0 through 4.
function seed() {
var bbox = L.latLngBounds(L.latLng(-80,-180), L.latLng(85,180));
layer.seed( bbox, 0, 4 );
}
// Display seed progress on console
layer.on('seedprogress', function(seedData){
var percent = 100 - Math.floor(seedData.remainingLength / seedData.queueLength * 100);
console.log('Seeding ' + percent + '% done');
});
layer.on('seedend', function(seedData){
console.log('Cache seeding complete');
});
</script>
</body>
</html>