maplibre-gl-basemap-control 0.4.1 → 0.6.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/README.md CHANGED
@@ -9,6 +9,7 @@ A MapLibre GL JS control for searching and switching public basemaps. It keeps t
9
9
 
10
10
  - Search-first basemap picker inspired by QuickMapServices
11
11
  - Built-in catalog for common public basemaps, MapTiler styles, Amazon Location styles, and Mapbox styles
12
+ - Stackable traffic overlays for TomTom, HERE, Mapbox, and Google
12
13
  - Custom basemap and provider definitions
13
14
  - MapLibre `IControl` implementation
14
15
  - React wrapper and state hook
@@ -171,6 +172,45 @@ Mapbox style URLs follow this form:
171
172
  https://api.mapbox.com/styles/v1/mapbox/{styleId}?access_token={api-key}
172
173
  ```
173
174
 
175
+ ### Traffic Overlays
176
+
177
+ The catalog ships real-time traffic overlays in the `Traffic` category. They are
178
+ stackable overlays rather than full basemaps, so enable `allowMultiple: true` (or
179
+ toggle "Add basemaps" in the panel) to lay them on top of any basemap. Click an
180
+ active traffic layer again to remove it.
181
+
182
+ | Basemap id | Provider | Credential |
183
+ |------------|----------|------------|
184
+ | `tomtom-traffic-flow-relative`, `tomtom-traffic-flow-absolute`, `tomtom-traffic-flow-relative-delay` | TomTom | `tomtomApiKey` |
185
+ | `here-traffic-flow` | HERE | `hereApiKey` |
186
+ | `mapbox-traffic` | Mapbox | `mapboxAccessToken` |
187
+ | `google-traffic` | Google | `googleMapsApiKey` |
188
+
189
+ ```typescript
190
+ const control = new BasemapControl({
191
+ allowMultiple: true,
192
+ tomtomApiKey: 'YOUR_TOMTOM_API_KEY',
193
+ hereApiKey: 'YOUR_HERE_API_KEY',
194
+ mapboxAccessToken: 'YOUR_MAPBOX_ACCESS_TOKEN',
195
+ googleMapsApiKey: 'YOUR_GOOGLE_MAPS_API_KEY',
196
+ });
197
+ ```
198
+
199
+ The TomTom and HERE overlays are transparent raster flow tiles; Mapbox Traffic is
200
+ a vector overlay colored by congestion level. Google Traffic uses the
201
+ [Map Tiles API](https://developers.google.com/maps/documentation/tile/session_tokens):
202
+ the control creates a tile session (with `layerTypes: ['layerTraffic']`) using your
203
+ key, caches the session token until it expires, then loads the traffic tiles. The
204
+ key must have the Map Tiles API enabled.
205
+
206
+ > **Troubleshooting `API_KEY_SERVICE_BLOCKED`** ("Requests to this API tile method
207
+ > ...Bootstrap are blocked"): this is a key restriction, not project API
208
+ > enablement. Enabling the Map Tiles API on the project is not enough if the key
209
+ > itself has an API allow-list. In Cloud Console go to **APIs & Services →
210
+ > Credentials → your key → API restrictions** and either choose "Don't restrict
211
+ > key" or add **Map Tiles API** to the allowed list, then save (changes can take a
212
+ > few minutes to propagate). Make sure billing is enabled on the project too.
213
+
174
214
  ## API
175
215
 
176
216
  ### BasemapControl Options
@@ -185,7 +225,10 @@ https://api.mapbox.com/styles/v1/mapbox/{styleId}?access_token={api-key}
185
225
  | `mapTilerApiKey` | `string` | `undefined` | Initial MapTiler API key for built-in MapTiler styles |
186
226
  | `amazonApiKey` | `string` | `undefined` | Initial Amazon Location API key for built-in Amazon styles |
187
227
  | `awsRegion` | `string` | `'us-east-1'` | AWS region for built-in Amazon Location styles |
188
- | `mapboxAccessToken` | `string` | `undefined` | Initial Mapbox access token for built-in Mapbox styles |
228
+ | `mapboxAccessToken` | `string` | `undefined` | Initial Mapbox access token for built-in Mapbox styles and the Mapbox Traffic overlay |
229
+ | `tomtomApiKey` | `string` | `undefined` | Initial TomTom API key for the TomTom Traffic overlays |
230
+ | `hereApiKey` | `string` | `undefined` | Initial HERE API key for the HERE Traffic overlay |
231
+ | `googleMapsApiKey` | `string` | `undefined` | Initial Google Maps API key (Map Tiles API) for the Google Traffic overlay |
189
232
  | `basemaps` | `BasemapDefinition[]` | `[]` | Custom basemaps to add or use |
190
233
  | `providers` | `BasemapProvider[]` | `[]` | Custom provider labels |
191
234
  | `includeDefaultBasemaps` | `boolean` | `true` | Include the built-in public catalog |
@@ -193,6 +236,7 @@ https://api.mapbox.com/styles/v1/mapbox/{styleId}?access_token={api-key}
193
236
  | `allowMultiple` | `boolean` | `false` | Stack raster basemaps instead of replacing the active one |
194
237
  | `showMultipleToggle` | `boolean` | `true` | Show the in-panel toggle that switches between adding and replacing |
195
238
  | `resizable` | `boolean` | `true` | Allow resizing the panel by dragging its bottom-left or bottom-right corner |
239
+ | `confirmStyleReplace` | `(confirmation) => boolean \| Promise<boolean>` | `undefined` | Confirm before a style basemap replaces stacked raster basemaps (only invoked in `allowMultiple` mode with at least one raster stacked); return `false` to cancel |
196
240
 
197
241
  ### Multiple Basemaps
198
242
 
@@ -222,6 +266,22 @@ a style basemap always replaces the active basemaps (and clears any stacked rast
222
266
  overlays). Use the `before_id` input to control where each raster basemap is
223
267
  inserted relative to existing layers.
224
268
 
269
+ Because that swap is destructive in stack mode, you can pass `confirmStyleReplace`
270
+ to confirm before the stacked rasters are discarded. It is only invoked in
271
+ `allowMultiple` mode when at least one raster basemap is currently stacked, and
272
+ receives the `{ basemap, replacedBasemapIds }` it is about to replace. Return (or
273
+ resolve to) `false` to cancel and keep the current basemaps.
274
+
275
+ ```typescript
276
+ const control = new BasemapControl({
277
+ allowMultiple: true,
278
+ confirmStyleReplace: ({ basemap, replacedBasemapIds }) =>
279
+ window.confirm(
280
+ `Switching to "${basemap.name}" will remove ${replacedBasemapIds.length} stacked basemap(s). Continue?`,
281
+ ),
282
+ });
283
+ ```
284
+
225
285
  ### Methods
226
286
 
227
287
  - `setBasemap(id)` - Apply a basemap and remove the previous plugin-managed basemap
@@ -232,6 +292,9 @@ inserted relative to existing layers.
232
292
  - `setMapTilerApiKey(apiKey)` - Set or update the MapTiler API key used by MapTiler styles
233
293
  - `setAmazonCredentials(apiKey, awsRegion)` - Set or update Amazon Location credentials
234
294
  - `setMapboxAccessToken(accessToken)` - Set or update the Mapbox access token
295
+ - `setTomTomApiKey(apiKey)` - Set or update the TomTom API key used by TomTom Traffic overlays
296
+ - `setHereApiKey(apiKey)` - Set or update the HERE API key used by the HERE Traffic overlay
297
+ - `setGoogleMapsApiKey(apiKey)` - Set or update the Google Maps API key used by the Google Traffic overlay
235
298
  - `getActiveBasemap()` - Return the most recently selected basemap definition
236
299
  - `getActiveBasemaps()` - Return all currently active basemap definitions
237
300
  - `getBasemaps()` - Return the catalog