From 64d78151493ad282bdd1befcc8ceb896e9c83a2e Mon Sep 17 00:00:00 2001 From: Brandon Liu Date: Wed, 5 Oct 2022 17:21:40 +0800 Subject: [PATCH] Inspector app handles v2 archives better and assumes they are vector tiles --- app/src/Inspector.tsx | 18 ++++++++++++------ app/src/Start.tsx | 1 - 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/Inspector.tsx b/app/src/Inspector.tsx index d5b24c3..dba8599 100644 --- a/app/src/Inspector.tsx +++ b/app/src/Inspector.tsx @@ -1,6 +1,6 @@ import { useState, useEffect, Dispatch, SetStateAction } from "react"; import { createPortal } from "react-dom"; -import { PMTiles, Entry, tileIdToZxy, TileType } from "../../js"; +import { PMTiles, Entry, tileIdToZxy, TileType, Header } from "../../js"; import { styled } from "./stitches.config"; import { decompressSync } from "fflate"; import Protobuf from "pbf"; @@ -274,14 +274,14 @@ const RasterPreview = (props: { file: PMTiles; entry: Entry }) => { function Inspector(props: { file: PMTiles }) { let [entryRows, setEntryRows] = useState([]); let [selectedEntry, setSelectedEntry] = useState(null); - let [tileType, setTileType] = useState(TileType.Unknown); + let [header, setHeader] = useState
(null); useEffect(() => { let fn = async () => { let header = await props.file.getHeader(); let entries = await props.file.root_entries(); setEntryRows(entries); - setTileType(header.tileType); + setHeader(header); }; fn(); @@ -292,13 +292,13 @@ function Inspector(props: { file: PMTiles }) { )); let tilePreview =
; - if (selectedEntry && tileType) { - if (tileType === TileType.Mvt) { + if (selectedEntry && header?.tileType) { + if (header.tileType === TileType.Mvt) { tilePreview = ( ); } else { @@ -306,9 +306,15 @@ function Inspector(props: { file: PMTiles }) { } } + let warning = ""; + if (header && header.specVersion < 3) { + warning = "Directory listing supported only for PMTiles v3 archives." + } + return ( + {warning} diff --git a/app/src/Start.tsx b/app/src/Start.tsx index caf82ea..6a4d6b9 100644 --- a/app/src/Start.tsx +++ b/app/src/Start.tsx @@ -98,7 +98,6 @@ const ExampleList = styled("div", { }); const EXAMPLE_FILES = [ - "https://protomaps-static.sfo3.digitaloceanspaces.com/osm_carto.pmtiles", "https://protomaps-static.sfo3.digitaloceanspaces.com/mantle-trial.pmtiles", "https://protomaps-static.sfo3.digitaloceanspaces.com/cb_2018_us_zcta510_500k_nolimit.pmtiles", "https://protomaps-static.sfo3.digitaloceanspaces.com/cb_2018_us_zcta510_500k_gzip.pmtiles",