maplibre-gl-basemap-control 0.2.2 → 0.4.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
@@ -8,7 +8,7 @@ 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 no-key catalog for common public basemaps
11
+ - Built-in catalog for common public basemaps, MapTiler styles, Amazon Location styles, and Mapbox styles
12
12
  - Custom basemap and provider definitions
13
13
  - MapLibre `IControl` implementation
14
14
  - React wrapper and state hook
@@ -131,6 +131,46 @@ const control = new BasemapControl({
131
131
 
132
132
  Set `includeDefaultBasemaps: false` to use only your supplied catalog.
133
133
 
134
+ ## Keyed Provider Styles
135
+
136
+ The built-in catalog includes MapTiler styles such as Streets, Base, Dataviz, Outdoor, Topo,
137
+ Satellite Hybrid, Satellite Plain, Aquarelle, Backdrop, Landscape, Ocean, Toner, OpenStreetMap, and
138
+ Winter. It also includes Amazon Location styles: Standard, Monochrome, Hybrid, and Satellite.
139
+ Mapbox styles include Streets, Outdoors, Light, Dark, Satellite, Satellite Streets, Navigation Day,
140
+ and Navigation Night.
141
+
142
+ MapTiler and Amazon Location styles require API keys. Mapbox styles require an access token. Users
143
+ can enter keys and tokens in the collapsible provider settings section in the control panel, or you
144
+ can provide them when creating the control.
145
+
146
+ ```typescript
147
+ const control = new BasemapControl({
148
+ defaultBasemapId: 'maptiler-streets',
149
+ mapTilerApiKey: 'YOUR_MAPTILER_API_KEY',
150
+ amazonApiKey: 'YOUR_AMAZON_LOCATION_API_KEY',
151
+ awsRegion: 'us-east-1',
152
+ mapboxAccessToken: 'YOUR_MAPBOX_ACCESS_TOKEN',
153
+ });
154
+ ```
155
+
156
+ The default MapTiler style URLs follow this form:
157
+
158
+ ```text
159
+ https://api.maptiler.com/maps/{mapId}/style.json?key={api-key}
160
+ ```
161
+
162
+ Amazon Location style URLs follow this form:
163
+
164
+ ```text
165
+ https://maps.geo.{aws-region}.amazonaws.com/v2/styles/{mapStyle}/descriptor?key={api-key}
166
+ ```
167
+
168
+ Mapbox style URLs follow this form:
169
+
170
+ ```text
171
+ https://api.mapbox.com/styles/v1/mapbox/{styleId}?access_token={api-key}
172
+ ```
173
+
134
174
  ## API
135
175
 
136
176
  ### BasemapControl Options
@@ -142,15 +182,58 @@ Set `includeDefaultBasemaps: false` to use only your supplied catalog.
142
182
  | `title` | `string` | `'Basemaps'` | Panel title and button label |
143
183
  | `panelWidth` | `number` | `340` | Floating panel width in pixels |
144
184
  | `className` | `string` | `''` | Extra class for the control button container |
185
+ | `mapTilerApiKey` | `string` | `undefined` | Initial MapTiler API key for built-in MapTiler styles |
186
+ | `amazonApiKey` | `string` | `undefined` | Initial Amazon Location API key for built-in Amazon styles |
187
+ | `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 |
145
189
  | `basemaps` | `BasemapDefinition[]` | `[]` | Custom basemaps to add or use |
146
190
  | `providers` | `BasemapProvider[]` | `[]` | Custom provider labels |
147
191
  | `includeDefaultBasemaps` | `boolean` | `true` | Include the built-in public catalog |
148
192
  | `defaultBasemapId` | `string` | `undefined` | Basemap to apply after the control is added |
193
+ | `allowMultiple` | `boolean` | `false` | Stack raster basemaps instead of replacing the active one |
194
+ | `showMultipleToggle` | `boolean` | `true` | Show the in-panel toggle that switches between adding and replacing |
195
+ | `resizable` | `boolean` | `true` | Allow resizing the panel by dragging its bottom-left or bottom-right corner |
196
+
197
+ ### Multiple Basemaps
198
+
199
+ By default, selecting a basemap replaces the active one. Set `allowMultiple: true`
200
+ to stack raster basemaps instead: each click adds the selected raster basemap as
201
+ an additional overlay, and clicking an already-active raster basemap removes it.
202
+ This lets a project hold several raster basemaps at once and switch between them by
203
+ toggling the entries in the panel.
204
+
205
+ ```typescript
206
+ const control = new BasemapControl({
207
+ allowMultiple: true,
208
+ });
209
+ ```
210
+
211
+ The panel also shows an **Add basemaps** toggle so users can switch between adding
212
+ and replacing at runtime. Hide it with `showMultipleToggle: false`.
213
+
214
+ ### Resizable Panel
215
+
216
+ The panel can be resized by dragging either of its bottom corners (bottom-left or
217
+ bottom-right). The resized width and height are reflected in `state.panelWidth` and
218
+ `state.panelHeight`. Set `resizable: false` to disable the handles.
219
+
220
+ Style basemaps cannot stack because they replace the entire map style, so selecting
221
+ a style basemap always replaces the active basemaps (and clears any stacked raster
222
+ overlays). Use the `before_id` input to control where each raster basemap is
223
+ inserted relative to existing layers.
149
224
 
150
225
  ### Methods
151
226
 
152
227
  - `setBasemap(id)` - Apply a basemap and remove the previous plugin-managed basemap
153
- - `getActiveBasemap()` - Return the current basemap definition
228
+ - `addBasemap(id)` - Add a raster basemap as an additional overlay (style basemaps replace instead)
229
+ - `removeBasemap(id)` - Remove a previously added managed raster basemap
230
+ - `toggleBasemap(id)` - Add the raster basemap if inactive, otherwise remove it
231
+ - `isBasemapActive(id)` - Whether the basemap is currently active
232
+ - `setMapTilerApiKey(apiKey)` - Set or update the MapTiler API key used by MapTiler styles
233
+ - `setAmazonCredentials(apiKey, awsRegion)` - Set or update Amazon Location credentials
234
+ - `setMapboxAccessToken(accessToken)` - Set or update the Mapbox access token
235
+ - `getActiveBasemap()` - Return the most recently selected basemap definition
236
+ - `getActiveBasemaps()` - Return all currently active basemap definitions
154
237
  - `getBasemaps()` - Return the catalog
155
238
  - `setBasemaps(basemaps)` - Replace the catalog
156
239
  - `toggle()`, `expand()`, `collapse()` - Control panel visibility
@@ -164,7 +247,8 @@ before that layer.
164
247
 
165
248
  ### Events
166
249
 
167
- - `basemapchange`
250
+ - `basemapchange` (includes a `mode` of `'replace'` or `'add'`)
251
+ - `basemapremove`
168
252
  - `error`
169
253
  - `collapse`
170
254
  - `expand`