-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CDC #121 - Adding geocoding capabilities to MapDraw component
- Loading branch information
dleadbetter
committed
Apr 10, 2024
1 parent
ea6ab01
commit 910d05f
Showing
7 changed files
with
157 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
}, | ||
"dependencies": { | ||
"@mapbox/mapbox-gl-draw": "^1.4.3", | ||
"@maptiler/geocoding-control": "^1.2.2", | ||
"@turf/turf": "^6.5.0", | ||
"mapbox-gl": "npm:[email protected]", | ||
"maplibre-gl": "^3.6.2", | ||
|
@@ -38,4 +39,4 @@ | |
"react-dom": "^18.2.0", | ||
"vite": "^5.1.4" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// @flow | ||
|
||
import { GeocodingControl as MapTilerGeocoding } from '@maptiler/geocoding-control/maplibregl'; | ||
import maplibregl from 'maplibre-gl'; | ||
import { forwardRef, useImperativeHandle } from 'react'; | ||
import { useControl, type ControlPosition } from 'react-map-gl'; | ||
|
||
type Props = { | ||
apiKey: string, | ||
onSelection: () => void, | ||
position?: ControlPosition | ||
}; | ||
|
||
const GeocodingControl = forwardRef(({ position, ...props }: Props, ref) => { | ||
/** | ||
* Creates the drawer ref using MapboxDraw. | ||
*/ | ||
const geocodingRef = useControl(() => { | ||
const control = new MapTilerGeocoding({ ...props, maplibregl }); | ||
control.addEventListener('pick', props.onSelection); | ||
|
||
return control; | ||
}, { position }); | ||
|
||
/** | ||
* Exposes the ref for the MapboxDraw object. | ||
*/ | ||
useImperativeHandle(ref, () => geocodingRef, [geocodingRef]); | ||
|
||
return null; | ||
}); | ||
|
||
export default GeocodingControl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
@import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css'; | ||
@import 'maplibre-gl/dist/maplibre-gl.css'; | ||
@import '@maptiler/geocoding-control/style.css'; | ||
@import 'maplibre-gl/dist/maplibre-gl.css'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2089,6 +2089,13 @@ | |
rw "^1.3.3" | ||
sort-object "^3.0.3" | ||
|
||
"@maptiler/geocoding-control@^1.2.2": | ||
version "1.2.2" | ||
resolved "https://registry.yarnpkg.com/@maptiler/geocoding-control/-/geocoding-control-1.2.2.tgz#319b1b2abaa2b4de6cc91e1a2990e58b18557960" | ||
integrity sha512-w0JH0MOWN/z4l5t89LPinn9P9CGUg+L9R0WslXSVFP8gX9SYUMaqmGB28txXlSJsckA5/oyYfOe5UOBgXK7sbw== | ||
dependencies: | ||
geo-coordinates-parser "^1.6.4" | ||
|
||
"@mdx-js/react@^2.1.5": | ||
version "2.3.0" | ||
resolved "https://registry.yarnpkg.com/@mdx-js/react/-/react-2.3.0.tgz#4208bd6d70f0d0831def28ef28c26149b03180b3" | ||
|
@@ -9056,6 +9063,11 @@ gensync@^1.0.0-beta.2: | |
resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0" | ||
integrity sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg== | ||
|
||
geo-coordinates-parser@^1.6.4: | ||
version "1.6.6" | ||
resolved "https://registry.yarnpkg.com/geo-coordinates-parser/-/geo-coordinates-parser-1.6.6.tgz#856ea86639b5fb4ea20208418b7cfcf465d55fc2" | ||
integrity sha512-+zmVBzbTrC/LyFUMcYrvUqi+XUYkJ6bWqPHywfCsMYLa9BEGHEzLsBgltwXS9Ul5oJcFbrdt2y/CjjxNtTTQ+w== | ||
|
||
[email protected]: | ||
version "0.1.6" | ||
resolved "https://registry.yarnpkg.com/geojson-equality/-/geojson-equality-0.1.6.tgz#a171374ef043e5d4797995840bae4648e0752d72" | ||
|