Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect pmtiles urls using URL parsing [#147] #148

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script src="pixelmatch.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.0/dist/protomaps-leaflet.min.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.1/dist/protomaps-leaflet.min.js"></script>
<!-- <script src="../dist/protomaps-leaflet.js"></script> -->
<style>
html {
Expand Down
2 changes: 1 addition & 1 deletion examples/comparison.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@3.3.1/dist/maplibre-gl.css" crossorigin="anonymous">
<script src="https://unpkg.com/maplibre-gl@3.3.1/dist/maplibre-gl.js" crossorigin="anonymous"></script>
<script src="https://unpkg.com/@maplibre/maplibre-gl-leaflet@0.0.20/leaflet-maplibre-gl.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.0/dist/protomaps-leaflet.min.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.1/dist/protomaps-leaflet.min.js"></script>
<style>
#parent {
display:flex;
Expand Down
2 changes: 1 addition & 1 deletion examples/fonts.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet-hash@0.2.1/leaflet-hash.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.0/dist/protomaps-leaflet.min.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.1/dist/protomaps-leaflet.min.js"></script>
<!-- <script src="../dist/protomaps-leaflet.js"></script> -->

<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100..900&family=Work+Sans:wght@100..900&family=Petrona:wght@100..900&family=Raleway:wght@100..900" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion examples/inset.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/protomaps-leaflet@3.1.0/dist/protomaps-leaflet.min.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.1/dist/protomaps-leaflet.min.js"></script>
<!-- <script src="../dist/protomaps-leaflet.js"></script> -->
<style>
#map {
Expand Down
2 changes: 1 addition & 1 deletion examples/labels.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet-hash@0.2.1/leaflet-hash.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.0/dist/protomaps-leaflet.min.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.1/dist/protomaps-leaflet.min.js"></script>
<!-- <script src="../dist/protomaps-leaflet.js"></script> -->
<style>
body, #map {
Expand Down
2 changes: 1 addition & 1 deletion examples/leaflet.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet-hash@0.2.1/leaflet-hash.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.0/dist/protomaps-leaflet.min.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.1/dist/protomaps-leaflet.min.js"></script>
<!-- <script src="../dist/protomaps-leaflet.js"></script> -->
<style>
body, #map {
Expand Down
2 changes: 1 addition & 1 deletion examples/multi_source.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet-hash@0.2.1/leaflet-hash.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.0/dist/protomaps-leaflet.min.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.1/dist/protomaps-leaflet.min.js"></script>
<!-- <script src="../dist/protomaps-leaflet.js"></script> -->
<style>
body, #map {
Expand Down
2 changes: 1 addition & 1 deletion examples/pmtiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.0/dist/protomaps-leaflet.min.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.1/dist/protomaps-leaflet.min.js"></script>
<!-- <script src="../dist/protomaps-leaflet.js"></script> -->
<style>
body, #map {
Expand Down
2 changes: 1 addition & 1 deletion examples/pmtiles_headers.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script src="https://unpkg.com/pmtiles@3.0.3/dist/pmtiles.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.0/dist/protomaps-leaflet.min.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.1/dist/protomaps-leaflet.min.js"></script>
<!-- <script src="../dist/protomaps-leaflet.js"></script> -->
<style>
body, #map {
Expand Down
2 changes: 1 addition & 1 deletion examples/sandwich.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet-hash@0.2.1/leaflet-hash.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.0/dist/protomaps-leaflet.min.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.1/dist/protomaps-leaflet.min.js"></script>
<!-- <script src="../dist/protomaps-leaflet.js"></script> -->
<style>
body, #map {
Expand Down
2 changes: 1 addition & 1 deletion examples/sprites.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet-hash@0.2.1/leaflet-hash.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.0/dist/protomaps-leaflet.min.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.1/dist/protomaps-leaflet.min.js"></script>
<!-- <script src="../dist/protomaps-leaflet.js"></script> -->
<style>
body, #map {
Expand Down
2 changes: 1 addition & 1 deletion examples/static.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/protomaps-leaflet@3.1.0/dist/protomaps-leaflet.min.js"></script>
<script src="https://unpkg.com/protomaps-leaflet@3.1.1/dist/protomaps-leaflet.min.js"></script>
<!-- <script src="../dist/protomaps-leaflet.js"></script> -->
<style>
#map {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "protomaps-leaflet",
"version": "3.1.0",
"version": "3.1.1",
"files": [
"dist",
"src"
Expand Down
5 changes: 4 additions & 1 deletion src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.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);
Expand Down
7 changes: 6 additions & 1 deletion test/view.test.ts
Original file line number Diff line number Diff line change
@@ -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 { PmtilesSource, TileCache } from "../src/tilecache";
import { View, sourcesToViews, wrap } from "../src/view";
import { StubSource } from "./test_helpers";

Expand Down Expand Up @@ -102,3 +102,8 @@ test("sources to views", async () => {
});
assert.equal(v.get("source1").levelDiff, 1);
});

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);
});