From f68d32b1f2b5ea34202c2bd62d7a91770942b7f0 Mon Sep 17 00:00:00 2001 From: Marcus Jaschen Date: Thu, 30 Jun 2022 11:15:01 +0200 Subject: [PATCH] Improves rendering of Overpass data; add OSM link to Overpass popups (see #467) (#574) - add some styling to the Overpass data table (alternating row colors; text alignment) - add link to OSM object below the Overpass data table - add 4 new entries in `en.json` --- css/style.css | 40 +++++++++++++++++++++++++++++++- js/LayersConfig.js | 57 +++++++++++++++++++++++++++++++++++++++++++++- locales/en.json | 4 ++++ 3 files changed, 99 insertions(+), 2 deletions(-) diff --git a/css/style.css b/css/style.css index 4614093..367b101 100644 --- a/css/style.css +++ b/css/style.css @@ -50,10 +50,48 @@ table.dataTable { font-size: 1.2rem; } -.overpass-tags th { +.overpass-tags th, +.overpass-tags td { + padding: 0.25em 0.5em; vertical-align: top; } +.overpass-tags thead { + text-transform: uppercase; + color: #666; +} + +.overpass-tags thead tr { + background-color: #ddd; +} + +.overpass-tags thead th.overpass-label-key { + text-align: right; +} + +.overpass-tags tbody tr:nth-child(even) { + background-color: #eee; +} + +.overpass-tags tbody tr:last-child { + border-bottom: 1px solid #eee; +} + +.overpass-tags tbody th { + text-align: right; + font-weight: normal; +} + +.overpass-osm-link { + margin-top: 0.5rem; + text-align: right; + font-size: 80%; +} +.overpass-osm-link::before { + content: '🔎'; + margin-right: 0.25em; +} + .overpass-layer-icon .sign > * { position: absolute; top: -34px; diff --git a/js/LayersConfig.js b/js/LayersConfig.js index 4eb6a20..142bfe5 100644 --- a/js/LayersConfig.js +++ b/js/LayersConfig.js @@ -216,7 +216,7 @@ BR.LayersConfig = L.Class.extend({ minZoom: 12, feature: { title: '{{ tags.name }}', - body: '{% for k, v in tags %}{% if k[:5] != "addr:" %}{% endif %}{% endfor %}
{{ k }}{% if k matches "/email/" %}{{ v }}{% elseif v matches "/^http/" %}{{ v }}{% elseif v matches "/^www/" %}{{ v }}{% else %}{{ v }}{% endif %}
', + body: this.renderOverpassPopupBody, markerSymbol: '', markerSign, @@ -240,6 +240,61 @@ BR.LayersConfig = L.Class.extend({ ); }, + renderOverpassPopupBody: function (overpassData) { + let output = ''; + + output += ''; + + output += ''; + output += + ''; + output += ''; + + output += ''; + for (const key in overpassData.tags) { + if (key.substring(0, 5) === 'addr:') { + continue; + } + // `new Option().innerHTML` escapes HTML entities for XSS protection + let value = new Option(overpassData.tags[key]).innerHTML; + if (key.match(/email/)) { + value = '' + value + ''; + } + if (value.match(/^https?:\/\//)) { + value = '' + value + ''; + } + if (value.match(/^www/)) { + value = '' + value + ''; + } + output += ''; + output += ''; + output += ''; + output += ''; + } + output += ''; + + output += '
' + + i18next.t('layers.overpass-table-key') + + '' + + i18next.t('layers.overpass-table-value') + + '
' + key + '' + value + '
'; + + output += ''; + + return output; + }, + createOpenStreetMapNotesLayer: function () { return new leafletOsmNotes(); }, diff --git a/locales/en.json b/locales/en.json index c0e8ed4..91f728d 100644 --- a/locales/en.json +++ b/locales/en.json @@ -81,6 +81,10 @@ "customize": "Customize layers", "opacity-slider": "Opacity slider", "overpass-loading-indicator": "Running Overpass API query ...", + "overpass-table-key": "Key", + "overpass-table-value": "Value", + "overpass-inspect-at-openstreetmap": "Inspect Object at OpenStreetMap", + "overpass-osm": "OSM", "remove-selection": "Remove selection" }, "loadNogos": {