Skip to content

Commit 090e00c

Browse files
committed
Make nominatim endpoint modifiable
Most of API endpoints can be modified via leaflet_options.js, which is mentioned in README as a target of manual modify. But nominatim endpoint cannot be modified by this way. As nominatim can be self-hosted, I think it should be modifiable in configuration.
1 parent 1771d15 commit 090e00c

4 files changed

Lines changed: 8 additions & 3 deletions

File tree

scripts/replace.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function applyReplacements(content, env) {
1212
const BACKEND = env.OSRM_BACKEND || 'https://router.project-osrm.org'
1313
const LANGUAGE = env.OSRM_LANGUAGE || 'en'
1414
const DEFAULT_LAYER = env.OSRM_DEFAULT_LAYER || 'streets'
15+
const NOMINATIM_ENDPOINT = env.NOMINATIM_ENDPOINT || 'https://nominatim.openstreetmap.org/'
1516

1617
let options = content
1718

@@ -34,6 +35,7 @@ function applyReplacements(content, env) {
3435
// Leaflet uses LatLng
3536
else options = options.replace('38.8995,-77.0269', latlng)
3637
}
38+
if (NOMINATIM_ENDPOINT) options = options.replace('https://nominatim.openstreetmap.org/', NOMINATIM_ENDPOINT)
3739

3840
return options
3941
}

src/geocoder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ function parseCoords(query) {
4141
// For non-coordinate input, falls through to Nominatim forward-geocode as normal.
4242
// Also bridges leaflet-control-geocoder's Promise API to the callback-based API
4343
// that leaflet-routing-machine's autocomplete expects.
44-
geocoder.coordPreserving = function() {
45-
var nominatim = L.Control.Geocoder.nominatim();
44+
geocoder.coordPreserving = function(nominatimUrl) {
45+
var nominatim = L.Control.Geocoder.nominatim({serviceUrl: nominatimUrl});
4646

4747
function withCallback(promise, cb, context) {
4848
return promise.then(function(results) {

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function makeIcon(i, n) {
9999
}
100100
}
101101
var plan = new ReversablePlan([], {
102-
geocoder: createGeocoder.coordPreserving(),
102+
geocoder: createGeocoder.coordPreserving(leafletOptions.nominatim.path),
103103
routeWhileDragging: true,
104104
createMarker: function(i, wp, n) {
105105
var options = {

src/leaflet_options.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,8 @@ module.exports = {
6565
three: satellite,
6666
four: osm,
6767
five: osm_de
68+
},
69+
nominatim: {
70+
path: 'https://nominatim.openstreetmap.org/'
6871
}
6972
};

0 commit comments

Comments
 (0)