mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 02:41:09 +00:00
@@ -15,16 +15,19 @@
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
<script type="text/javascript">
|
||||
const map = L.map('map').setView([0, 0], 0);
|
||||
const map = L.map("map").setView([0, 0], 0);
|
||||
|
||||
const p = new pmtiles.PMTiles("https://pmtiles.io/stamen_toner(raster)CC-BY+ODbL_z3.pmtiles")
|
||||
p.getHeader().then(h => {
|
||||
const p = new pmtiles.PMTiles(
|
||||
"https://pmtiles.io/stamen_toner(raster)CC-BY+ODbL_z3.pmtiles"
|
||||
);
|
||||
p.getHeader().then((h) => {
|
||||
let layer = pmtiles.leafletRasterLayer(p, {
|
||||
maxzoom: h.maxZoom,
|
||||
attribution:'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.'
|
||||
attribution:
|
||||
'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.',
|
||||
});
|
||||
layer.addTo(map);
|
||||
})
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -30,65 +30,66 @@
|
||||
protocol.add(p);
|
||||
|
||||
// we first fetch the header so we can get the center lon, lat of the map.
|
||||
p.getHeader().then(h => {
|
||||
p.getHeader().then((h) => {
|
||||
const map = new maplibregl.Map({
|
||||
container: 'map',
|
||||
container: "map",
|
||||
zoom: h.maxZoom - 2,
|
||||
center: [h.centerLon, h.centerLat],
|
||||
style: {
|
||||
version: 8,
|
||||
sources: {
|
||||
"example_source": {
|
||||
example_source: {
|
||||
type: "vector",
|
||||
// For standard Z/X/Y tile APIs or Z/X/Y URLs served from go-pmtiles, replace "url" with "tiles" and remove all the pmtiles-related client code.
|
||||
// tiles: ["https://example.com/{z}/[x}/{y}.mvt"],
|
||||
// see https://maplibre.org/maplibre-style-spec/sources/#vector
|
||||
url: "pmtiles://" + PMTILES_URL,
|
||||
attribution: '© <a href="https://openstreetmap.org">OpenStreetMap</a>'
|
||||
}
|
||||
attribution:
|
||||
'© <a href="https://openstreetmap.org">OpenStreetMap</a>',
|
||||
},
|
||||
},
|
||||
layers: [
|
||||
{
|
||||
"id":"water",
|
||||
"source": "example_source",
|
||||
id: "water",
|
||||
source: "example_source",
|
||||
"source-layer": "water",
|
||||
"type": "fill",
|
||||
"paint": {
|
||||
"fill-color": "#80b1d3"
|
||||
}
|
||||
type: "fill",
|
||||
paint: {
|
||||
"fill-color": "#80b1d3",
|
||||
},
|
||||
},
|
||||
{
|
||||
"id":"buildings",
|
||||
"source": "example_source",
|
||||
id: "buildings",
|
||||
source: "example_source",
|
||||
"source-layer": "buildings",
|
||||
"type": "fill",
|
||||
"paint": {
|
||||
"fill-color": "#d9d9d9"
|
||||
}
|
||||
type: "fill",
|
||||
paint: {
|
||||
"fill-color": "#d9d9d9",
|
||||
},
|
||||
},
|
||||
{
|
||||
"id":"roads",
|
||||
"source": "example_source",
|
||||
id: "roads",
|
||||
source: "example_source",
|
||||
"source-layer": "roads",
|
||||
"type": "line",
|
||||
"paint": {
|
||||
"line-color": "#fc8d62"
|
||||
}
|
||||
type: "line",
|
||||
paint: {
|
||||
"line-color": "#fc8d62",
|
||||
},
|
||||
},
|
||||
{
|
||||
"id":"pois",
|
||||
"source": "example_source",
|
||||
id: "pois",
|
||||
source: "example_source",
|
||||
"source-layer": "pois",
|
||||
"type": "circle",
|
||||
"paint": {
|
||||
"circle-color": "#ffffb3"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
type: "circle",
|
||||
paint: {
|
||||
"circle-color": "#ffffb3",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
map.showTileBoundaries = true;
|
||||
})
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -30,39 +30,50 @@
|
||||
<script type="text/javascript">
|
||||
let protocol = new pmtiles.Protocol();
|
||||
maplibregl.addProtocol("pmtiles", protocol.tile);
|
||||
let URL = "https://r2-public.protomaps.com/protomaps-sample-datasets/terrarium_z9.pmtiles";
|
||||
let URL =
|
||||
"https://r2-public.protomaps.com/protomaps-sample-datasets/terrarium_z9.pmtiles";
|
||||
|
||||
function formatBytes(a,b=2){if(!+a)return"0 Bytes";const c=0>b?0:b,d=Math.floor(Math.log(a)/Math.log(1024));return`${parseFloat((a/Math.pow(1024,d)).toFixed(c))} ${["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][d]}`}
|
||||
function formatBytes(a, b = 2) {
|
||||
if (!+a) return "0 Bytes";
|
||||
const c = 0 > b ? 0 : b,
|
||||
d = Math.floor(Math.log(a) / Math.log(1024));
|
||||
return `${parseFloat((a / Math.pow(1024, d)).toFixed(c))} ${
|
||||
["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"][d]
|
||||
}`;
|
||||
}
|
||||
|
||||
fetch(URL, {method:"HEAD"}).then(resp => {
|
||||
fetch(URL, { method: "HEAD" }).then((resp) => {
|
||||
let length = resp.headers.get("Content-Length");
|
||||
document.getElementById("overlay").innerHTML = `<a href="${URL}">${URL}</a> (${formatBytes(length)})`;
|
||||
})
|
||||
document.getElementById(
|
||||
"overlay"
|
||||
).innerHTML = `<a href="${URL}">${URL}</a> (${formatBytes(length)})`;
|
||||
});
|
||||
|
||||
const map = new maplibregl.Map({
|
||||
container: 'map',
|
||||
container: "map",
|
||||
zoom: 0,
|
||||
center: [0, 0],
|
||||
style: {
|
||||
version: 8,
|
||||
sources: {
|
||||
"example_source": {
|
||||
example_source: {
|
||||
type: "raster-dem",
|
||||
url: "pmtiles://" + URL,
|
||||
attribution: '<a href="https://github.com/tilezen/joerd/blob/master/docs/attribution.md">Tilezen Joerd: Attribution</a>',
|
||||
encoding:"terrarium"
|
||||
}
|
||||
attribution:
|
||||
'<a href="https://github.com/tilezen/joerd/blob/master/docs/attribution.md">Tilezen Joerd: Attribution</a>',
|
||||
encoding: "terrarium",
|
||||
},
|
||||
},
|
||||
layers: [
|
||||
{
|
||||
"id":"dem",
|
||||
"source": "example_source",
|
||||
id: "dem",
|
||||
source: "example_source",
|
||||
"source-layer": "landuse",
|
||||
"type": "hillshade"
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
type: "hillshade",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user