fix: comply with OpenStreetMap tile and Nominatim usage policies - #118
Open
marcopixel wants to merge 2 commits into
Open
marcopixel wants to merge 2 commits into
marcopixel wants to merge 2 commits into
Conversation
Prevent tile requests from being blocked due to restrictive Referrer-Policy by setting `strict-origin-when-cross-origin` on the tile layer. This is the recommended way by OSM (https://wiki.openstreetmap.org/wiki/Referer). Comply with OpenStreetMap Nominatim request limits by serializing and caching geocoding requests on the client.
- Handle empty geocoding responses in geo/abstract.js and return address_not_found. - Ignore unsuccessful reverse geocoding responses instead of showing an undefined tooltip. - Destroy the existing Leaflet map before rebuilding the container to prevent orphaned maps and tile layers.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes in this pull request
This PR addresses three related issues in the OpenStreetMap/Leaflet integration:
Tile requests: explicit
Referrer-PolicyThe
L.tileLayer(...)configuration ingeo/abstract.jsdid not specify areferrerPolicy. As a result, theReferersent to the OSM tile server depended on theReferrer-Policyheader configured by the web server serving the admin bundle, or on the browser default if no header was set.This is easily visible inside the Admin UI by seeing this error message instead of map tiles:
The OSM wiki's Referer policy says tile requests without a
Refererget blocked, and listsstrict-origin-when-cross-originas an accepted policy. Leaflet itself applied the same fix upstream in Leaflet/Leaflet#9897.Fix:
Set
referrerPolicy: 'strict-origin-when-cross-origin'explicitly on the tile layer. This ensures consistent behaviour regardless of the nginx/Apache configuration of the installation.Geocoding: rate limiting and caching
The Nominatim usage policy limits clients to 1 request per second and requires applications to cache results.
Previously,
geocodeandreverseGeocodecalledsendRequestdirectly without any shared rate limiting or caching. This could result in multiple independent requests when several geo fields were present on a page.geopointcould also trigger reverse geocoding during every render and marker movement, while identical queries were never cached.Fix:
opendxp.helpers.geocodingRequestas a shared geocoding helper.geopoint.jsnow performs geocoding when the marker is clicked instead of during rendering.Both
geocodeandreverseGeocodenow use the shared helper.Leaflet map re-initialization
Handling empty geocoding results also exposed an existing Leaflet issue when performing a new search.
If a map already exists on the container, calling
L.map(...)again throws an error because Leaflet does not allow a second map instance to be initialized on the same container.Fix:
getLeafletMap()now removes the existingthis.leafletMapinstance before creating a new map.