From 6bc2fdd6f9c54cf175b5b0f44b0b15bfb4febbd4 Mon Sep 17 00:00:00 2001 From: Brandon Liu Date: Wed, 3 Apr 2024 21:05:02 -0700 Subject: [PATCH 1/3] Detect pmtiles urls using URL parsing [#147] * fixes case where pmtiles URL has params at end. --- src/view.ts | 2 +- test/view.test.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/view.ts b/src/view.ts index a0f7727b..4fdec409 100644 --- a/src/view.ts +++ b/src/view.ts @@ -241,7 +241,7 @@ export const sourcesToViews = (options: SourceOptions) => { const maxDataZoom = o.maxDataZoom || 15; let source: TileSource; if (typeof o.url === "string") { - if (o.url.endsWith(".pmtiles")) { + if (o.url.startsWith("http") && new URL(o.url).pathname.endsWith(".pmtiles")) { source = new PmtilesSource(o.url, true); } else { source = new ZxySource(o.url, true); diff --git a/test/view.test.ts b/test/view.test.ts index 6ebdf540..7f48149d 100644 --- a/test/view.test.ts +++ b/test/view.test.ts @@ -1,7 +1,7 @@ import assert from "assert"; import { test } from "node:test"; import Point from "@mapbox/point-geometry"; -import { TileCache } from "../src/tilecache"; +import { TileCache, PmtilesSource } from "../src/tilecache"; import { View, sourcesToViews, wrap } from "../src/view"; import { StubSource } from "./test_helpers"; @@ -102,3 +102,8 @@ test("sources to views", async () => { }); assert.equal(v.get("source1").levelDiff, 1); }); + +test ("sources to views with pmtiles parameters", async () => { + let v = sourcesToViews({ url: "http://example.com/foo.pmtiles?k=v" }); + assert.ok(v.get("").tileCache.source instanceof PmtilesSource) +}); From 1e4c25cc694169ccfbc9800086620d0625222fbf Mon Sep 17 00:00:00 2001 From: Brandon Liu Date: Wed, 3 Apr 2024 21:12:58 -0700 Subject: [PATCH 2/3] linting --- src/view.ts | 5 ++++- test/view.test.ts | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/view.ts b/src/view.ts index 4fdec409..bbc47f49 100644 --- a/src/view.ts +++ b/src/view.ts @@ -241,7 +241,10 @@ export const sourcesToViews = (options: SourceOptions) => { const maxDataZoom = o.maxDataZoom || 15; let source: TileSource; if (typeof o.url === "string") { - if (o.url.startsWith("http") && new URL(o.url).pathname.endsWith(".pmtiles")) { + if ( + o.url.startsWith("http") && + new URL(o.url).pathname.endsWith(".pmtiles") + ) { source = new PmtilesSource(o.url, true); } else { source = new ZxySource(o.url, true); diff --git a/test/view.test.ts b/test/view.test.ts index 7f48149d..75987d26 100644 --- a/test/view.test.ts +++ b/test/view.test.ts @@ -1,7 +1,7 @@ import assert from "assert"; import { test } from "node:test"; import Point from "@mapbox/point-geometry"; -import { TileCache, PmtilesSource } from "../src/tilecache"; +import { PmtilesSource, TileCache } from "../src/tilecache"; import { View, sourcesToViews, wrap } from "../src/view"; import { StubSource } from "./test_helpers"; @@ -103,7 +103,7 @@ test("sources to views", async () => { assert.equal(v.get("source1").levelDiff, 1); }); -test ("sources to views with pmtiles parameters", async () => { - let v = sourcesToViews({ url: "http://example.com/foo.pmtiles?k=v" }); - assert.ok(v.get("").tileCache.source instanceof PmtilesSource) +test("sources to views with pmtiles parameters", async () => { + const v = sourcesToViews({ url: "http://example.com/foo.pmtiles?k=v" }); + assert.ok(v.get("").tileCache.source instanceof PmtilesSource); }); From 3768bffc7a4ce3d96de0d5296377e2d710b9a4e4 Mon Sep 17 00:00:00 2001 From: Brandon Liu Date: Wed, 3 Apr 2024 21:16:06 -0700 Subject: [PATCH 3/3] js 3.1.1 --- benchmark/index.html | 2 +- examples/comparison.html | 2 +- examples/fonts.html | 2 +- examples/inset.html | 2 +- examples/labels.html | 2 +- examples/leaflet.html | 2 +- examples/multi_source.html | 2 +- examples/pmtiles.html | 2 +- examples/pmtiles_headers.html | 2 +- examples/sandwich.html | 2 +- examples/sprites.html | 2 +- examples/static.html | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 14 files changed, 15 insertions(+), 15 deletions(-) diff --git a/benchmark/index.html b/benchmark/index.html index b717d981..3235e2cd 100644 --- a/benchmark/index.html +++ b/benchmark/index.html @@ -6,7 +6,7 @@ - +