@locate2u/mesh-map 0.1.0-beta.0 → 0.1.0-beta.2
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/README.md +10 -0
- package/THIRD-PARTY-NOTICES.md +3 -3
- package/dist/errors.d.ts +2 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +9 -2
- package/dist/errors.js.map +1 -1
- package/dist/map.d.ts +13 -0
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +94 -5
- package/dist/map.js.map +1 -1
- package/dist/pause.d.ts +56 -0
- package/dist/pause.d.ts.map +1 -0
- package/dist/pause.js +134 -0
- package/dist/pause.js.map +1 -0
- package/dist/tile-fetch.d.ts +24 -0
- package/dist/tile-fetch.d.ts.map +1 -0
- package/dist/tile-fetch.js +74 -0
- package/dist/tile-fetch.js.map +1 -0
- package/package.json +40 -11
package/README.md
CHANGED
|
@@ -102,6 +102,7 @@ onError: (e) => {
|
|
|
102
102
|
// discovery_failed could not ask the service what it serves
|
|
103
103
|
// tile_unreadable a square arrived and could not be parsed
|
|
104
104
|
// quota_exceeded over the allowance for this period
|
|
105
|
+
// rate_limited too many squares in the last minute; clears itself
|
|
105
106
|
// token_refresh_failed the map will go dark when the current token expires
|
|
106
107
|
// e.fatal says whether the map is still usable.
|
|
107
108
|
}
|
|
@@ -109,6 +110,15 @@ onError: (e) => {
|
|
|
109
110
|
|
|
110
111
|
Credentials are stripped from every error before it reaches you.
|
|
111
112
|
|
|
113
|
+
### When the service says "too many"
|
|
114
|
+
|
|
115
|
+
If the tiles service answers 429, the control stops requesting map squares for
|
|
116
|
+
ten seconds — however much the person drags — then sends one request to check.
|
|
117
|
+
If that is refused it waits another ten seconds; if it succeeds, loading
|
|
118
|
+
resumes on its own. While it waits, a short notice over the map says so and
|
|
119
|
+
counts down. Restyle it with the `.mesh-map-notice` class, or turn it off with
|
|
120
|
+
`rateLimitNotice: false` (requests still pause either way).
|
|
121
|
+
|
|
112
122
|
With the custom element, the same thing arrives as a DOM event:
|
|
113
123
|
|
|
114
124
|
```js
|
package/THIRD-PARTY-NOTICES.md
CHANGED
|
@@ -15,17 +15,17 @@ exists from the first commit rather than from the day someone remembers.
|
|
|
15
15
|
|
|
16
16
|
| Package | Licence | Why we depend on it |
|
|
17
17
|
|---|---|---|
|
|
18
|
-
| [`maplibre-gl`](https://github.com/maplibre/maplibre-gl-js) | BSD-3-Clause | Renders the map. ⚠️ **MapLibre, never Mapbox GL JS v2 or later** — the latter requires a billed Mapbox account even when pointed at our own tiles, which would defeat the entire point of self-hosting the map. Pinned by `loc-mesh/design` ADR 0039. |
|
|
18
|
+
| [`maplibre-gl`](https://github.com/maplibre/maplibre-gl-js) **5.x** | BSD-3-Clause | Renders the map. ⚠️ **Pinned to 5, deliberately** — 6 moved the web worker into a separate file whose name it computes at runtime, which bundlers cannot emit; see `src/map.ts`. ⚠️ **MapLibre, never Mapbox GL JS v2 or later** — the latter requires a billed Mapbox account even when pointed at our own tiles, which would defeat the entire point of self-hosting the map. Pinned by `loc-mesh/design` ADR 0039. |
|
|
19
19
|
|
|
20
20
|
## Transitive dependencies
|
|
21
21
|
|
|
22
|
-
Audited 2026-10-16 across the whole declared tree of `maplibre-gl`
|
|
22
|
+
Audited 2026-10-16 across the whole declared tree of `maplibre-gl` 5.x (20 packages). **No
|
|
23
23
|
copyleft or share-alike licence appears anywhere** — no GPL, LGPL, AGPL, MPL or
|
|
24
24
|
SSPL.
|
|
25
25
|
|
|
26
26
|
| Licence | Packages |
|
|
27
27
|
|---|---|
|
|
28
|
-
| ISC | `earcut`, `kdbush`, `potpack`, `tinyqueue`, `quickselect`, `@maplibre/geojson-vt`, `@mapbox/point-geometry`, `@maplibre/maplibre-gl-style-spec` |
|
|
28
|
+
| ISC | 9 packages including `earcut`, `kdbush`, `potpack`, `tinyqueue`, `quickselect`, `@maplibre/geojson-vt`, `@mapbox/point-geometry`, `@maplibre/maplibre-gl-style-spec` |
|
|
29
29
|
| MIT | `bidi-js`, `gl-matrix`, `murmurhash-js`, `@types/geojson`, `@maplibre/vt-pbf` |
|
|
30
30
|
| BSD-3-Clause | `maplibre-gl`, `pbf`, `@mapbox/vector-tile` |
|
|
31
31
|
| BSD-2-Clause | `@mapbox/tiny-sdf`, `@mapbox/unitbezier` |
|
package/dist/errors.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export type MeshMapErrorCode =
|
|
|
26
26
|
| 'tile_unreadable'
|
|
27
27
|
/** The tenant is over its allowance for this period. */
|
|
28
28
|
| 'quota_exceeded'
|
|
29
|
+
/** This browser asked for map squares faster than the per-minute limit allows. Clears within a minute. */
|
|
30
|
+
| 'rate_limited'
|
|
29
31
|
/** Minting a short-lived map token failed, so the map cannot keep refreshing. */
|
|
30
32
|
| 'token_refresh_failed'
|
|
31
33
|
/** Anything else, with the original attached. */
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,MAAM,gBAAgB;AAC1B,sHAAsH;AACpH,qBAAqB;AACvB,2EAA2E;GACzE,oBAAoB;AACtB,oFAAoF;GAClF,aAAa;AACf,uGAAuG;GACrG,kBAAkB;AACpB,0EAA0E;GACxE,iBAAiB;AACnB,wDAAwD;GACtD,gBAAgB;AAClB,iFAAiF;GAC/E,sBAAsB;AACxB,iDAAiD;GAC/C,SAAS,CAAC;AAEd,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,gBAAgB,CAAC;IACvB,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,kEAAkE;AAClE,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ1C;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,MAAM,gBAAgB;AAC1B,sHAAsH;AACpH,qBAAqB;AACvB,2EAA2E;GACzE,oBAAoB;AACtB,oFAAoF;GAClF,aAAa;AACf,uGAAuG;GACrG,kBAAkB;AACpB,0EAA0E;GACxE,iBAAiB;AACnB,wDAAwD;GACtD,gBAAgB;AAClB,0GAA0G;GACxG,cAAc;AAChB,iFAAiF;GAC/E,sBAAsB;AACxB,iDAAiD;GAC/C,SAAS,CAAC;AAEd,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,gBAAgB,CAAC;IACvB,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,kEAAkE;AAClE,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ1C;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAmEnD"}
|
package/dist/errors.js
CHANGED
|
@@ -65,9 +65,16 @@ export function classify(raw) {
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
if (status === 429) {
|
|
68
|
+
// ⚠️ 429 has two causes with opposite fixes: the per-minute brake (wait a
|
|
69
|
+
// minute) and the monthly allowance (talk to Locate2u). The map library
|
|
70
|
+
// usually hides the response body, so only claim the allowance when the
|
|
71
|
+
// service said so; the brake is by far the commoner cause.
|
|
72
|
+
const quota = /quota_exceeded|allowance/i.test(message);
|
|
68
73
|
return {
|
|
69
|
-
code: 'quota_exceeded',
|
|
70
|
-
message:
|
|
74
|
+
code: quota ? 'quota_exceeded' : 'rate_limited',
|
|
75
|
+
message: quota
|
|
76
|
+
? 'This tenant is over its map allowance for the current period.'
|
|
77
|
+
: 'Map squares were requested faster than the per-minute limit allows. Loading resumes within a minute.',
|
|
71
78
|
status,
|
|
72
79
|
url,
|
|
73
80
|
fatal: false,
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAmCH,kEAAkE;AAClE,MAAM,UAAU,MAAM,CAAC,GAAW;IAChC,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACvB,KAAK,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,CAAC;YAAE,IAAI,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;gBAAE,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QACxG,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;IACtB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,CAAC;IACb,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAY;IACnC,MAAM,GAAG,GAAG,GAAsE,CAAC;IACnF,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,EAAE,OAAO,IAAI,GAAG,IAAI,8CAA8C,CAAC,CAAC;IAC9F,MAAM,MAA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,CAAC,CAAC,sGAAsG;YAC1G,MAAM;YACN,GAAG;YACH,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,GAAG;SACX,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACnB,OAAO;YACL,IAAI,EAAE,aAAa;YACnB,OAAO,EACL,wFAAwF;gBACxF,qBAAqB;YACvB,MAAM;YACN,GAAG;YACH,KAAK,EAAE,IAAI;YACX,KAAK,EAAE,GAAG;SACX,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AAC7E,CAAC"}
|
package/dist/map.d.ts
CHANGED
|
@@ -59,6 +59,12 @@ export interface MeshMapOptions {
|
|
|
59
59
|
buildings3d?: boolean;
|
|
60
60
|
/** Pin to a particular published region instead of the first one offered. */
|
|
61
61
|
region?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Show a short notice over the map while tile requests are paused because the
|
|
64
|
+
* service answered 429. On by default. Requests pause either way; this only
|
|
65
|
+
* controls whether the person looking at the map is told why.
|
|
66
|
+
*/
|
|
67
|
+
rateLimitNotice?: boolean;
|
|
62
68
|
/** Told why the map is not drawing. Strongly recommended — see `errors.ts`. */
|
|
63
69
|
onError?: (error: MeshMapError) => void;
|
|
64
70
|
}
|
|
@@ -74,6 +80,9 @@ export declare class MeshMap {
|
|
|
74
80
|
private theme;
|
|
75
81
|
private autoThemeTimer;
|
|
76
82
|
private disposed;
|
|
83
|
+
private notice;
|
|
84
|
+
private noticeTimer;
|
|
85
|
+
private unsubscribeGate;
|
|
77
86
|
private constructor();
|
|
78
87
|
/**
|
|
79
88
|
* Create a map. Asynchronous because it asks the service what it can serve
|
|
@@ -91,6 +100,10 @@ export declare class MeshMap {
|
|
|
91
100
|
get style(): StyleSpecification;
|
|
92
101
|
/** Stop timers and release the map. Safe to call twice. */
|
|
93
102
|
destroy(): void;
|
|
103
|
+
private onGate;
|
|
104
|
+
/** A plain notice over the map; the page can restyle it through `.mesh-map-notice`. */
|
|
105
|
+
private showNotice;
|
|
106
|
+
private hideNotice;
|
|
94
107
|
private startAutoTheme;
|
|
95
108
|
}
|
|
96
109
|
export {};
|
package/dist/map.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAuBH,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AAEjD,qFAAqF;AACrF,KAAK,kBAAkB,GAAG,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;AAC9D,OAAO,EAAgC,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAY,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAIlD,MAAM,WAAW,cAAc;IAC7B,yCAAyC;IACzC,SAAS,EAAE,WAAW,GAAG,MAAM,CAAC;IAChC,4FAA4F;IAC5F,YAAY,EAAE,MAAM,CAAC;IAErB,oFAAoF;IACpF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B,qBAAqB;IACrB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,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AAI,KAAK,IAAI,kBAAkB,CAE9B;IAED,2DAA2D;IAC3D,OAAO,IAAI,IAAI;IAUf,OAAO,CAAC,MAAM;IAOd,uFAAuF;IACvF,OAAO,CAAC,UAAU;IAiClB,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,cAAc;CAUvB"}
|
package/dist/map.js
CHANGED
|
@@ -17,15 +17,34 @@
|
|
|
17
17
|
* it is handed. A control that fetched your runs for you would be a product
|
|
18
18
|
* surface rather than a platform one — design ADR 0059 §4 and `scope.md`.
|
|
19
19
|
*/
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
20
|
+
// 🔴 MAPLIBRE 5, NOT 6, AND THE PIN IS LOAD-BEARING. Version 6 moved the web
|
|
21
|
+
// worker into a separate file whose name it computes at runtime
|
|
22
|
+
// (`dev ? "maplibre-gl-worker-dev.mjs" : "maplibre-gl-worker.mjs"`). A bundler
|
|
23
|
+
// cannot statically see that, so it never emits the file — and the failure is
|
|
24
|
+
// vicious: a dev server resolves it fine, a production build does not, and the
|
|
25
|
+
// missing path is answered by the single-page-app fallback with index.html and
|
|
26
|
+
// a 200. MapLibre reports "Worker failed to load", the map draws nothing, and
|
|
27
|
+
// the network tab shows no failed request at all.
|
|
28
|
+
//
|
|
29
|
+
// Measured 2026-10-16 against the published package in a stock Vite app:
|
|
30
|
+
// with 6.14.0, 0 layers drew; with 5.24.0, 52 drew and 29 street names
|
|
31
|
+
// rendered. Version 5 inlines the worker, so any bundler produces a working
|
|
32
|
+
// build with no configuration from the customer — which is the entire job of
|
|
33
|
+
// this package.
|
|
34
|
+
//
|
|
35
|
+
// ⚠️ Do not widen this range to `^5 || ^6` hoping for the best. npm would
|
|
36
|
+
// resolve 6 and every consumer would get a blank map.
|
|
37
|
+
//
|
|
38
|
+
// ⚠️ Named import, never a default: v6 removed the default export, and if this
|
|
39
|
+
// package ever does move to 6 the default form compiles and is undefined at
|
|
40
|
+
// runtime.
|
|
24
41
|
import { Map as MapLibreMap } from 'maplibre-gl';
|
|
25
42
|
import { Credential, transformRequest } from './credentials.js';
|
|
26
43
|
import { discover } from './discovery.js';
|
|
27
44
|
import { classify } from './errors.js';
|
|
28
45
|
import { themeFor } from './theme.js';
|
|
46
|
+
import { gate } from './pause.js';
|
|
47
|
+
import { registerTileProtocol, rewrite } from './tile-fetch.js';
|
|
29
48
|
const DEFAULT_PAIR = { day: 'light', night: 'dark' };
|
|
30
49
|
export class MeshMap {
|
|
31
50
|
/** The MapLibre map, for anything this control does not wrap. */
|
|
@@ -39,6 +58,9 @@ export class MeshMap {
|
|
|
39
58
|
theme;
|
|
40
59
|
autoThemeTimer;
|
|
41
60
|
disposed = false;
|
|
61
|
+
notice;
|
|
62
|
+
noticeTimer;
|
|
63
|
+
unsubscribeGate;
|
|
42
64
|
constructor(args) {
|
|
43
65
|
this.map = args.map;
|
|
44
66
|
this.published = args.published;
|
|
@@ -88,13 +110,14 @@ export class MeshMap {
|
|
|
88
110
|
// lost by somebody who never knew it was required. Compact is permitted:
|
|
89
111
|
// the OSMF guidelines allow it behind an information icon.
|
|
90
112
|
attributionControl: { compact: true },
|
|
91
|
-
transformRequest: transformRequest(origin, () => credential.current),
|
|
113
|
+
transformRequest: gatedTransform(transformRequest(origin, () => credential.current), origin),
|
|
92
114
|
});
|
|
93
115
|
const self = new MeshMap({ map, published, credential, origin, theme, options, onError });
|
|
94
116
|
// ⚠️ The handler that would have turned 2026-10-16's blank grey rectangle
|
|
95
117
|
// into one sentence. MapLibre reports tile parse failures on this event and
|
|
96
118
|
// nowhere else, and only if something is listening.
|
|
97
119
|
map.on('error', (e) => self.onError(classify(e?.error ?? e)));
|
|
120
|
+
self.unsubscribeGate = gate.subscribe((state, resumesAt) => self.onGate(state, resumesAt));
|
|
98
121
|
if (options.autoTheme && pair)
|
|
99
122
|
self.startAutoTheme(pair);
|
|
100
123
|
return self;
|
|
@@ -128,9 +151,61 @@ export class MeshMap {
|
|
|
128
151
|
this.disposed = true;
|
|
129
152
|
if (this.autoThemeTimer)
|
|
130
153
|
clearInterval(this.autoThemeTimer);
|
|
154
|
+
this.unsubscribeGate?.();
|
|
155
|
+
this.hideNotice();
|
|
131
156
|
this.credential.dispose();
|
|
132
157
|
this.map.remove();
|
|
133
158
|
}
|
|
159
|
+
onGate(state, resumesAt) {
|
|
160
|
+
if (this.disposed)
|
|
161
|
+
return;
|
|
162
|
+
if (state === 'open')
|
|
163
|
+
return this.hideNotice();
|
|
164
|
+
if (state !== 'paused' || this.options.rateLimitNotice === false)
|
|
165
|
+
return;
|
|
166
|
+
this.showNotice(resumesAt ?? Date.now());
|
|
167
|
+
}
|
|
168
|
+
/** A plain notice over the map; the page can restyle it through `.mesh-map-notice`. */
|
|
169
|
+
showNotice(resumesAt) {
|
|
170
|
+
if (!this.notice) {
|
|
171
|
+
const el = document.createElement('div');
|
|
172
|
+
el.className = 'mesh-map-notice';
|
|
173
|
+
el.setAttribute('role', 'status');
|
|
174
|
+
el.setAttribute('aria-live', 'polite');
|
|
175
|
+
Object.assign(el.style, {
|
|
176
|
+
position: 'absolute',
|
|
177
|
+
top: '12px',
|
|
178
|
+
left: '50%',
|
|
179
|
+
transform: 'translateX(-50%)',
|
|
180
|
+
zIndex: '10',
|
|
181
|
+
padding: '8px 14px',
|
|
182
|
+
borderRadius: '6px',
|
|
183
|
+
background: 'rgba(11, 15, 26, 0.85)',
|
|
184
|
+
color: '#fff',
|
|
185
|
+
font: '14px/1.4 system-ui, sans-serif',
|
|
186
|
+
pointerEvents: 'none',
|
|
187
|
+
whiteSpace: 'nowrap',
|
|
188
|
+
});
|
|
189
|
+
this.map.getContainer().appendChild(el);
|
|
190
|
+
this.notice = el;
|
|
191
|
+
}
|
|
192
|
+
const el = this.notice;
|
|
193
|
+
const render = () => {
|
|
194
|
+
const s = Math.max(1, Math.ceil((resumesAt - Date.now()) / 1000));
|
|
195
|
+
el.textContent = `Too many map requests. Trying again in ${s} second${s === 1 ? '' : 's'}…`;
|
|
196
|
+
};
|
|
197
|
+
render();
|
|
198
|
+
if (this.noticeTimer)
|
|
199
|
+
clearInterval(this.noticeTimer);
|
|
200
|
+
this.noticeTimer = setInterval(render, 1000);
|
|
201
|
+
}
|
|
202
|
+
hideNotice() {
|
|
203
|
+
if (this.noticeTimer)
|
|
204
|
+
clearInterval(this.noticeTimer);
|
|
205
|
+
this.noticeTimer = undefined;
|
|
206
|
+
this.notice?.remove();
|
|
207
|
+
this.notice = undefined;
|
|
208
|
+
}
|
|
134
209
|
startAutoTheme(pair) {
|
|
135
210
|
// Every five minutes is far more often than needed to land the switch
|
|
136
211
|
// within a few minutes of civil twilight, and costs nothing.
|
|
@@ -144,6 +219,20 @@ export class MeshMap {
|
|
|
144
219
|
}, 5 * 60 * 1000);
|
|
145
220
|
}
|
|
146
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Route map squares for the tiles service through the gated fetch in
|
|
224
|
+
* `tile-fetch.ts`, after the credential has been added. Everything else — the
|
|
225
|
+
* style, fonts, icons, any third-party source — goes untouched.
|
|
226
|
+
*/
|
|
227
|
+
function gatedTransform(inner, origin) {
|
|
228
|
+
registerTileProtocol();
|
|
229
|
+
return (url, resourceType) => {
|
|
230
|
+
const out = inner(url);
|
|
231
|
+
if (resourceType === 'Tile' && url.startsWith(origin))
|
|
232
|
+
return { url: rewrite(out.url) };
|
|
233
|
+
return out;
|
|
234
|
+
};
|
|
235
|
+
}
|
|
147
236
|
function resolvePair(auto) {
|
|
148
237
|
if (!auto)
|
|
149
238
|
return undefined;
|
package/dist/map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.js","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,8EAA8E;AAC9E,
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,6EAA6E;AAC7E,g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AC,aAAa,CAC5G,CAAC;IACF,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACrC,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK;QAAE,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChE,IAAI,OAAO,CAAC,WAAW,KAAK,IAAI;QAAE,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IAC5E,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;AACtB,CAAC"}
|
package/dist/pause.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stop asking for map squares while the service is saying "too many".
|
|
3
|
+
*
|
|
4
|
+
* 🔴 WHY THIS EXISTS. The tiles service answers 429 when one browser asks for
|
|
5
|
+
* squares faster than its per-minute limit. Left alone, the map library keeps
|
|
6
|
+
* requesting a square for every new piece of view while the person keeps
|
|
7
|
+
* dragging — every one of them refused, every one of them more load, and the
|
|
8
|
+
* limit never gets the quiet minute it needs to clear.
|
|
9
|
+
*
|
|
10
|
+
* So the first 429 closes a gate for ten seconds. Nothing is sent while it is
|
|
11
|
+
* closed: requests wait, and the ones the person drags past are cancelled by
|
|
12
|
+
* the map library before they ever reach the network. When the ten seconds are
|
|
13
|
+
* up ONE request goes out as a probe. If it is refused, the gate closes for
|
|
14
|
+
* another ten seconds; if it succeeds, everything waiting goes.
|
|
15
|
+
*
|
|
16
|
+
* ⚠️ One gate per page, not per map. The service counts per credential and
|
|
17
|
+
* per client address, so two maps on one page share one budget and must share
|
|
18
|
+
* one pause.
|
|
19
|
+
*/
|
|
20
|
+
export type GateState = 'open' | 'paused' | 'probing';
|
|
21
|
+
export interface GateListener {
|
|
22
|
+
(state: GateState, resumesAt: number | undefined): void;
|
|
23
|
+
}
|
|
24
|
+
export declare class RequestGate {
|
|
25
|
+
private readonly pauseMs;
|
|
26
|
+
private readonly now;
|
|
27
|
+
private state;
|
|
28
|
+
private resumesAt;
|
|
29
|
+
private probeOut;
|
|
30
|
+
private timer;
|
|
31
|
+
private readonly waiting;
|
|
32
|
+
private readonly listeners;
|
|
33
|
+
constructor(pauseMs?: number, now?: () => number);
|
|
34
|
+
get current(): GateState;
|
|
35
|
+
/** When the current pause ends, in epoch milliseconds. Undefined when not paused. */
|
|
36
|
+
get resumeTime(): number | undefined;
|
|
37
|
+
subscribe(listener: GateListener): () => void;
|
|
38
|
+
/** Resolves when this request may go to the network. Rejects if it is cancelled first. */
|
|
39
|
+
wait(signal?: AbortSignal): Promise<void>;
|
|
40
|
+
/** The service said 429. */
|
|
41
|
+
limited(): void;
|
|
42
|
+
/** A request came back with something other than 429. */
|
|
43
|
+
succeeded(): void;
|
|
44
|
+
/**
|
|
45
|
+
* A request ended without an answer — cancelled because the person dragged
|
|
46
|
+
* past it, or a network failure. If it was the probe, send another.
|
|
47
|
+
*/
|
|
48
|
+
abandoned(): void;
|
|
49
|
+
dispose(): void;
|
|
50
|
+
private startProbe;
|
|
51
|
+
private releaseOne;
|
|
52
|
+
private emit;
|
|
53
|
+
}
|
|
54
|
+
/** The page-wide gate every map shares. */
|
|
55
|
+
export declare const gate: RequestGate;
|
|
56
|
+
//# sourceMappingURL=pause.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pause.d.ts","sourceRoot":"","sources":["../src/pause.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEtD,MAAM,WAAW,YAAY;IAC3B,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;CACzD;AAED,qBAAa,WAAW;IASpB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG;IATtB,OAAO,CAAC,KAAK,CAAqB;IAClC,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,KAAK,CAA4C;IACzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA2B;gBAGlC,OAAO,SAAS,EAChB,GAAG,GAAE,MAAM,MAAyB;IAGvD,IAAI,OAAO,IAAI,SAAS,CAEvB;IAED,qFAAqF;IACrF,IAAI,UAAU,IAAI,MAAM,GAAG,SAAS,CAEnC;IAED,SAAS,CAAC,QAAQ,EAAE,YAAY,GAAG,MAAM,IAAI;IAK7C,0FAA0F;IAC1F,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBzC,4BAA4B;IAC5B,OAAO,IAAI,IAAI;IAYf,yDAAyD;IACzD,SAAS,IAAI,IAAI;IAUjB;;;OAGG;IACH,SAAS,IAAI,IAAI;IAMjB,OAAO,IAAI,IAAI;IAKf,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,IAAI;CAGb;AAQD,2CAA2C;AAC3C,eAAO,MAAM,IAAI,aAAoB,CAAC"}
|
package/dist/pause.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stop asking for map squares while the service is saying "too many".
|
|
3
|
+
*
|
|
4
|
+
* 🔴 WHY THIS EXISTS. The tiles service answers 429 when one browser asks for
|
|
5
|
+
* squares faster than its per-minute limit. Left alone, the map library keeps
|
|
6
|
+
* requesting a square for every new piece of view while the person keeps
|
|
7
|
+
* dragging — every one of them refused, every one of them more load, and the
|
|
8
|
+
* limit never gets the quiet minute it needs to clear.
|
|
9
|
+
*
|
|
10
|
+
* So the first 429 closes a gate for ten seconds. Nothing is sent while it is
|
|
11
|
+
* closed: requests wait, and the ones the person drags past are cancelled by
|
|
12
|
+
* the map library before they ever reach the network. When the ten seconds are
|
|
13
|
+
* up ONE request goes out as a probe. If it is refused, the gate closes for
|
|
14
|
+
* another ten seconds; if it succeeds, everything waiting goes.
|
|
15
|
+
*
|
|
16
|
+
* ⚠️ One gate per page, not per map. The service counts per credential and
|
|
17
|
+
* per client address, so two maps on one page share one budget and must share
|
|
18
|
+
* one pause.
|
|
19
|
+
*/
|
|
20
|
+
export class RequestGate {
|
|
21
|
+
pauseMs;
|
|
22
|
+
now;
|
|
23
|
+
state = 'open';
|
|
24
|
+
resumesAt;
|
|
25
|
+
probeOut = false;
|
|
26
|
+
timer;
|
|
27
|
+
waiting = [];
|
|
28
|
+
listeners = new Set();
|
|
29
|
+
constructor(pauseMs = 10_000, now = () => Date.now()) {
|
|
30
|
+
this.pauseMs = pauseMs;
|
|
31
|
+
this.now = now;
|
|
32
|
+
}
|
|
33
|
+
get current() {
|
|
34
|
+
return this.state;
|
|
35
|
+
}
|
|
36
|
+
/** When the current pause ends, in epoch milliseconds. Undefined when not paused. */
|
|
37
|
+
get resumeTime() {
|
|
38
|
+
return this.resumesAt;
|
|
39
|
+
}
|
|
40
|
+
subscribe(listener) {
|
|
41
|
+
this.listeners.add(listener);
|
|
42
|
+
return () => this.listeners.delete(listener);
|
|
43
|
+
}
|
|
44
|
+
/** Resolves when this request may go to the network. Rejects if it is cancelled first. */
|
|
45
|
+
wait(signal) {
|
|
46
|
+
if (this.state === 'open')
|
|
47
|
+
return Promise.resolve();
|
|
48
|
+
if (this.state === 'probing' && !this.probeOut) {
|
|
49
|
+
this.probeOut = true;
|
|
50
|
+
return Promise.resolve();
|
|
51
|
+
}
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const go = () => {
|
|
54
|
+
signal?.removeEventListener('abort', cancel);
|
|
55
|
+
resolve();
|
|
56
|
+
};
|
|
57
|
+
const cancel = () => {
|
|
58
|
+
const i = this.waiting.indexOf(go);
|
|
59
|
+
if (i >= 0)
|
|
60
|
+
this.waiting.splice(i, 1);
|
|
61
|
+
reject(abortError());
|
|
62
|
+
};
|
|
63
|
+
if (signal?.aborted)
|
|
64
|
+
return cancel();
|
|
65
|
+
signal?.addEventListener('abort', cancel, { once: true });
|
|
66
|
+
this.waiting.push(go);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** The service said 429. */
|
|
70
|
+
limited() {
|
|
71
|
+
// Concurrent requests already in flight all come back 429 together; the
|
|
72
|
+
// first one starts the pause and the rest must not keep extending it.
|
|
73
|
+
if (this.state === 'paused')
|
|
74
|
+
return;
|
|
75
|
+
this.state = 'paused';
|
|
76
|
+
this.probeOut = false;
|
|
77
|
+
this.resumesAt = this.now() + this.pauseMs;
|
|
78
|
+
if (this.timer)
|
|
79
|
+
clearTimeout(this.timer);
|
|
80
|
+
this.timer = setTimeout(() => this.startProbe(), this.pauseMs);
|
|
81
|
+
this.emit();
|
|
82
|
+
}
|
|
83
|
+
/** A request came back with something other than 429. */
|
|
84
|
+
succeeded() {
|
|
85
|
+
if (this.state !== 'probing')
|
|
86
|
+
return;
|
|
87
|
+
this.state = 'open';
|
|
88
|
+
this.probeOut = false;
|
|
89
|
+
this.resumesAt = undefined;
|
|
90
|
+
const all = this.waiting.splice(0);
|
|
91
|
+
all.forEach((go) => go());
|
|
92
|
+
this.emit();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A request ended without an answer — cancelled because the person dragged
|
|
96
|
+
* past it, or a network failure. If it was the probe, send another.
|
|
97
|
+
*/
|
|
98
|
+
abandoned() {
|
|
99
|
+
if (this.state !== 'probing')
|
|
100
|
+
return;
|
|
101
|
+
this.probeOut = false;
|
|
102
|
+
this.releaseOne();
|
|
103
|
+
}
|
|
104
|
+
dispose() {
|
|
105
|
+
if (this.timer)
|
|
106
|
+
clearTimeout(this.timer);
|
|
107
|
+
this.listeners.clear();
|
|
108
|
+
}
|
|
109
|
+
startProbe() {
|
|
110
|
+
this.timer = undefined;
|
|
111
|
+
this.state = 'probing';
|
|
112
|
+
this.resumesAt = undefined;
|
|
113
|
+
this.emit();
|
|
114
|
+
this.releaseOne();
|
|
115
|
+
}
|
|
116
|
+
releaseOne() {
|
|
117
|
+
const next = this.waiting.shift();
|
|
118
|
+
if (!next)
|
|
119
|
+
return; // the next request to arrive becomes the probe
|
|
120
|
+
this.probeOut = true;
|
|
121
|
+
next();
|
|
122
|
+
}
|
|
123
|
+
emit() {
|
|
124
|
+
this.listeners.forEach((l) => l(this.state, this.resumesAt));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function abortError() {
|
|
128
|
+
const e = new Error('The request was cancelled.');
|
|
129
|
+
e.name = 'AbortError';
|
|
130
|
+
return e;
|
|
131
|
+
}
|
|
132
|
+
/** The page-wide gate every map shares. */
|
|
133
|
+
export const gate = new RequestGate();
|
|
134
|
+
//# sourceMappingURL=pause.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pause.js","sourceRoot":"","sources":["../src/pause.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAQH,MAAM,OAAO,WAAW;IASH;IACA;IATX,KAAK,GAAc,MAAM,CAAC;IAC1B,SAAS,CAAqB;IAC9B,QAAQ,GAAG,KAAK,CAAC;IACjB,KAAK,CAA4C;IACxC,OAAO,GAAsB,EAAE,CAAC;IAChC,SAAS,GAAG,IAAI,GAAG,EAAgB,CAAC;IAErD,YACmB,UAAU,MAAM,EAChB,MAAoB,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;QADpC,YAAO,GAAP,OAAO,CAAS;QAChB,QAAG,GAAH,GAAG,CAAiC;IACpD,CAAC;IAEJ,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,qFAAqF;IACrF,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,SAAS,CAAC,QAAsB;QAC9B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,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GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAEO,UAAU;QAChB,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAClC,IAAI,CAAC,IAAI;YAAE,OAAO,CAAC,+CAA+C;QAClE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,EAAE,CAAC;IACT,CAAC;IAEO,IAAI;QACV,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAC/D,CAAC;CACF;AAED,SAAS,UAAU;IACjB,MAAM,CAAC,GAAG,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAClD,CAAC,CAAC,IAAI,GAAG,YAAY,CAAC;IACtB,OAAO,CAAC,CAAC;AACX,CAAC;AAED,2CAA2C;AAC3C,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map squares from the tiles service are fetched here rather than by the map
|
|
3
|
+
* library, so they can be held while the service is saying 429 — see
|
|
4
|
+
* `pause.ts`.
|
|
5
|
+
*
|
|
6
|
+
* The map library lets a page register its own URL scheme. `rewrite` moves
|
|
7
|
+
* every square bound for the tiles service onto that scheme; `fetchTile`
|
|
8
|
+
* waits at the gate, fetches over the real scheme, and tells the gate what
|
|
9
|
+
* came back. Nothing else the library loads is touched.
|
|
10
|
+
*/
|
|
11
|
+
import { type RequestGate } from './pause.js';
|
|
12
|
+
/** Register the scheme with the map library, once per page. */
|
|
13
|
+
export declare function registerTileProtocol(): void;
|
|
14
|
+
/** Move a square bound for the tiles service onto the gated scheme. */
|
|
15
|
+
export declare function rewrite(url: string): string;
|
|
16
|
+
export declare function fetchTile(url: string, signal: AbortSignal, headers?: Record<string, string>, deps?: {
|
|
17
|
+
gate?: RequestGate;
|
|
18
|
+
fetch?: typeof fetch;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
data: ArrayBuffer;
|
|
21
|
+
cacheControl?: string;
|
|
22
|
+
expires?: string;
|
|
23
|
+
}>;
|
|
24
|
+
//# sourceMappingURL=tile-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tile-fetch.d.ts","sourceRoot":"","sources":["../src/tile-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAKnE,+DAA+D;AAC/D,wBAAgB,oBAAoB,IAAI,IAAI,CAO3C;AAED,uEAAuE;AACvE,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,wBAAsB,SAAS,CAC7B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,IAAI,GAAE;IAAE,IAAI,CAAC,EAAE,WAAW,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CAAO,GACtD,OAAO,CAAC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA2BzE"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map squares from the tiles service are fetched here rather than by the map
|
|
3
|
+
* library, so they can be held while the service is saying 429 — see
|
|
4
|
+
* `pause.ts`.
|
|
5
|
+
*
|
|
6
|
+
* The map library lets a page register its own URL scheme. `rewrite` moves
|
|
7
|
+
* every square bound for the tiles service onto that scheme; `fetchTile`
|
|
8
|
+
* waits at the gate, fetches over the real scheme, and tells the gate what
|
|
9
|
+
* came back. Nothing else the library loads is touched.
|
|
10
|
+
*/
|
|
11
|
+
import { addProtocol } from 'maplibre-gl';
|
|
12
|
+
import { gate as defaultGate } from './pause.js';
|
|
13
|
+
const PREFIX = 'meshtile+';
|
|
14
|
+
let registered = false;
|
|
15
|
+
/** Register the scheme with the map library, once per page. */
|
|
16
|
+
export function registerTileProtocol() {
|
|
17
|
+
if (registered)
|
|
18
|
+
return;
|
|
19
|
+
registered = true;
|
|
20
|
+
const load = (params, abort) => fetchTile(params.url, abort.signal, params.headers);
|
|
21
|
+
addProtocol('meshtile+https', load);
|
|
22
|
+
addProtocol('meshtile+http', load);
|
|
23
|
+
}
|
|
24
|
+
/** Move a square bound for the tiles service onto the gated scheme. */
|
|
25
|
+
export function rewrite(url) {
|
|
26
|
+
return url.startsWith('http') ? PREFIX + url : url;
|
|
27
|
+
}
|
|
28
|
+
export async function fetchTile(url, signal, headers, deps = {}) {
|
|
29
|
+
const g = deps.gate ?? defaultGate;
|
|
30
|
+
const doFetch = deps.fetch ?? fetch;
|
|
31
|
+
const real = url.startsWith(PREFIX) ? url.slice(PREFIX.length) : url;
|
|
32
|
+
await g.wait(signal);
|
|
33
|
+
let res;
|
|
34
|
+
try {
|
|
35
|
+
res = await doFetch(real, { signal, headers });
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
g.abandoned();
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
if (res.status === 429) {
|
|
42
|
+
g.limited();
|
|
43
|
+
throw await httpError(res, real);
|
|
44
|
+
}
|
|
45
|
+
g.succeeded();
|
|
46
|
+
if (!res.ok)
|
|
47
|
+
throw await httpError(res, real);
|
|
48
|
+
return {
|
|
49
|
+
data: await res.arrayBuffer(),
|
|
50
|
+
cacheControl: res.headers.get('cache-control') ?? undefined,
|
|
51
|
+
expires: res.headers.get('expires') ?? undefined,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Shaped like the map library's own HTTP error, so `classify` reads it the
|
|
56
|
+
* same way. The service's error code goes into the message, because it is the
|
|
57
|
+
* only thing that separates the per-minute limit from the monthly allowance.
|
|
58
|
+
*/
|
|
59
|
+
async function httpError(res, url) {
|
|
60
|
+
let code = '';
|
|
61
|
+
try {
|
|
62
|
+
const body = (await res.json());
|
|
63
|
+
code = body?.error?.code ?? '';
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// An unreadable body is not worth a second failure.
|
|
67
|
+
}
|
|
68
|
+
const e = new Error(`${res.status} ${res.statusText}${code ? ` (${code})` : ''}`);
|
|
69
|
+
e.name = 'AJAXError';
|
|
70
|
+
e.status = res.status;
|
|
71
|
+
e.url = url;
|
|
72
|
+
return e;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=tile-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tile-fetch.js","sourceRoot":"","sources":["../src/tile-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,IAAI,IAAI,WAAW,EAAoB,MAAM,YAAY,CAAC;AAEnE,MAAM,MAAM,GAAG,WAAW,CAAC;AAC3B,IAAI,UAAU,GAAG,KAAK,CAAC;AAEvB,+DAA+D;AAC/D,MAAM,UAAU,oBAAoB;IAClC,IAAI,UAAU;QAAE,OAAO;IACvB,UAAU,GAAG,IAAI,CAAC;IAClB,MAAM,IAAI,GAAG,CAAC,MAAyD,EAAE,KAAsB,EAAE,EAAE,CACjG,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACtD,WAAW,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;IACpC,W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C,WAAW,EAAE;QAC7B,YAAY,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,SAAS;QAC3D,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,SAAS;KACjD,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,SAAS,CAAC,GAAa,EAAE,GAAW;IACjD,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAkC,CAAC;QACjE,IAAI,GAAG,IAAI,EAAE,KAAK,EAAE,IAAI,IAAI,EAAE,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,oDAAoD;IACtD,CAAC;IACD,MAAM,CAAC,GAAG,IAAI,KAAK,CAAC,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAG/E,CAAC;IACF,CAAC,CAAC,IAAI,GAAG,WAAW,CAAC;IACrB,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IACtB,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;IACZ,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@locate2u/mesh-map",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.2",
|
|
4
4
|
"description": "The Locate2u Mesh map control. Put a map on a page with your Mesh map key — themes, credentials, attribution and error reporting handled.",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"locate2u",
|
|
7
|
+
"mesh",
|
|
8
|
+
"map",
|
|
9
|
+
"maplibre",
|
|
10
|
+
"openstreetmap",
|
|
11
|
+
"logistics",
|
|
12
|
+
"delivery",
|
|
13
|
+
"web-component"
|
|
14
|
+
],
|
|
6
15
|
"homepage": "https://github.com/loc-mesh/sdk-map/tree/main/packages/web#readme",
|
|
7
|
-
"bugs": {
|
|
8
|
-
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/loc-mesh/sdk-map/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/loc-mesh/sdk-map.git",
|
|
22
|
+
"directory": "packages/web"
|
|
23
|
+
},
|
|
9
24
|
"license": "MIT",
|
|
10
25
|
"author": "Locate2u <engineering@locate2u.com> (https://locate2u.com)",
|
|
11
26
|
"publisher": "Locate2u",
|
|
@@ -14,12 +29,27 @@
|
|
|
14
29
|
"module": "./dist/index.js",
|
|
15
30
|
"types": "./dist/index.d.ts",
|
|
16
31
|
"exports": {
|
|
17
|
-
".": {
|
|
18
|
-
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./element": {
|
|
37
|
+
"types": "./dist/element.d.ts",
|
|
38
|
+
"import": "./dist/element.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"README.md",
|
|
44
|
+
"LICENSE",
|
|
45
|
+
"THIRD-PARTY-NOTICES.md"
|
|
46
|
+
],
|
|
47
|
+
"sideEffects": [
|
|
48
|
+
"./dist/element.js"
|
|
49
|
+
],
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=20"
|
|
19
52
|
},
|
|
20
|
-
"files": ["dist", "README.md", "LICENSE", "THIRD-PARTY-NOTICES.md"],
|
|
21
|
-
"sideEffects": ["./dist/element.js"],
|
|
22
|
-
"engines": { "node": ">=20" },
|
|
23
53
|
"scripts": {
|
|
24
54
|
"build": "tsc -p tsconfig.build.json",
|
|
25
55
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
@@ -28,7 +58,7 @@
|
|
|
28
58
|
"verify-publish": "npm pack --dry-run && npm publish --dry-run --tag beta"
|
|
29
59
|
},
|
|
30
60
|
"dependencies": {
|
|
31
|
-
"maplibre-gl": "^
|
|
61
|
+
"maplibre-gl": "^5.24.0"
|
|
32
62
|
},
|
|
33
63
|
"devDependencies": {
|
|
34
64
|
"@types/node": "^20.14.10",
|
|
@@ -37,7 +67,6 @@
|
|
|
37
67
|
},
|
|
38
68
|
"publishConfig": {
|
|
39
69
|
"access": "public",
|
|
40
|
-
"provenance": false,
|
|
41
70
|
"tag": "beta"
|
|
42
71
|
}
|
|
43
72
|
}
|