diff --git a/app/src/MapView.tsx b/app/src/MapView.tsx index 7378aa98..7ffcbfb1 100644 --- a/app/src/MapView.tsx +++ b/app/src/MapView.tsx @@ -42,6 +42,17 @@ import { parseHash, } from "./utils"; +const STYLE_MAJOR_VERSION = 4; + +const DEFAULT_TILES = "https://demo-bucket.protomaps.com/v4.pmtiles"; + +const VERSION_COMPATIBILITY: Record = { + 4: [4], + 3: [3], + 2: [2], + 1: [1], +}; + const ATTRIBUTION = 'Protomaps © OpenStreetMap'; @@ -52,9 +63,6 @@ function getSourceLayer(l: LayerSpecification): string { return ""; } -const areSetsEqual = (a: Set, b: Set) => - a.size === b.size && [...a].every((value) => b.has(value)); - const featureIdToOsmId = (raw: string | number) => { return Number(BigInt(raw) & ((BigInt(1) << BigInt(44)) - BigInt(1))); }; @@ -213,6 +221,7 @@ function MapLibreView(props: { showBoxes: boolean; tiles?: string; npmLayers: LayerSpecification[]; + npmVersion?: string; droppedArchive?: PMTiles; ref?: (ref: MapLibreViewRef) => void; }) { @@ -225,8 +234,7 @@ function MapLibreView(props: { const [timelinessInfo, setTimelinessInfo] = createSignal(); const [protocolRef, setProtocolRef] = createSignal(); const [zoom, setZoom] = createSignal(0); - const [mismatchedTilesetVersion, setMismatchedTilesetVersion] = - createSignal(false); + const [mismatch, setMismatch] = createSignal(""); onMount(() => { props.ref?.({ fit }); @@ -404,26 +412,24 @@ function MapLibreView(props: { }); createEffect(() => { - const layersInStyle = new Set( - memoizedStyle() - .layers.map((l) => { - if ("source-layer" in l) { - return l["source-layer"]; - } - }) - .filter((v) => v !== undefined), - ); + const styleMajorVersion = props.npmVersion + ? +props.npmVersion.split(".")[0] + : STYLE_MAJOR_VERSION; + console.log(styleMajorVersion); memoizedArchive() ?.getMetadata() .then((m) => { - if ( - m instanceof Object && - "vector_layers" in m && - m.vector_layers instanceof Array - ) { - const layersInTiles = new Set(m.vector_layers.map((v) => v.id)); - if (!areSetsEqual(layersInTiles, layersInStyle)) { - setMismatchedTilesetVersion(true); + if (m instanceof Object && "version" in m) { + const tilesetVersion = +(m.version as string).split(".")[0]; + console.log(tilesetVersion); + if ( + VERSION_COMPATIBILITY[tilesetVersion].indexOf(styleMajorVersion) < 0 + ) { + setMismatch( + `style v${styleMajorVersion} may not be compatible with tileset v${tilesetVersion}. `, + ); + } else { + setMismatch(""); } } }); @@ -449,9 +455,9 @@ function MapLibreView(props: {