diff --git a/docs/getting-started/config.md b/docs/getting-started/config.md index a9750b4..44486e9 100644 --- a/docs/getting-started/config.md +++ b/docs/getting-started/config.md @@ -179,9 +179,15 @@ return [ #### `disablePopulateMissingFieldData` _Default: `false`_ -Will disable the automatic population of missing field data. This can be useful +Will disable the automatic population of missing field data. This can be useful in preventing API spam when importing lots of map data. +#### `nominatimBaseUrl` +_Default: `'https://nominatim.openstreetmap.org'`_ + +The base URL for the Nominatim service. Override to use a self-hosted instance +or a proxy. + #### `geoLocationService` _Default: `GeoLocationService::None`_ diff --git a/src/models/Settings.php b/src/models/Settings.php index c36cb41..4faa147 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -58,6 +58,12 @@ class Settings extends Model */ public bool $disablePopulateMissingFieldData = false; + /** + * @var string The base URL for the Nominatim service. Override to use a + * self-hosted instance or a proxy. + */ + public string $nominatimBaseUrl = 'https://nominatim.openstreetmap.org'; + // Properties: w3w // ------------------------------------------------------------------------- diff --git a/src/services/GeoService.php b/src/services/GeoService.php index c83ad64..a9d7963 100644 --- a/src/services/GeoService.php +++ b/src/services/GeoService.php @@ -599,7 +599,7 @@ public static function latLngFromAddress (string $address, string $country = nul $address, $country ), GeoEnum::Nominatim => static::_latLngFromAddress_Nominatim( - $address, $country + $address, $country, $settings->nominatimBaseUrl ), default => throw new Exception( 'Unknown geo-coding service: ' . $settings->geoService @@ -638,7 +638,7 @@ public static function addressFromLatLng (float $lat, float $lng): ?array $lat, $lng ), GeoEnum::Nominatim => static::_addressFromLatLng_Nominatim( - $lat, $lng + $lat, $lng, $settings->nominatimBaseUrl ), default => throw new Exception( 'Unknown geo-coding service: ' . $settings->geoService @@ -783,9 +783,9 @@ private static function _latLngFromAddress_Mapbox ($token, $address, $country): ]; } - private static function _latLngFromAddress_Nominatim ($address, $country): ?array + private static function _latLngFromAddress_Nominatim ($address, $country, $baseUrl): ?array { - $url = 'https://nominatim.openstreetmap.org/search?format=jsonv2&limit=1'; + $url = $baseUrl . '/search?format=jsonv2&limit=1'; $url .= '&accept-language=' . Craft::$app->locale->getLanguageID(); $url .= '&q=' . rawurlencode($address); if ($country !== null) @@ -877,9 +877,9 @@ private static function _addressFromLatLng_Mapbox ($token, $lat, $lng): ?array ]; } - private static function _addressFromLatLng_Nominatim ($lat, $lng): ?array + private static function _addressFromLatLng_Nominatim ($lat, $lng, $baseUrl): ?array { - $url = 'https://nominatim.openstreetmap.org/reverse?format=jsonv2&limit=1&addressdetails=1'; + $url = $baseUrl . '/reverse?format=jsonv2&limit=1&addressdetails=1'; $url .= '&accept-language=' . Craft::$app->locale->getLanguageID(); $url .= '&lat=' . rawurlencode($lat) . '&lon=' . rawurldecode($lng);