mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 23:53:25 +00:00
use nominatim for geocoding
This commit is contained in:
@@ -108,15 +108,40 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (geocoder) {
|
if (geocoder) {
|
||||||
newMap.addControl(
|
let geocoder = new MapboxGeocoder({
|
||||||
new MapboxGeocoder({
|
mapboxgl: mapboxgl,
|
||||||
accessToken: mapboxgl.accessToken,
|
enableEventLogging: false,
|
||||||
mapboxgl: mapboxgl,
|
collapsed: true,
|
||||||
collapsed: true,
|
flyTo: fitBoundsOptions,
|
||||||
flyTo: fitBoundsOptions,
|
language,
|
||||||
language
|
localGeocoder: () => [],
|
||||||
})
|
localGeocoderOnly: true,
|
||||||
);
|
externalGeocoder: (query: string) =>
|
||||||
|
fetch(
|
||||||
|
`https://nominatim.openstreetmap.org/search?format=json&q=${query}&limit=5&accept-language=${language}`
|
||||||
|
)
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
return data.map((result: any) => {
|
||||||
|
return {
|
||||||
|
type: 'Feature',
|
||||||
|
geometry: {
|
||||||
|
type: 'Point',
|
||||||
|
coordinates: [result.lon, result.lat]
|
||||||
|
},
|
||||||
|
place_name: result.display_name
|
||||||
|
};
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
let onKeyDown = geocoder._onKeyDown;
|
||||||
|
geocoder._onKeyDown = (e: KeyboardEvent) => {
|
||||||
|
// Trigger search on Enter key only
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
onKeyDown.apply(geocoder, [{ target: geocoder._inputEl }]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
newMap.addControl(geocoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (geolocate) {
|
if (geolocate) {
|
||||||
|
Reference in New Issue
Block a user