@florasync/leaflet-geokit 0.9.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +2 -1
- package/dist/django/index.js +735 -735
- package/dist/django/index.js.map +1 -1
- package/dist/leaflet-geokit.es.js +1705 -1705
- package/dist/leaflet-geokit.es.js.map +1 -1
- package/dist/leaflet-geokit.external.es.js +1502 -1497
- package/dist/leaflet-geokit.external.es.js.map +1 -1
- package/dist/leaflet-geokit.pmtiles.es.js +95 -0
- package/dist/leaflet-geokit.pmtiles.es.js.map +1 -0
- package/dist/leaflet-geokit.umd.js +11 -14
- package/dist/leaflet-geokit.umd.js.map +1 -1
- package/dist/preact/{index-DCKj0r6a.js → index-D9ScFTVe.js} +475 -470
- package/dist/preact/index-D9ScFTVe.js.map +1 -0
- package/dist/preact/index.js +1 -1
- package/dist/preact-bundled/index.js +732 -732
- package/dist/preact-bundled/index.js.map +1 -1
- package/dist/react/{index-DCKj0r6a.js → index-D9ScFTVe.js} +475 -470
- package/dist/react/index-D9ScFTVe.js.map +1 -0
- package/dist/react/index.js +1 -1
- package/dist/react-bundled/index.js +732 -732
- package/dist/react-bundled/index.js.map +1 -1
- package/dist/types/lib/MapController.d.ts +3 -3
- package/dist/types/pmtiles.d.ts +38 -0
- package/dist/types/preact/index.d.ts +1 -1
- package/dist/types/react/index.d.ts +1 -1
- package/dist/types/types/public.d.ts +3 -3
- package/docs/pmtiles.md +153 -0
- package/docs/providers.md +8 -65
- package/package.json +27 -5
- package/dist/preact/index-DCKj0r6a.js.map +0 -1
- package/dist/react/index-DCKj0r6a.js.map +0 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import * as y from "leaflet";
|
|
2
|
+
import { maplibreGL as h } from "@maplibre/maplibre-gl-leaflet";
|
|
3
|
+
import { addProtocol as w, removeProtocol as b } from "maplibre-gl";
|
|
4
|
+
import { Protocol as v } from "pmtiles";
|
|
5
|
+
function L(e) {
|
|
6
|
+
var o, i;
|
|
7
|
+
return {
|
|
8
|
+
attribution: e.attribution,
|
|
9
|
+
provider: {
|
|
10
|
+
kind: "vector",
|
|
11
|
+
capabilities: {
|
|
12
|
+
attributionRequired: !0,
|
|
13
|
+
offline: (o = e.offline) != null ? o : "unknown",
|
|
14
|
+
apiKey: (i = e.apiKey) != null ? i : "host-defined"
|
|
15
|
+
},
|
|
16
|
+
createLayer: e.createLayer
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
let r, l = 0;
|
|
21
|
+
function g() {
|
|
22
|
+
if (!r) {
|
|
23
|
+
const o = new v();
|
|
24
|
+
w("pmtiles", o.tile), r = { protocol: o, owners: 0 };
|
|
25
|
+
}
|
|
26
|
+
r.owners++;
|
|
27
|
+
let e = !1;
|
|
28
|
+
return () => {
|
|
29
|
+
if (!e) {
|
|
30
|
+
if ((r == null ? void 0 : r.owners) === 1 && l > 0)
|
|
31
|
+
throw new Error("Remove PMTiles basemaps before releasing the protocol");
|
|
32
|
+
e = !0, r && --r.owners === 0 && (b("pmtiles"), r = void 0);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function A(e) {
|
|
37
|
+
if (!e.attribution.trim())
|
|
38
|
+
throw new Error("PMTiles attribution is required");
|
|
39
|
+
const { style: o, attribution: i, onMap: s } = e;
|
|
40
|
+
return L({
|
|
41
|
+
attribution: i,
|
|
42
|
+
offline: "unknown",
|
|
43
|
+
apiKey: "host-defined",
|
|
44
|
+
createLayer(m) {
|
|
45
|
+
if (m.Layer !== y.Layer)
|
|
46
|
+
throw new Error(
|
|
47
|
+
"PMTiles requires /external with one shared Leaflet instance"
|
|
48
|
+
);
|
|
49
|
+
const t = h({
|
|
50
|
+
style: o,
|
|
51
|
+
interactive: !1,
|
|
52
|
+
attributionControl: !1
|
|
53
|
+
}), p = t.onAdd, c = t.onRemove;
|
|
54
|
+
let n = !1;
|
|
55
|
+
return t.onAdd = function(a) {
|
|
56
|
+
var u, d;
|
|
57
|
+
try {
|
|
58
|
+
p.call(this, a);
|
|
59
|
+
} catch (f) {
|
|
60
|
+
try {
|
|
61
|
+
(u = t.getMaplibreMap()) == null || u.remove();
|
|
62
|
+
} finally {
|
|
63
|
+
(d = t.getContainer()) == null || d.remove();
|
|
64
|
+
}
|
|
65
|
+
throw f;
|
|
66
|
+
}
|
|
67
|
+
n = !0, l++;
|
|
68
|
+
try {
|
|
69
|
+
s == null || s(t.getMaplibreMap());
|
|
70
|
+
} catch (f) {
|
|
71
|
+
try {
|
|
72
|
+
c.call(this, a);
|
|
73
|
+
} finally {
|
|
74
|
+
n = !1, l--;
|
|
75
|
+
}
|
|
76
|
+
throw f;
|
|
77
|
+
}
|
|
78
|
+
return this;
|
|
79
|
+
}, t.onRemove = function(a) {
|
|
80
|
+
if (n)
|
|
81
|
+
try {
|
|
82
|
+
c.call(this, a);
|
|
83
|
+
} finally {
|
|
84
|
+
n = !1, l--;
|
|
85
|
+
}
|
|
86
|
+
return this;
|
|
87
|
+
}, t;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
A as createPMTilesBasemapAdapter,
|
|
93
|
+
g as registerPMTilesProtocol
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=leaflet-geokit.pmtiles.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"leaflet-geokit.pmtiles.es.js","sources":["../src/lib/providers.ts","../src/pmtiles.ts"],"sourcesContent":["import type * as Leaflet from \"leaflet\";\nimport { buildTileURL } from \"./TileProviderFactory.js\";\nimport type {\n TileProviderConfig,\n TileURLTemplate,\n} from \"./TileProviderFactory.js\";\n\n/** Technical potential is not a license to cache a vendor's data. */\nexport type OfflineSupport = \"unsupported\" | \"host-managed\" | \"unknown\";\nexport type ApiKeyRequirement = \"none\" | \"required\" | \"host-defined\";\n\nexport interface ProviderCapabilities {\n attributionRequired: boolean;\n offline: OfflineSupport;\n apiKey: ApiKeyRequirement;\n}\n\n/** Raster resolution does not own the map or drawing engine. */\nexport interface RasterTileProvider {\n kind: \"raster\";\n capabilities: ProviderCapabilities;\n resolve(): TileURLTemplate;\n}\n\n/** An optional renderer bridge must return a fresh, unmounted Leaflet layer.\n * The layer owns renderer/event cleanup in onRemove. Global protocols are host-owned.\n */\nexport interface VectorBasemapProvider {\n kind: \"vector\";\n capabilities: ProviderCapabilities;\n createLayer(leaflet: typeof Leaflet): Leaflet.Layer;\n}\n\nexport type BasemapProvider = RasterTileProvider | VectorBasemapProvider;\n\n/** Drawing is independent of basemap vendors; native renderer replacements\n * must implement this separate port before claiming drawing parity.\n */\nexport interface DrawEngineAdapter<TContext, TDocument, TCommand> {\n attach(context: TContext): void;\n read(): TDocument;\n write(document: TDocument): void;\n execute(command: TCommand): boolean;\n dispose(): void;\n}\n\nexport interface ProviderDiagnostics {\n kind: \"raster\" | \"vector\";\n attribution: \"present\" | \"missing\";\n attributionRequired: boolean;\n offline: OfflineSupport;\n apiKey: ApiKeyRequirement;\n drawing: \"leaflet-draw\";\n /** Static capability report, not a network/credentials/renderer health probe. */\n scope: \"configuration\";\n}\n\n/** Explicit field selection: never return URL, style, key, or arbitrary provider metadata. */\nexport function getProviderDiagnostics(\n provider: BasemapProvider,\n attribution: string,\n): ProviderDiagnostics {\n return {\n kind: provider.kind,\n attribution: attribution.trim() ? \"present\" : \"missing\",\n attributionRequired: provider.capabilities.attributionRequired,\n offline: provider.capabilities.offline,\n apiKey: provider.capabilities.apiKey,\n drawing: \"leaflet-draw\",\n scope: \"configuration\",\n };\n}\n\nexport function createRasterProvider(\n config: TileProviderConfig,\n): RasterTileProvider {\n const name = config.provider.trim().toLowerCase();\n // Snapshot the config so later caller mutation cannot silently change a provider.\n const snapshot = { ...config };\n return {\n kind: \"raster\",\n capabilities: {\n attributionRequired: true,\n offline: name === \"osm\" || name === \"here\" ? \"unsupported\" : \"unknown\",\n apiKey: name === \"here\" ? \"required\" : \"none\",\n },\n resolve: () => buildTileURL(snapshot),\n };\n}\n\n/** Existing custom tile-url behavior, without guessing licensing or authentication. */\nexport function createCustomRasterProvider(\n config: TileURLTemplate,\n): RasterTileProvider {\n const snapshot = { ...config, subdomains: config.subdomains?.slice() };\n return {\n kind: \"raster\",\n capabilities: {\n attributionRequired: true,\n offline: \"unknown\",\n apiKey: \"host-defined\",\n },\n resolve: () => ({ ...snapshot, subdomains: snapshot.subdomains?.slice() }),\n };\n}\n\nexport interface BasemapAdapter {\n provider: BasemapProvider;\n /** Trusted host-supplied attribution HTML, never unsanitized remote input. */\n attribution: string;\n}\n\n/** Feasibility shim: host injects a MapLibre-to-Leaflet bridge and owns PMTiles\n * protocol registration. No MapLibre, PMTiles, Google SDK, or keys in core.\n */\nexport function createMapLibreBasemapAdapter(options: {\n createLayer: (leaflet: typeof Leaflet) => Leaflet.Layer;\n attribution: string;\n offline?: OfflineSupport;\n apiKey?: ApiKeyRequirement;\n}): BasemapAdapter {\n return {\n attribution: options.attribution,\n provider: {\n kind: \"vector\",\n capabilities: {\n attributionRequired: true,\n offline: options.offline ?? \"unknown\",\n apiKey: options.apiKey ?? \"host-defined\",\n },\n createLayer: options.createLayer,\n },\n };\n}\n","import * as L from \"leaflet\";\nimport { maplibreGL } from \"@maplibre/maplibre-gl-leaflet\";\nimport { addProtocol, removeProtocol } from \"maplibre-gl\";\nimport type { StyleSpecification } from \"@maplibre/maplibre-gl-style-spec\";\nimport { Protocol } from \"pmtiles\";\nimport { createMapLibreBasemapAdapter } from \"./lib/providers.js\";\nimport type { BasemapAdapter } from \"./lib/providers.js\";\n\nlet registration: { protocol: Protocol; owners: number } | undefined;\nlet mountedLayers = 0;\n\n/** Register once per application; leases share a cache. Do not also register the\n * `pmtiles` scheme yourself. Release all leases after removing all adapter maps.\n * Hosts already managing the scheme may omit this helper entirely.\n */\nexport function registerPMTilesProtocol(): () => void {\n if (!registration) {\n const protocol = new Protocol();\n addProtocol(\"pmtiles\", protocol.tile);\n registration = { protocol, owners: 0 };\n }\n registration.owners++;\n let released = false;\n return () => {\n if (released) return;\n if (registration?.owners === 1 && mountedLayers > 0) {\n throw new Error(\"Remove PMTiles basemaps before releasing the protocol\");\n }\n released = true;\n if (registration && --registration.owners === 0) {\n removeProtocol(\"pmtiles\");\n registration = undefined;\n }\n };\n}\n\n/** Stable event surface of the renderer, without importing its private worker\n * declarations into strict NodeNext consumers. The runtime value is a MapLibre\n * Map; hosts needing its full API may narrow it using their own renderer types.\n */\nexport interface PMTilesMap {\n on(type: \"error\", listener: (event: { error: Error }) => void): unknown;\n on(type: \"load\" | \"remove\", listener: () => void): unknown;\n off(type: \"error\", listener: (event: { error: Error }) => void): unknown;\n off(type: \"load\" | \"remove\", listener: () => void): unknown;\n}\n\nexport interface PMTilesBasemapOptions {\n /** Trusted MapLibre style; use pmtiles://https://... vector source URLs.\n * Source-layer names must match the archive. No vendor schema is assumed.\n */\n style: StyleSpecification | string;\n /** Trusted HTML required by your data license; shown by Leaflet. */\n attribution: string;\n /** Called on mount, before asynchronous load/error events. Attach listeners\n * here for readiness and explicit host fallback. Never implies offline support.\n */\n onMap?: (map: PMTilesMap) => void;\n}\n\n/** Optional concrete MapLibre bridge. Use /external and the same Leaflet module.\n * Leaflet retains interaction, drawing, and view ownership (no pitch/rotation).\n * Protocol registration is explicit and application-owned.\n */\nexport function createPMTilesBasemapAdapter(\n options: PMTilesBasemapOptions,\n): BasemapAdapter {\n if (!options.attribution.trim())\n throw new Error(\"PMTiles attribution is required\");\n const { style, attribution, onMap } = options;\n return createMapLibreBasemapAdapter({\n attribution,\n offline: \"unknown\",\n apiKey: \"host-defined\",\n createLayer(leaflet) {\n if (leaflet.Layer !== L.Layer) {\n throw new Error(\n \"PMTiles requires /external with one shared Leaflet instance\",\n );\n }\n const layer = maplibreGL({\n style,\n interactive: false,\n attributionControl: false,\n });\n const add = layer.onAdd;\n const remove = layer.onRemove;\n let mounted = false;\n layer.onAdd = function (map) {\n try {\n add.call(this, map);\n } catch (error) {\n // The upstream bridge appends its container before constructing WebGL.\n // A constructor failure must not leave a dead canvas in the tile pane.\n try {\n layer.getMaplibreMap()?.remove();\n } finally {\n layer.getContainer()?.remove();\n }\n throw error;\n }\n mounted = true;\n mountedLayers++;\n try {\n onMap?.(layer.getMaplibreMap());\n } catch (error) {\n try {\n remove.call(this, map);\n } finally {\n mounted = false;\n mountedLayers--;\n }\n throw error;\n }\n return this;\n };\n layer.onRemove = function (map) {\n if (mounted) {\n try {\n remove.call(this, map);\n } finally {\n mounted = false;\n mountedLayers--;\n }\n }\n return this;\n };\n return layer;\n },\n });\n}\n"],"names":["createMapLibreBasemapAdapter","options","_a","_b","registration","mountedLayers","registerPMTilesProtocol","protocol","Protocol","addProtocol","released","removeProtocol","createPMTilesBasemapAdapter","style","attribution","onMap","leaflet","L","layer","maplibreGL","add","remove","mounted","map","error"],"mappings":";;;;AAmHO,SAASA,EAA6BC,GAK1B;;AACjB,SAAO;AAAA,IACL,aAAaA,EAAQ;AAAA,IACrB,UAAU;AAAA,MACR,MAAM;AAAA,MACN,cAAc;AAAA,QACZ,qBAAqB;AAAA,QACrB,UAASC,IAAAD,EAAQ,YAAR,OAAAC,IAAmB;AAAA,QAC5B,SAAQC,IAAAF,EAAQ,WAAR,OAAAE,IAAkB;AAAA,MAAA;AAAA,MAE5B,aAAaF,EAAQ;AAAA,IAAA;AAAA,EACvB;AAEJ;AC7HA,IAAIG,GACAC,IAAgB;AAMb,SAASC,IAAsC;AACpD,MAAI,CAACF,GAAc;AACjB,UAAMG,IAAW,IAAIC,EAAA;AACrB,IAAAC,EAAY,WAAWF,EAAS,IAAI,GACpCH,IAAe,EAAE,UAAAG,GAAU,QAAQ,EAAA;AAAA,EACrC;AACA,EAAAH,EAAa;AACb,MAAIM,IAAW;AACf,SAAO,MAAM;AACX,QAAI,CAAAA,GACJ;AAAA,WAAIN,KAAA,gBAAAA,EAAc,YAAW,KAAKC,IAAgB;AAChD,cAAM,IAAI,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