maplibre-gl-basemap-control 0.12.0 → 0.14.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 +129 -9
- package/dist/{BasemapControl-DcXJBZtu.js → BasemapControl-CKgYscxI.js} +683 -83
- package/dist/BasemapControl-CKgYscxI.js.map +1 -0
- package/dist/{BasemapControl-BbsxylnF.cjs → BasemapControl-DgR3c4ci.cjs} +683 -83
- package/dist/BasemapControl-DgR3c4ci.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.mjs +1 -1
- package/dist/types/lib/core/BasemapControl.d.ts +10 -0
- package/dist/types/lib/core/BasemapControl.d.ts.map +1 -1
- package/dist/types/lib/core/catalog.d.ts.map +1 -1
- package/dist/types/lib/core/types.d.ts +26 -6
- package/dist/types/lib/core/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/BasemapControl-BbsxylnF.cjs.map +0 -1
- package/dist/BasemapControl-DcXJBZtu.js.map +0 -1
package/README.md
CHANGED
|
@@ -8,7 +8,8 @@ A MapLibre GL JS control for searching and switching public basemaps. It keeps t
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
10
10
|
- Search-first basemap picker inspired by QuickMapServices
|
|
11
|
-
- Built-in catalog for common public basemaps, MapTiler styles, Amazon Location styles, and
|
|
11
|
+
- Built-in catalog for common public basemaps, MapTiler styles, Amazon Location styles, Mapbox styles, Maptoolkit styles, Protomaps styles, and Stadia Maps basemaps
|
|
12
|
+
- Tianditu, Amap, and Tencent basemaps, served from inside mainland China
|
|
12
13
|
- Stackable traffic overlays for TomTom, HERE, Mapbox, and Google
|
|
13
14
|
- Custom basemap and provider definitions
|
|
14
15
|
- MapLibre `IControl` implementation
|
|
@@ -138,11 +139,12 @@ The built-in catalog includes MapTiler styles such as Streets, Base, Dataviz, Ou
|
|
|
138
139
|
Satellite Hybrid, Satellite Plain, Aquarelle, Backdrop, Landscape, Ocean, Toner, OpenStreetMap, and
|
|
139
140
|
Winter. It also includes Amazon Location styles: Standard, Monochrome, Hybrid, and Satellite.
|
|
140
141
|
Mapbox styles include Streets, Outdoors, Light, Dark, Satellite, Satellite Streets, Navigation Day,
|
|
141
|
-
and Navigation Night.
|
|
142
|
+
and Navigation Night. Protomaps styles include Light, Dark, White, Black, Grayscale, and Contrast.
|
|
142
143
|
|
|
143
|
-
MapTiler
|
|
144
|
-
can enter keys and tokens in the dedicated API keys view, opened from the key button in
|
|
145
|
-
header, or you can provide them when creating the control. When a basemap is selected
|
|
144
|
+
MapTiler, Amazon Location, and Protomaps styles require API keys. Mapbox styles require an access
|
|
145
|
+
token. Users can enter keys and tokens in the dedicated API keys view, opened from the key button in
|
|
146
|
+
the panel header, or you can provide them when creating the control. When a basemap is selected
|
|
147
|
+
before its key
|
|
146
148
|
is set, the control surfaces the error and the matching credential field inline, before any
|
|
147
149
|
destructive style change, so the missing key can be entered and the basemap retried with Enter.
|
|
148
150
|
|
|
@@ -153,6 +155,9 @@ const control = new BasemapControl({
|
|
|
153
155
|
amazonApiKey: 'YOUR_AMAZON_LOCATION_API_KEY',
|
|
154
156
|
awsRegion: 'us-east-1',
|
|
155
157
|
mapboxAccessToken: 'YOUR_MAPBOX_ACCESS_TOKEN',
|
|
158
|
+
protomapsApiKey: 'YOUR_PROTOMAPS_API_KEY',
|
|
159
|
+
stadiaApiKey: 'YOUR_STADIA_MAPS_API_KEY',
|
|
160
|
+
tiandituApiKey: 'YOUR_TIANDITU_API_KEY',
|
|
156
161
|
});
|
|
157
162
|
```
|
|
158
163
|
|
|
@@ -174,6 +179,87 @@ Mapbox style URLs follow this form:
|
|
|
174
179
|
https://api.mapbox.com/styles/v1/mapbox/{styleId}?access_token={api-key}
|
|
175
180
|
```
|
|
176
181
|
|
|
182
|
+
Protomaps style URLs follow this form:
|
|
183
|
+
|
|
184
|
+
```text
|
|
185
|
+
https://api.protomaps.com/styles/v5/{styleId}/en.json?key={api-key}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Stadia Maps and Stamen
|
|
189
|
+
|
|
190
|
+
The catalog ships Stadia Maps' own styles (Alidade Smooth, Alidade Smooth Dark, Alidade Satellite,
|
|
191
|
+
Outdoors, OSM Bright) and the Stadia x Stamen classics (Toner, Toner Lite, Toner Background, Toner
|
|
192
|
+
Labels, Terrain, Terrain Background, Terrain Labels, Watercolor). Stadia has hosted the Stamen
|
|
193
|
+
tilesets since 2023.
|
|
194
|
+
|
|
195
|
+
These are raster tiles that take the key directly on each tile URL:
|
|
196
|
+
|
|
197
|
+
```text
|
|
198
|
+
https://tiles.stadiamaps.com/tiles/{slug}/{z}/{x}/{y}.png?api_key={api-key}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Alidade Satellite and Stamen Watercolor are served as `.jpg` instead. The `_labels` layers are
|
|
202
|
+
transparent overlays, so pair them with `allowMultiple: true` to stack them over a base layer.
|
|
203
|
+
|
|
204
|
+
> **Note.** Stadia also supports keyless access from allowlisted domains (localhost included), but
|
|
205
|
+
> this control always sends `api_key`, so a key is required here. Set `stadiaApiKey` or enter it in
|
|
206
|
+
> the panel's API keys view.
|
|
207
|
+
|
|
208
|
+
### China Basemaps
|
|
209
|
+
|
|
210
|
+
Most of the catalog is hosted outside mainland China with no presence inside it, so for users there
|
|
211
|
+
OpenStreetMap, OpenFreeMap, Protomaps, Carto, Google, and Mapbox range from slow to unreachable. The
|
|
212
|
+
catalog ships three providers that are served from inside China:
|
|
213
|
+
|
|
214
|
+
| Basemap id | Provider | Datum | Credential |
|
|
215
|
+
|------------|----------|-------|------------|
|
|
216
|
+
| `tianditu-vector`, `tianditu-imagery`, `tianditu-terrain` and their `-labels` overlays | Tianditu (天地图) | CGCS2000 | `tiandituApiKey` |
|
|
217
|
+
| `amap-street`, `amap-satellite`, `amap-labels` | Amap (高德地图) | GCJ-02 | none |
|
|
218
|
+
| `tencent-street`, `tencent-dark` | Tencent Maps (腾讯地图) | GCJ-02 | none |
|
|
219
|
+
|
|
220
|
+
They are searchable by their Chinese names as well as their English ones, so typing `天地图`, `高德`,
|
|
221
|
+
or `腾讯` into the panel's filter finds them.
|
|
222
|
+
|
|
223
|
+
> **The datum matters more than the speed.** Chinese law requires public map services to publish in
|
|
224
|
+
> GCJ-02, an offset datum that displaces features by roughly 100-700 m from WGS84. Neither this
|
|
225
|
+
> control nor MapLibre applies the shift, so WGS84 data laid over Amap or Tencent will visibly
|
|
226
|
+
> misalign. **Tianditu is the exception**: it publishes in CGCS2000, which is close enough to WGS84
|
|
227
|
+
> for web mapping, so ordinary data overlays correctly. Prefer Tianditu whenever you are also
|
|
228
|
+
> rendering your own data; reach for Amap or Tencent when the basemap is the whole point, or convert
|
|
229
|
+
> your data to GCJ-02 first.
|
|
230
|
+
|
|
231
|
+
Tianditu is China's official National Platform for Common Geospatial Information Services. Register
|
|
232
|
+
a free key at [console.tianditu.gov.cn](https://console.tianditu.gov.cn/api/key), then set
|
|
233
|
+
`tiandituApiKey` or enter it in the panel's API keys view. Its layers ride the `DataServer`
|
|
234
|
+
endpoint, the xyz-shaped form of its WMTS services:
|
|
235
|
+
|
|
236
|
+
```text
|
|
237
|
+
https://t{0-7}.tianditu.gov.cn/DataServer?T={layer}&x={x}&y={y}&l={z}&tk={api-key}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Tianditu splits every basemap from its labels, so the `-labels` overlays are separate transparent
|
|
241
|
+
layers. Pair them with `allowMultiple: true` to stack them over their base:
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
const control = new BasemapControl({
|
|
245
|
+
allowMultiple: true,
|
|
246
|
+
tiandituApiKey: 'YOUR_TIANDITU_API_KEY',
|
|
247
|
+
defaultBasemapId: 'tianditu-vector',
|
|
248
|
+
});
|
|
249
|
+
await control.addBasemap('tianditu-vector-labels');
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
The same applies to `amap-labels`, a transparent roads-and-labels overlay meant to sit on top of
|
|
253
|
+
`amap-satellite`. Note that `tianditu-terrain` and `tianditu-terrain-labels` are only published to
|
|
254
|
+
zoom 14, where the vector and imagery layers reach 18, and Amap serves a "no imagery" placeholder
|
|
255
|
+
rather than a 404 past zoom 18, so `amap-satellite` caps there and lets MapLibre overzoom.
|
|
256
|
+
|
|
257
|
+
> **Terms of use.** Tianditu's key-based access is the sanctioned route and the one to build on. The
|
|
258
|
+
> Amap and Tencent tile endpoints are widely used but are not documented public APIs, and carry the
|
|
259
|
+
> same caveat as the keyless Google tiles below: fine for development and demos, but the operators
|
|
260
|
+
> may rate-limit, change, or block them at any time. Obtain a commercial key from the provider before
|
|
261
|
+
> shipping either one.
|
|
262
|
+
|
|
177
263
|
### Traffic Overlays
|
|
178
264
|
|
|
179
265
|
The catalog ships real-time traffic overlays in the `Traffic` category. They are
|
|
@@ -214,10 +300,18 @@ key must have the Map Tiles API enabled.
|
|
|
214
300
|
> few minutes to propagate). Make sure billing is enabled on the project too.
|
|
215
301
|
|
|
216
302
|
The same `googleMapsApiKey` also upgrades the base Google basemaps
|
|
217
|
-
(`google-maps`, `google-satellite`, `google-terrain`, `google-hybrid`).
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
303
|
+
(`google-maps`, `google-satellite`, `google-terrain`, `google-hybrid`). By
|
|
304
|
+
default these use the public keyless `mt1.google.com` xyz tiles, so they work out
|
|
305
|
+
of the box; when a key is set they load from the authorized Map Tiles API instead
|
|
306
|
+
(via a tile session, like Google Traffic).
|
|
307
|
+
|
|
308
|
+
In the catalog definition this is the split between `source.tiles` and
|
|
309
|
+
`source.sessionTiles`: `tiles` always holds the public keyless template, so
|
|
310
|
+
reading `source.tiles` without a key gives a directly usable URL, while
|
|
311
|
+
`sessionTiles` holds the Map Tiles API template (with its `{session}` and
|
|
312
|
+
`{api-key}` placeholders) that is only used once a key is configured. Basemaps
|
|
313
|
+
that cannot work keylessly, such as `google-traffic`, have no `sessionTiles` and
|
|
314
|
+
keep the session template in `tiles`.
|
|
221
315
|
|
|
222
316
|
> **Licensing caveat.** The keyless `mt1.google.com` tiles are Google Maps'
|
|
223
317
|
> internal endpoints. They are **not** covered by any public or open license, and
|
|
@@ -228,6 +322,26 @@ tiles so they keep working out of the box.
|
|
|
228
322
|
> so these basemaps use the authorized [Map Tiles API](https://developers.google.com/maps/documentation/tile)
|
|
229
323
|
> (which requires the Map Tiles API enabled and billing on your project).
|
|
230
324
|
|
|
325
|
+
## Maptoolkit Styles
|
|
326
|
+
|
|
327
|
+
The catalog ships the seven [Maptoolkit](https://www.maptoolkit.org) vector styles. They need no
|
|
328
|
+
API key and load straight from `https://styles.maptoolkit.org/{styleId}.json`:
|
|
329
|
+
|
|
330
|
+
| Basemap id | Style | Category |
|
|
331
|
+
|------------|-------|----------|
|
|
332
|
+
| `maptoolkit-summer` | `summer` | Outdoor |
|
|
333
|
+
| `maptoolkit-light` | `light` | Light |
|
|
334
|
+
| `maptoolkit-hiking` | `hiking` | Outdoor |
|
|
335
|
+
| `maptoolkit-cycling` | `cycling` | Cycling |
|
|
336
|
+
| `maptoolkit-winter` | `winter` | Outdoor |
|
|
337
|
+
| `maptoolkit-dark` | `dark` | Dark |
|
|
338
|
+
| `maptoolkit-street` | `street` | Street |
|
|
339
|
+
|
|
340
|
+
> **Attribution.** The Maptoolkit style JSONs carry no `attribution` on their sources, so the catalog
|
|
341
|
+
> supplies the required "© Maptoolkit © OSM" credit links. Maptoolkit additionally requires the
|
|
342
|
+
> Maptoolkit logo (at least 24px tall) to be visible and unobstructed on the map; add it to your own
|
|
343
|
+
> UI, since the control cannot render it for you.
|
|
344
|
+
|
|
231
345
|
## API
|
|
232
346
|
|
|
233
347
|
### BasemapControl Options
|
|
@@ -243,6 +357,9 @@ tiles so they keep working out of the box.
|
|
|
243
357
|
| `amazonApiKey` | `string` | `undefined` | Initial Amazon Location API key for built-in Amazon styles |
|
|
244
358
|
| `awsRegion` | `string` | `'us-east-1'` | AWS region for built-in Amazon Location styles |
|
|
245
359
|
| `mapboxAccessToken` | `string` | `undefined` | Initial Mapbox access token for built-in Mapbox styles and the Mapbox Traffic overlay |
|
|
360
|
+
| `protomapsApiKey` | `string` | `undefined` | Initial Protomaps API key for built-in Protomaps styles |
|
|
361
|
+
| `stadiaApiKey` | `string` | `undefined` | Initial Stadia Maps API key for built-in Stadia and Stadia x Stamen basemaps |
|
|
362
|
+
| `tiandituApiKey` | `string` | `undefined` | Initial Tianditu API key (`tk`) for the built-in Tianditu basemaps |
|
|
246
363
|
| `tomtomApiKey` | `string` | `undefined` | Initial TomTom API key for the TomTom Traffic overlays |
|
|
247
364
|
| `hereApiKey` | `string` | `undefined` | Initial HERE API key for the HERE Traffic overlay |
|
|
248
365
|
| `googleMapsApiKey` | `string` | `undefined` | Initial Google Maps API key (Map Tiles API) for the Google Traffic overlay and the base Google Maps/Satellite/Terrain/Hybrid basemaps (which fall back to keyless tiles without a key) |
|
|
@@ -309,6 +426,9 @@ const control = new BasemapControl({
|
|
|
309
426
|
- `setMapTilerApiKey(apiKey)` - Set or update the MapTiler API key used by MapTiler styles
|
|
310
427
|
- `setAmazonCredentials(apiKey, awsRegion)` - Set or update Amazon Location credentials
|
|
311
428
|
- `setMapboxAccessToken(accessToken)` - Set or update the Mapbox access token
|
|
429
|
+
- `setProtomapsApiKey(apiKey)` - Set or update the Protomaps API key used by Protomaps styles
|
|
430
|
+
- `setStadiaApiKey(apiKey)` - Set or update the Stadia Maps API key used by Stadia basemaps
|
|
431
|
+
- `setTiandituApiKey(apiKey)` - Set or update the Tianditu API key used by Tianditu basemaps
|
|
312
432
|
- `setTomTomApiKey(apiKey)` - Set or update the TomTom API key used by TomTom Traffic overlays
|
|
313
433
|
- `setHereApiKey(apiKey)` - Set or update the HERE API key used by the HERE Traffic overlay
|
|
314
434
|
- `setGoogleMapsApiKey(apiKey)` - Set or update the Google Maps API key used by the Google Traffic overlay and the base Google basemaps
|