feat: allow to hide the back to home button (#2638)

This commit is contained in:
Yohan Boniface 2025-04-11 17:30:15 +02:00 committed by GitHub
commit ef072f0a8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 11 deletions

View file

@ -23,6 +23,7 @@ BaseMap.mergeOptions({
const ControlsMixin = { const ControlsMixin = {
HIDDABLE_CONTROLS: [ HIDDABLE_CONTROLS: [
'home',
'zoom', 'zoom',
'search', 'search',
'fullscreen', 'fullscreen',
@ -41,6 +42,7 @@ const ControlsMixin = {
if (this._umap.hasEditMode() && !this.options.noControl) { if (this._umap.hasEditMode() && !this.options.noControl) {
new U.EditControl(this).addTo(this) new U.EditControl(this).addTo(this)
} }
this._controls.home = new U.HomeControl(this._umap)
this._controls.zoom = new Control.Zoom({ this._controls.zoom = new Control.Zoom({
zoomInTitle: translate('Zoom in'), zoomInTitle: translate('Zoom in'),
zoomOutTitle: translate('Zoom out'), zoomOutTitle: translate('Zoom out'),
@ -91,10 +93,6 @@ const ControlsMixin = {
} }
if (this.options.noControl) return 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) this._controls.attribution = new U.AttributionControl().addTo(this)
if (this.options.miniMap) { if (this.options.miniMap) {
this.whenReady(function () { this.whenReady(function () {

View file

@ -204,6 +204,12 @@ export const SCHEMA = {
type: Object, type: Object,
impacts: ['data'], impacts: ['data'],
}, },
homeControl: {
type: Boolean,
impacts: ['ui'],
label: translate('Display the back to home icon'),
default: true,
},
iconClass: { iconClass: {
type: String, type: String,
impacts: ['data'], impacts: ['data'],

View file

@ -106,6 +106,11 @@ export default class Umap {
if (geojson.properties.schema) this.overrideSchema(geojson.properties.schema) if (geojson.properties.schema) this.overrideSchema(geojson.properties.schema)
// Do not display in an iframe.
if (window.self !== window.top) {
geojson.properties.homeControl = false
}
this._leafletMap.setup() this._leafletMap.setup()
this.panel = new Panel(this, this._leafletMap) this.panel = new Panel(this, this._leafletMap)
@ -828,6 +833,7 @@ export default class Umap {
UIFields.push(`properties.${name}Control`) UIFields.push(`properties.${name}Control`)
} }
UIFields = UIFields.concat([ UIFields = UIFields.concat([
'properties.homeControl',
'properties.moreControl', 'properties.moreControl',
'properties.scrollWheelZoom', 'properties.scrollWheelZoom',
'properties.miniMap', 'properties.miniMap',

View file

@ -69,13 +69,7 @@ def test_zoomcontrol_impacts_ui(live_server, page, tilelayer):
# Hide them # Hide them
page.get_by_text("User interface options").click() page.get_by_text("User interface options").click()
hide_zoom_controls = ( page.locator(".panel .umap-field-zoomControl").get_by_text("never").click()
page.locator(".panel")
.filter(has_text=re.compile("Display the zoom control"))
.locator("label")
.nth(2)
)
hide_zoom_controls.click()
expect(zoom_in).to_be_hidden() expect(zoom_in).to_be_hidden()
expect(zoom_out).to_be_hidden() expect(zoom_out).to_be_hidden()