Merge pull request #1756 from umap-project/edit-in-osm-in-contextmenu

feat: add link in contextmenu to edit map in OSM
This commit is contained in:
Yohan Boniface 2024-04-17 15:04:09 +02:00 committed by GitHub
commit 67bc181098
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View file

@ -239,6 +239,7 @@ UMAP_EXTRA_URLS = {
"routing": "http://www.openstreetmap.org/directions?engine=osrm_car&route={lat},{lng}&locale={locale}#map={zoom}/{lat}/{lng}", # noqa "routing": "http://www.openstreetmap.org/directions?engine=osrm_car&route={lat},{lng}&locale={locale}#map={zoom}/{lat}/{lng}", # noqa
"ajax_proxy": "/ajax-proxy/?url={url}&ttl={ttl}", "ajax_proxy": "/ajax-proxy/?url={url}&ttl={ttl}",
"search": "https://photon.komoot.io/api/?", "search": "https://photon.komoot.io/api/?",
"edit_in_osm": "https://www.openstreetmap.org/edit#map={zoom}/{lat}/{lng}",
} }
UMAP_KEEP_VERSIONS = env.int("UMAP_KEEP_VERSIONS", default=10) UMAP_KEEP_VERSIONS = env.int("UMAP_KEEP_VERSIONS", default=10)
SITE_URL = env("SITE_URL", default="http://umap.org") SITE_URL = env("SITE_URL", default="http://umap.org")

View file

@ -1769,9 +1769,24 @@ U.Map = L.Map.extend({
callback: this.openExternalRouting, callback: this.openExternalRouting,
}) })
} }
if (this.options.urls.edit_in_osm) {
items.push('-', {
text: L._('Edit in OpenStreetMap'),
callback: this.editInOSM,
})
}
this.options.contextmenuItems = items this.options.contextmenuItems = items
}, },
editInOSM: function (e) {
const url = this.urls.get('edit_in_osm', {
lat: e.latlng.lat,
lng: e.latlng.lng,
zoom: Math.max(this.getZoom(), 16),
})
if (url) window.open(url)
},
openExternalRouting: function (e) { openExternalRouting: function (e) {
const url = this.urls.get('routing', { const url = this.urls.get('routing', {
lat: e.latlng.lat, lat: e.latlng.lat,