Skip to content

Commit aaaf0d2

Browse files
feat(widgets): GeocoderWidget and experimental Geocoders (#9610)
1 parent 0dc3524 commit aaaf0d2

File tree

17 files changed

+752
-381
lines changed

17 files changed

+752
-381
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# GeocoderWidget
2+
3+
The GeocoderWidget helps the user find positions on the map.
4+
5+
This widget provides an input box for entering an address or a pair of coordinates.
6+
7+
The user types an address or coordinates into the text field and press **Go** to move the map. The most recent addresses that have been successfully located are presented in a drop-down menu.
8+
9+
Addresses that return a valid location are stored in browser local storage (up to five entries). They will appear in the drop-down for quick re-use during later visits.
10+
11+
## Usage
12+
13+
```ts
14+
import {GeocoderWidget} from '@deck.gl/widgets';
15+
import {Deck} from '@deck.gl/core';
16+
17+
new Deck({
18+
widgets: [new GeocoderWidget()]
19+
});
20+
```
21+
22+
## Props
23+
24+
The `GeocoderWidget` shares the base properties listed on the [widget overview page](./overview.md). Additional options are listed below.
25+
26+
#### `geocoder` (string, optional) {#geocoder}
27+
28+
Default: `'coordinates'`
29+
30+
Which geocoding service to use. Supported values are `'coordinates'`, `'google'`, `'mapbox'`, `'opencage'`, or `'custom'`.
31+
32+
#### `apiKey` (string, optional) {#apiKey}
33+
34+
Required if `geocoder` is set to a third party provider. For quick testing, applications can use the `coordinates` geocode does not require an api key.
35+
36+
#### `customGeocoder` (optional) {#customGeocoder}
37+
38+
Only used when `geocoder` is `'custom'`. A function that receives the entered text and an API key, and resolves to a `{longitude, latitude}` object when successful.
39+
40+
#### `_geolocation` (optional) {#geolocation}
41+
42+
In addition to addresses / coordinates, one position of obvious interest is the user's own current position. This experimental option adds a `current` menu item that calls the browser's geolocation API and navigates to the user's current position. Note that this requires the user to enable geolocation in the browser.
43+
44+
If `props._geolocation` **Current position** from the drop-down uses `navigator.geolocation` to center the map. The option is hidden if the browser does not provide the Geolocation API or the user denies access.
45+

docs/api-reference/widgets/geolocate-widget.md

Lines changed: 0 additions & 59 deletions
This file was deleted.

docs/api-reference/widgets/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This module contains the following widgets:
1414

1515
- [CompassWidget](./compass-widget.md)
1616
<!-- - [ScaleWidget](./scale-widget.md) -->
17-
<!-- - [GeolocateWidget](./geolocate-widget.md) -->
17+
<!-- - [GeocoderWidget](./geocoder-widget.md) -->
1818

1919
### Utility Widgets
2020

docs/table-of-contents.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,19 @@
315315
"items": [
316316
"api-reference/widgets/overview",
317317
"api-reference/widgets/styling",
318-
"api-reference/widgets/zoom-widget",
319318
"api-reference/widgets/compass-widget",
319+
"api-reference/widgets/fps-widget",
320320
"api-reference/widgets/fullscreen-widget",
321+
"api-reference/widgets/gimbal-widget",
322+
"api-reference/widgets/info-widget",
323+
"api-reference/widgets/loading-widget",
321324
"api-reference/widgets/reset-view-widget",
325+
"api-reference/widgets/scale-widget",
322326
"api-reference/widgets/screenshot-widget",
323-
"api-reference/widgets/fps-widget",
324-
"api-reference/widgets/loading-widget",
327+
"api-reference/widgets/splitter-widget",
325328
"api-reference/widgets/theme-widget",
326-
"api-reference/widgets/info-widget"
329+
"api-reference/widgets/timeline-widget",
330+
"api-reference/widgets/zoom-widget"
327331
]
328332
}
329333
]

docs/whats-new.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ Target release date: Q2, 2025
1212

1313
- [ResetViewWidget](./api-reference/widgets/reset-view-widget.md)
1414
- [ScaleWidget](./api-reference/widgets/scale-widget.md)
15-
- [GeolocateWidget](./api-reference/widgets/geolocate-widget.md)
15+
- [GeocoderWidget](./api-reference/widgets/geocoder-widget.md)
1616
- [ScreenshotWidget](./api-reference/widgets/screenshot-widget.md)
1717
- [LoadingWidget](./api-reference/widgets/loading-widget.md)
1818
- [ThemeWidget](./api-reference/widgets/theme-widget.md)
1919
- [InfoWidget](./api-reference/widgets/info-widget.md)
2020
- [SplitterWidget](./api-reference/widgets/splitter-widget.md)
2121

22-
Also, pre-wrapped React components for the new deck.gl widgets are available via the [`@deck.gl/react`](./api-reference/react/overview.md) package.
22+
Pre-wrapped React components for the new deck.gl widgets are available via the [`@deck.gl/react`](./api-reference/react/overview.md) package.
2323

2424
### Core
2525

modules/react/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export {default} from './deckgl';
99
export {CompassWidget} from './widgets/compass-widget';
1010
export {FullscreenWidget} from './widgets/fullscreen-widget';
1111
export {ZoomWidget} from './widgets/zoom-widget';
12-
export {GeolocateWidget as _GeolocateWidget} from './widgets/geolocate-widget';
12+
export {GeocoderWidget as _GeocoderWidget} from './widgets/geocoder-widget';
1313
export {InfoWidget as _InfoWidget} from './widgets/info-widget';
1414
export {ContextMenuWidget as _ContextMenuWidget} from './widgets/context-menu-widget';
1515
export {LoadingWidget as _LoadingWidget} from './widgets/loading-widget';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// deck.gl
2+
// SPDX-License-Identifier: MIT
3+
// Copyright (c) vis.gl contributors
4+
5+
import {_GeocoderWidget} from '@deck.gl/widgets';
6+
import type {GeocoderWidgetProps} from '@deck.gl/widgets';
7+
import {useWidget} from '../utils/use-widget';
8+
9+
/**
10+
* React wrapper for the GeocoderWidget.
11+
*/
12+
export const GeocoderWidget = (props: GeocoderWidgetProps = {}) => {
13+
useWidget(_GeocoderWidget, props);
14+
return null;
15+
};

modules/react/src/widgets/geolocate-widget.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)