forked from MazeMap/Leaflet.TileLayer.PouchDBCached
-
Notifications
You must be signed in to change notification settings - Fork 5
/
demo.html
58 lines (53 loc) · 1.95 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
<!DOCTYPE html PUBLIC>
<html style="height: 100%; width: 100%;">
<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.3.4/dist/leaflet.css" />
</head>
<body style="margin: 0px; padding: 0px;">
<div id="page-wrapper" style="margin-left: auto; margin-right: auto; padding: 0px; width: 100%;">
<div id="map" style="display: block; height: 100%;"></div>
</div>
<script src="https://unpkg.com/leaflet@1.3.4/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('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
dbName: 'leaflet-offline-tiles',
id: 'examples.map-i875mjb7',
maxZoom: 18,
crossOrigin: true,
useCache: 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(e) {
console.log('Cache hit: ', e.url);
});
layer.on('tilecachemiss',function(e) {
console.log('Cache miss: ', e.url);
});
layer.addTo(map);
var protocol = window.location.protocol;
if (!protocol.startsWith('http')) {
// fallback for unexpected protocols (like file: or ftp:)
protocol = 'http:'
}
var wmsLayer = L.tileLayer.wms(protocol + '//mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi', {
attribution: "Weather data © 2012 IEM Nexrad",
format: 'image/png',
layers: 'nexrad-n0r-900913',
maxAge: 30 * 1000, // 30 seconds
transparent: true,
crossOrigin: true,
useCache: true
});
wmsLayer.addTo(map);
</script>
</body>
</html>