-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvector-tiles.html
95 lines (87 loc) · 3.64 KB
/
vector-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
<!DOCTYPE html>
<html>
<head>
<title>leaflet-ptv-developer vector tiles example</title>
<meta charset="utf-8" />
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
<link rel="stylesheet" type="text/css" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css" />
<link rel="stylesheet" type="text/css" href="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.css">
<style>
body {
padding: 0;
margin: 0;
}
html,
body,
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript" src="https://unpkg.com/leaflet@1.9.3/dist/leaflet-src.js"></script>
<script type="text/javascript" src="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.js"></script>
<script type="text/javascript" src="https://unpkg.com/@maplibre/maplibre-gl-leaflet@0.0.19/leaflet-maplibre-gl.js"></script>
<script type="text/javascript" src="./dist/leaflet-ptv-developer-src.js"></script>
<script type="text/javascript" src="./api-key.js"></script>
<script>
var coordinate = L.latLng(49.012, 8.4044); // Karlsruhe, Germany
var tileSize = 256; // 512 or 1024 are also possible
var zoomOffset = tileSize === 256 ? 0 : tileSize === 512 ? -1 : - 2;
var map = L.map('map', {
fullscreenControl: true
}).setView(coordinate, 17);
var vectorLayer = L.maplibreGL({
attribution: '© ' + new Date().getFullYear() + ' PTV AG, HERE, TomTom',
interactive:false,
maxZoom: 18,
style: 'https://vectormaps-resources.myptv.com/styles/latest/standard.json',
transformRequest: (url, resourceType) => {
if (resourceType === 'Tile' && url.startsWith('https://api.myptv.com')) {
return {
url: url + '?apiKey=' + window.apiKey
}
}
}
}).addTo(map);
map.createPane('clickableTiles');
map.getPane('clickableTiles').style.zIndex = 500;
// insert clickable restrictions layer.
var restrictionsLayer = L.tileLayer.ptvDeveloper(
'https://api.myptv.com/rastermaps/v1/data-tiles/{z}/{x}/{y}' +
'?apiKey={token}&layers={layers}&size={tileSize}', {
layers: 'restrictions',
tileSize: tileSize,
zoomOffset: zoomOffset,
token: window.apiKey,
maxZoom: 18,
opacity: 0.5,
pane: 'clickableTiles'
}).addTo(map);
// insert clickable traffic incident layer.
var trafficIncidentsLayer = L.tileLayer.ptvDeveloper(
'https://api.myptv.com/rastermaps/v1/data-tiles/{z}/{x}/{y}' +
'?apiKey={token}&layers={layers}&size={tileSize}', {
layers: 'trafficIncidents',
tileSize: tileSize,
zoomOffset: zoomOffset,
token: window.apiKey,
maxZoom: 18,
opacity: 0.5,
pane: 'clickableTiles'
})
// add a layer switcher
var layers = {
"Vector Base Map": vectorLayer,
"Restrictions": restrictionsLayer,
"Traffic Incidents": trafficIncidentsLayer
};
L.control.layers({}, layers, {
position: 'bottomleft',
autoZIndex: false
}).addTo(map);
</script>
</body>
</html>