From 403d83a27ea3095d730dcc3c7ba5f91095455381 Mon Sep 17 00:00:00 2001 From: Brandon Liu Date: Fri, 2 Dec 2022 12:52:01 +0800 Subject: [PATCH] js leafletRasterLayer: show console error if attempting to load a vector archive [#101] --- js/adapters.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/js/adapters.ts b/js/adapters.ts index e64f6fe..dcb8072 100644 --- a/js/adapters.ts +++ b/js/adapters.ts @@ -5,6 +5,7 @@ declare const document: any; import { PMTiles, Source, TileType } from "./index"; export const leafletRasterLayer = (source: PMTiles, options: any) => { + let loaded = false; const cls = L.GridLayer.extend({ createTile: function (coord: any, done: any) { const el: any = document.createElement("img"); @@ -13,6 +14,16 @@ export const leafletRasterLayer = (source: PMTiles, options: any) => { el.cancel = () => { 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 .getZxy(coord.z, coord.x, coord.y, signal) .then((arr) => {