@chaosity/location-client 0.10.0 → 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.
Files changed (2) hide show
  1. package/README.md +68 -7
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -34,6 +34,12 @@ npm install maplibre-gl
34
34
  npm install maplibre-gl @maplibre/maplibre-gl-geocoder
35
35
  ```
36
36
 
37
+ The map helpers need `maplibre-gl` 6.4.1 or a later 6.x release. Earlier
38
+ releases carry
39
+ [GHSA-jrc7-96c5-q579](https://github.com/advisories/GHSA-jrc7-96c5-q579), an
40
+ XSS in the attribution control, and none of them has a fix. MapLibre 6 needs
41
+ its worker set up once under a bundler: see [The MapLibre worker](#the-maplibre-worker).
42
+
37
43
  ## Key Features
38
44
 
39
45
  - **Custom Authentication**: Uses Bearer tokens instead of AWS SigV4
@@ -183,7 +189,12 @@ import {
183
189
  fetchMapStyle,
184
190
  createTransformRequest,
185
191
  } from '@chaosity/location-client'
186
- import maplibregl from 'maplibre-gl'
192
+ import * as maplibregl from 'maplibre-gl'
193
+ import 'maplibre-gl/dist/maplibre-gl.css'
194
+ // Vite. For other bundlers, see "The MapLibre worker" below.
195
+ import workerUrl from 'maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url'
196
+
197
+ maplibregl.setWorkerUrl(workerUrl)
187
198
 
188
199
  const style = await fetchMapStyle(apiUrl, 'Standard', getToken, {
189
200
  colorScheme: 'Dark',
@@ -209,6 +220,58 @@ const style = await fetchMapStyle(apiUrl, 'Standard', getToken, {
209
220
  // then `maxPitch: 85` on the map, so the camera can tilt to see them
210
221
  ```
211
222
 
223
+ ### The MapLibre worker
224
+
225
+ MapLibre 6 loads and parses its tiles in a Web Worker, and it finds the
226
+ worker's file from its own module URL. A bundler rewrites that URL, so an
227
+ application built with one sets the worker's URL once, before the first map.
228
+ Without it the map mounts, draws no tile, and logs "Worker failed to load".
229
+
230
+ With Vite, import the worker's URL, as in the example above:
231
+
232
+ ```typescript
233
+ import * as maplibregl from 'maplibre-gl'
234
+ import workerUrl from 'maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url'
235
+
236
+ maplibregl.setWorkerUrl(workerUrl)
237
+ ```
238
+
239
+ With Next.js, serve the worker and the chunk it imports from `public/`. Copy
240
+ them before every build and dev run:
241
+
242
+ ```js
243
+ // scripts/copy-maplibre-worker.mjs
244
+ import { copyFileSync, mkdirSync } from 'node:fs'
245
+ import { createRequire } from 'node:module'
246
+ import path from 'node:path'
247
+
248
+ const pkg = createRequire(import.meta.url).resolve('maplibre-gl/package.json')
249
+ const dist = path.join(path.dirname(pkg), 'dist')
250
+ const dest = path.join(process.cwd(), 'public', 'maplibre')
251
+ mkdirSync(dest, { recursive: true })
252
+ for (const file of ['maplibre-gl-worker.mjs', 'maplibre-gl-shared.mjs']) {
253
+ copyFileSync(path.join(dist, file), path.join(dest, file))
254
+ }
255
+ ```
256
+
257
+ ```json
258
+ "scripts": {
259
+ "predev": "node scripts/copy-maplibre-worker.mjs",
260
+ "prebuild": "node scripts/copy-maplibre-worker.mjs"
261
+ }
262
+ ```
263
+
264
+ Then, in the client component that builds the map:
265
+
266
+ ```typescript
267
+ import * as maplibregl from 'maplibre-gl'
268
+
269
+ maplibregl.setWorkerUrl('/maplibre/maplibre-gl-worker.mjs')
270
+ ```
271
+
272
+ Other bundlers, and loading MapLibre from a CDN, are covered in MapLibre's own
273
+ [installation guide](https://maplibre.org/maplibre-gl-js/docs/#installation).
274
+
212
275
  ### Switching Map Language
213
276
 
214
277
  Change map label language instantly on the client side — no API calls needed:
@@ -321,7 +384,8 @@ Requires the optional peers: `npm install maplibre-gl @maplibre/maplibre-gl-geoc
321
384
  ```typescript
322
385
  import { GeoPlacesClient, GeoPlaces } from '@chaosity/location-client'
323
386
  import MaplibreGeocoder from '@maplibre/maplibre-gl-geocoder'
324
- import maplibregl from 'maplibre-gl'
387
+ import '@maplibre/maplibre-gl-geocoder/dist/maplibre-gl-geocoder.css'
388
+ import * as maplibregl from 'maplibre-gl'
325
389
 
326
390
  // GeoPlaces adapter takes a GeoPlacesClient instance and the map
327
391
  const client = new GeoPlacesClient({ apiUrl, token })
@@ -475,13 +539,10 @@ const style = await fetchMapStyle(apiUrl, 'Standard', getToken, {
475
539
  poiDensity: 'Sparse',
476
540
  language: 'fr',
477
541
  })
478
-
479
- const map = new maplibregl.Map({
480
- style,
481
- transformRequest: createTransformRequest(apiUrl, getToken),
482
- })
483
542
  ```
484
543
 
544
+ Hand `style` to `new maplibregl.Map`, with the worker set, as in [MapLibre Map Integration](#maplibre-map-integration).
545
+
485
546
  The overlays need the `terrain`, `buildings`, `contours`, `traffic` and `travel-modes` plan features — see [Plan features](#plan-features):
486
547
 
487
548
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaosity/location-client",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Client library for Chaosity Location Service with AWS Location Service compatibility",
5
5
  "type": "module",
6
6
  "main": "dist/cjs/index.js",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "peerDependencies": {
66
66
  "@maplibre/maplibre-gl-geocoder": "^1.9.4",
67
- "maplibre-gl": "^5.0.0"
67
+ "maplibre-gl": "^6.4.1"
68
68
  },
69
69
  "peerDependenciesMeta": {
70
70
  "@maplibre/maplibre-gl-geocoder": {
@@ -82,7 +82,7 @@
82
82
  "@vitest/coverage-v8": "^3.0.0",
83
83
  "eslint": "^10.1.0",
84
84
  "husky": "^9.0.0",
85
- "maplibre-gl": "^5.0.0",
85
+ "maplibre-gl": "^6.4.1",
86
86
  "prettier": "^3.8.1",
87
87
  "prettier-plugin-organize-imports": "^4.3.0",
88
88
  "typescript": "^5.0.0",