forked from CrunchyData/pg_tileserv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaflet-tiles.html
97 lines (84 loc) · 2.71 KB
/
leaflet-tiles.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Leaflet Vector Tiles</title>
<!-- CSS for Leaflet map -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
<!-- JS for Leaflet map -->
<!-- Make sure you put this AFTER Leaflet's CSS -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og=="
crossorigin=""></script>
<!-- Leaflet plugin for vector tiles support -->
<script type="text/javascript" src="https://unpkg.com/[email protected]"></script>
<style>
html, body, #map {
font-family: sans-serif;
height: 100%;
width: 100%;
}
body {
padding: 0;
margin: 0;
}
#map {
z-index: 1;
}
#meta {
background-color: rgba(255,255,255,0.75);
color: black;
z-index: 2;
position: absolute;
top: 10px;
left: 20px;
padding: 10px 20px;
margin: 0;
}
</style>
</head>
<body>
<div id="meta">
<h2>Leaflet Tile Map</h2>
<ul>
<li><a href="https://leafletjs.com/">Leaflet</a></li>
<li><a href="https://github.com/Leaflet/Leaflet.VectorGrid">Leaflet Vector Grid</a></li>
</ul>
</div>
<div id="map"></div>
<script>
var map = L.map('map').setView([0, 0], 2);
// Add a base map layer to the map
var baseUrl = "https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png";
var baseLayer = L.tileLayer(baseUrl, {
"maxZoom": 18
});
baseLayer.addTo(map);
// Add the tile layer to the map
// https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_countries.zip
var vectorServer = "http://localhost:7800/";
var vectorLayerId = "public.ne_50m_admin_0_countries";
var vectorUrl = vectorServer + vectorLayerId + "/{z}/{x}/{y}.pbf";
console.log("Reading tiles from " + vectorUrl);
var vectorTileStyling = {};
var vectorTileColor = "green";
vectorTileStyling[vectorLayerId] = {
"fill": true,
"fillColor": vectorTileColor,
"fillOpacity": 0.1,
"color": vectorTileColor,
"opacity": 0.7,
"weight": 2
};
var vectorTileOptions = {
"rendererFactory": L.canvas.tile,
"attribution": "© <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors, made with Natural Earth",
"vectorTileLayerStyles": vectorTileStyling
};
var vectorLayer = L.vectorGrid.protobuf(vectorUrl, vectorTileOptions).addTo(map);
</script>
</body>
</html>