From 2208a6c67dc1c32b05e180f3dfbf67f8dc396610 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 30 Jun 2023 16:26:50 +0200 Subject: [PATCH] WIP: OpenStreetMap dedicated popup template --- umap/static/umap/js/umap.forms.js | 1 + umap/static/umap/js/umap.popup.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/umap/static/umap/js/umap.forms.js b/umap/static/umap/js/umap.forms.js index b3970973..1aabfec5 100644 --- a/umap/static/umap/js/umap.forms.js +++ b/umap/static/umap/js/umap.forms.js @@ -372,6 +372,7 @@ L.FormBuilder.PopupContent = L.FormBuilder.Select.extend({ ['Table', L._('Table')], ['GeoRSSImage', L._('GeoRSS (title + image)')], ['GeoRSSLink', L._('GeoRSS (only link)')], + ['OSM', L._('OpenStreetMap')], ], }) diff --git a/umap/static/umap/js/umap.popup.js b/umap/static/umap/js/umap.popup.js index 6bccceed..e6b1d50f 100644 --- a/umap/static/umap/js/umap.popup.js +++ b/umap/static/umap/js/umap.popup.js @@ -251,3 +251,24 @@ L.U.PopupTemplate.GeoRSSLink = L.U.PopupTemplate.Default.extend({ return a }, }) + +L.U.PopupTemplate.OSM = L.U.PopupTemplate.Default.extend({ + options: { + className: 'umap-openstreetmap', + }, + + getName: function () { + const props = this.feature.properties + if (L.locale && props[`name:${L.locale}`]) return props[`name:${L.locale}`]; + return props.name + }, + + renderBody: function () { + const props = this.feature.properties + let kind = props.shop || props.amenity || props.craft + const container = L.DomUtil.add('div') + const kindEl = L.DomUtil.add('h4', '', container, kind) + L.DomUtil.add('h3', 'popup-title', container, this.getName()) + return container + }, +})