add addProtocol for maplibre [#6]

This commit is contained in:
Brandon Liu
2021-06-08 18:15:50 +08:00
parent 150a2561c2
commit 1bceca9535
2 changed files with 97 additions and 20 deletions

View File

@@ -4,9 +4,9 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.protomaps.com/maplibre-gl-js/1.13.0pm1/mapbox-gl.css" crossorigin="anonymous">
<script src="https://cdn.protomaps.com/maplibre-gl-js/1.13.0pm1/mapbox-gl.js" crossorigin="anonymous"></script>
<script src="../js/pmtiles.js"></script>
<link rel="stylesheet" href="http://localhost:9600/dist/maplibre-gl.css" crossorigin="anonymous">
<script src="http://localhost:9600/dist/maplibre-gl-dev.js" crossorigin="anonymous"></script>
<script src="../js/index.js"></script>
<style>
body, #map {
height:100vh;
@@ -15,8 +15,54 @@
</style>
</head>
<body>
<div id="map"></div>
<script>
</script>
<div id="map"></div>
<script>
pmtiles.addProtocol(maplibregl)
var style = {
"version": 8,
"sources": {
"tpe_sample": {
"type": "vector",
"tiles": ["pmtiles://tpe_sample.pmtiles/{z}/{x}/{y}"],
"maxzoom":14
}
},
"layers": [
{
"id": "buildings",
"type": "fill",
"source":"tpe_sample",
"source-layer":"buildings",
"paint": {
"fill-color":"black"
}
},
{
"id": "roads",
"type": "line",
"source":"tpe_sample",
"source-layer":"roads",
"paint": {
"line-color":"red"
}
},
{
"id": "mask",
"type": "fill",
"source":"tpe_sample",
"source-layer":"mask",
"paint": {
"fill-color":"white"
}
}
]
}
var map = new maplibregl.Map({
container: 'map',
center: [121.5177,25.0412],
zoom: 14,
style: style
});
</script>
</body>
</html>