From beae551367743127e478c2f7aa88c71751d7a42b Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 7 Mar 2025 17:11:28 +0100 Subject: [PATCH] feat: add new "Back to home" icon Co-authored-by: David Larlet --- umap/static/umap/img/home.svg | 7 +++++++ umap/static/umap/js/modules/rendering/map.js | 4 ++++ umap/static/umap/js/modules/umap.js | 8 ++++++-- umap/static/umap/js/umap.controls.js | 16 +++++++++++++++- umap/static/umap/map.css | 11 ++++++++++- 5 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 umap/static/umap/img/home.svg diff --git a/umap/static/umap/img/home.svg b/umap/static/umap/img/home.svg new file mode 100644 index 00000000..43f0bbae --- /dev/null +++ b/umap/static/umap/img/home.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/umap/static/umap/js/modules/rendering/map.js b/umap/static/umap/js/modules/rendering/map.js index dfb52ada..1a7c01a4 100644 --- a/umap/static/umap/js/modules/rendering/map.js +++ b/umap/static/umap/js/modules/rendering/map.js @@ -91,6 +91,10 @@ const ControlsMixin = { } if (this.options.noControl) return + // Do not display in an iframe. + if (window.self === window.top) { + this._controls.home = new U.HomeControl().addTo(this) + } this._controls.attribution = new U.AttributionControl().addTo(this) if (this.options.miniMap) { this.whenReady(function () { diff --git a/umap/static/umap/js/modules/umap.js b/umap/static/umap/js/modules/umap.js index 4b7f9792..1648f1fe 100644 --- a/umap/static/umap/js/modules/umap.js +++ b/umap/static/umap/js/modules/umap.js @@ -101,10 +101,10 @@ export default class Umap extends ServerStored { this.urls = new URLs(this.properties.urls) this.slideshow = new Slideshow(this, this._leafletMap) - this._leafletMap.setup() - if (geojson.properties.schema) this.overrideSchema(geojson.properties.schema) + this._leafletMap.setup() + this.panel = new Panel(this, this._leafletMap) this.dialog = new Dialog({ className: 'dark' }) this.topBar = new TopBar(this, this._leafletMap._controlContainer) @@ -1757,4 +1757,8 @@ export default class Umap extends ServerStored { this.isDirty = true this._defaultExtent = false } + + getStaticPathFor(name) { + return SCHEMA.iconUrl.default.replace('marker.svg', name) + } } diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index 3aee1cf2..d0945fe5 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -1,3 +1,17 @@ +U.HomeControl = L.Control.extend({ + options: { + position: 'topleft', + }, + + onAdd: (map) => { + const path = map._umap.getStaticPathFor('home.svg') + const container = U.Utils.loadTemplate( + `${L._('Home logo')}` + ) + return container + }, +}) + U.EditControl = L.Control.extend({ options: { position: 'topright', @@ -468,7 +482,7 @@ U.Search = L.PhotonSearch.extend({ }) el.appendChild(tools) this._formatResult(feature, el) - const path = U.SCHEMA.iconUrl.default.replace('marker.svg', 'target.svg') + const path = this.map._umap.getStaticPathFor('target.svg') const icon = L.icon({ iconUrl: path, iconSize: [24, 24], diff --git a/umap/static/umap/map.css b/umap/static/umap/map.css index c78baa4d..9ba84e7c 100644 --- a/umap/static/umap/map.css +++ b/umap/static/umap/map.css @@ -247,7 +247,16 @@ html[dir="rtl"] .leaflet-tooltip-pane > * { .leaflet-iconLayers:hover .leaflet-iconLayers-layerCell-plus { display: block; } - +.home-button { + cursor: pointer; + line-height: 0; + border: 1px solid var(--color-darkBlue); + border-radius: 50%; + background-color: var(--background-color); +} +.home-button:hover { + background-color: var(--color-lighterGray); +}