js leafletRasterLayer: show console error if attempting to load a vector archive [#101]

This commit is contained in:
Brandon Liu
2022-12-02 12:52:01 +08:00
parent 32828f391b
commit 403d83a27e

View File

@@ -5,6 +5,7 @@ declare const document: any;
import { PMTiles, Source, TileType } from "./index"; import { PMTiles, Source, TileType } from "./index";
export const leafletRasterLayer = (source: PMTiles, options: any) => { export const leafletRasterLayer = (source: PMTiles, options: any) => {
let loaded = false;
const cls = L.GridLayer.extend({ const cls = L.GridLayer.extend({
createTile: function (coord: any, done: any) { createTile: function (coord: any, done: any) {
const el: any = document.createElement("img"); const el: any = document.createElement("img");
@@ -13,6 +14,16 @@ export const leafletRasterLayer = (source: PMTiles, options: any) => {
el.cancel = () => { el.cancel = () => {
controller.abort(); controller.abort();
}; };
if (!loaded) {
source.getHeader().then((header) => {
if (header.tileType == TileType.Mvt) {
console.error(
"Error: archive contains MVT vector tiles, but leafletRasterLayer is for displaying raster tiles. See https://github.com/protomaps/PMTiles/tree/main/js for details."
);
}
});
loaded = true;
}
source source
.getZxy(coord.z, coord.x, coord.y, signal) .getZxy(coord.z, coord.x, coord.y, signal)
.then((arr) => { .then((arr) => {