Skip to content

Commit 92d5805

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 9344e76 commit 92d5805

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

scripts/replace.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ const fs = require('fs')
66
const path = require('path')
77

88
// Define filepaths
9+
const indexJsFile = path.join(__dirname, '..', 'src', 'index.js')
910
const leafletOptions = path.join(__dirname, '..', 'src', 'leaflet_options.js')
1011
const debug = path.join(__dirname, '..', 'debug', 'index.html')
1112

1213
// Read & Replace options
13-
for (const filepath of [leafletOptions, debug]) {
14+
for (const filepath of [indexJsFile, leafletOptions, debug]) {
1415
let options = fs.readFileSync(filepath, 'utf8')
1516

1617
// Define Environment variables
@@ -21,6 +22,7 @@ for (const filepath of [leafletOptions, debug]) {
2122
const LANGUAGE = process.env.OSRM_LANGUAGE || 'en'
2223
const DEFAULT_LAYER = process.env.OSRM_DEFAULT_LAYER || 'streets'
2324
const MAPBOX_TOKEN = process.env.OSRM_MAPBOX_TOKEN || 'pk.eyJ1IjoibXNsZWUiLCJhIjoiclpiTWV5SSJ9.P_h8r37vD8jpIH1A6i1VRg'
25+
const NOMINATIM_ENDPOINT = process.env.NOMINATIM_ENDPOINT || 'https://nominatim.openstreetmap.org/'
2426

2527
// Edit Leaflet Options
2628
if (BACKEND) options = options.replace(/http[s]?:\/\/router\.project-osrm\.org/, BACKEND)
@@ -42,6 +44,8 @@ for (const filepath of [leafletOptions, debug]) {
4244
else options = options.replace('38.8995,-77.0269', latlng)
4345
}
4446

47+
if (NOMINATIM_ENDPOINT) options = options.replace('https://nominatim.openstreetmap.org/', NOMINATIM_ENDPOINT)
48+
4549
// Save Leaflet Options
4650
fs.writeFileSync(filepath, options)
4751
}

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function makeIcon(i, n) {
9393
}
9494
}
9595
var plan = new ReversablePlan([], {
96-
geocoder: L.Control.Geocoder.nominatim(),
96+
geocoder: L.Control.Geocoder.nominatim({serviceUrl: 'https://nominatim.openstreetmap.org/'}),
9797
routeWhileDragging: true,
9898
createMarker: function(i, wp, n) {
9999
var options = {

0 commit comments

Comments
 (0)