forked from OurHike/OurHike
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotocol.ts
More file actions
27 lines (21 loc) · 1006 Bytes
/
Copy pathprotocol.ts
File metadata and controls
27 lines (21 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Registers pmtiles' MapLibre protocol handler, so a style can reference the
// on-device archive as `pmtiles://...`.
//
// pmtiles' own documentation is explicit that the Protocol "must be added once
// globally." Registering twice would leave MapLibre holding two handlers for
// the same scheme, each with its own decoded-directory cache, so tile lookups
// would miss a cache that the other one had already warmed. Since several
// components may reasonably want to guarantee the protocol exists before they
// build a map, the guarantee is made idempotent here rather than pushed onto
// every caller to coordinate.
import { addProtocol } from 'maplibre-gl'
import { Protocol } from 'pmtiles'
export const PMTILES_SCHEME = 'pmtiles'
let registered: Protocol | null = null
export function registerPMTilesProtocol(): Protocol {
if (registered !== null) return registered
const protocol = new Protocol()
addProtocol(PMTILES_SCHEME, protocol.tile)
registered = protocol
return protocol
}