mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-03-21 22:39:39 +00:00
JS cleanup (#640)
* JS cleanup * remove unused function * leaflet: properly clean up object URLs * maplibre: refactor tile type detection * update leaflet raster example
This commit is contained in:
@@ -15,17 +15,16 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
const map = L.map("map").setView([0, 0], 0);
|
const map = L.map("map");
|
||||||
|
|
||||||
const p = new pmtiles.PMTiles(
|
const p = new pmtiles.PMTiles(
|
||||||
"https://pmtiles.io/stamen_toner(raster)CC-BY+ODbL_z3.pmtiles"
|
"https://air.mtn.tw/flowers.pmtiles"
|
||||||
);
|
);
|
||||||
p.getHeader().then((h) => {
|
p.getHeader().then((h) => {
|
||||||
let layer = pmtiles.leafletRasterLayer(p, {
|
let layer = pmtiles.leafletRasterLayer(p, {
|
||||||
maxzoom: h.maxZoom,
|
maxNativeZoom: 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>.',
|
|
||||||
});
|
});
|
||||||
|
map.fitBounds(L.latLngBounds([h.minLat, h.minLon],[h.maxLat, h.maxLon]));
|
||||||
layer.addTo(map);
|
layer.addTo(map);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ export const leafletRasterLayer = (source: PMTiles, options: unknown) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tile.el.cancel) tile.el.cancel();
|
if (tile.el.cancel) tile.el.cancel();
|
||||||
|
if (tile.el.src) window.URL.revokeObjectURL(tile.el.src);
|
||||||
|
|
||||||
tile.el.width = 0;
|
tile.el.width = 0;
|
||||||
tile.el.height = 0;
|
tile.el.height = 0;
|
||||||
@@ -256,7 +257,6 @@ export class Protocol {
|
|||||||
const x = result[3];
|
const x = result[3];
|
||||||
const y = result[4];
|
const y = result[4];
|
||||||
|
|
||||||
const header = await instance.getHeader();
|
|
||||||
const resp = await instance?.getZxy(+z, +x, +y, abortController.signal);
|
const resp = await instance?.getZxy(+z, +x, +y, abortController.signal);
|
||||||
abortController.signal.throwIfAborted();
|
abortController.signal.throwIfAborted();
|
||||||
if (resp) {
|
if (resp) {
|
||||||
@@ -266,6 +266,7 @@ export class Protocol {
|
|||||||
expires: resp.expires,
|
expires: resp.expires,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
const header = await instance.getHeader();
|
||||||
if (header.tileType === TileType.Mvt) {
|
if (header.tileType === TileType.Mvt) {
|
||||||
if (this.errorOnMissingTile) {
|
if (this.errorOnMissingTile) {
|
||||||
throw new Error("Tile not found.");
|
throw new Error("Tile not found.");
|
||||||
|
|||||||
@@ -551,23 +551,6 @@ function deserializeIndex(buffer: ArrayBuffer): Entry[] {
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
function detectVersion(a: ArrayBuffer): number {
|
|
||||||
const v = new DataView(a);
|
|
||||||
if (v.getUint16(2, true) === 2) {
|
|
||||||
console.error(
|
|
||||||
"PMTiles spec version 2 is not supported; please see github.com/protomaps/PMTiles for tools to upgrade"
|
|
||||||
);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
if (v.getUint16(2, true) === 1) {
|
|
||||||
console.error(
|
|
||||||
"PMTiles spec version 1 is not supported; please see github.com/protomaps/PMTiles for tools to upgrade"
|
|
||||||
);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error thrown when a response for PMTiles over HTTP does not match previous, cached parts of the archive.
|
* Error thrown when a response for PMTiles over HTTP does not match previous, cached parts of the archive.
|
||||||
* The default PMTiles implementation will catch this error once internally and retry a request.
|
* The default PMTiles implementation will catch this error once internally and retry a request.
|
||||||
|
|||||||
Reference in New Issue
Block a user