chore: refactor simple button controls

This commit is contained in:
Yohan Boniface 2024-03-14 20:41:47 +01:00
parent c4e86c4ab9
commit 3bc57a8512

View file

@ -407,26 +407,6 @@ U.EditControl = L.Control.extend({
}, },
}) })
/* Share control */
L.Control.Embed = L.Control.extend({
options: {
position: 'topleft',
},
onAdd: function (map) {
const container = L.DomUtil.create('div', 'leaflet-control-embed umap-control')
const shareButton = L.DomUtil.createButton(
'',
container,
L._('Share and download'),
map.share.open,
map.share
)
L.DomEvent.on(shareButton, 'dblclick', L.DomEvent.stopPropagation)
return container
},
})
U.MoreControls = L.Control.extend({ U.MoreControls = L.Control.extend({
options: { options: {
position: 'topleft', position: 'topleft',
@ -503,8 +483,12 @@ L.Control.Button = L.Control.extend({
L.Control.prototype.initialize.call(this, options) L.Control.prototype.initialize.call(this, options)
}, },
getClassName: function () {
return this.options.className
},
onAdd: function (map) { onAdd: function (map) {
const container = L.DomUtil.create('div', `${this.options.className} umap-control`) const container = L.DomUtil.create('div', `${this.getClassName()} umap-control`)
const button = L.DomUtil.createButton( const button = L.DomUtil.createButton(
'', '',
container, container,
@ -541,6 +525,34 @@ U.CaptionControl = L.Control.Button.extend({
}, },
}) })
U.StarControl = L.Control.Button.extend({
options: {
position: 'topleft',
title: L._('Star this map'),
},
getClassName: function () {
const status = this.map.options.starred ? ' starred' : ''
return `leaflet-control-star umap-control${status}`
},
onClick: function () {
this.map.star()
},
})
L.Control.Embed = L.Control.Button.extend({
options: {
position: 'topleft',
title: L._('Share and download'),
className: 'leaflet-control-embed umap-control',
},
onClick: function () {
this.map.share.open()
},
})
U.DataLayer.include({ U.DataLayer.include({
renderLegend: function (container) { renderLegend: function (container) {
if (this.layer.renderLegend) return this.layer.renderLegend(container) if (this.layer.renderLegend) return this.layer.renderLegend(container)
@ -1111,29 +1123,6 @@ U.AttributionControl = L.Control.Attribution.extend({
}, },
}) })
U.StarControl = L.Control.extend({
options: {
position: 'topleft',
},
onAdd: function (map) {
const status = map.options.starred ? ' starred' : ''
const container = L.DomUtil.create(
'div',
`leaflet-control-star umap-control${status}`
)
const starMapButton = L.DomUtil.createButton(
'',
container,
L._('Star this map'),
map.star,
map
)
L.DomEvent.on(starMapButton, 'dblclick', L.DomEvent.stopPropagation)
return container
},
})
/* /*
* Take control over L.Control.Locate to be able to * Take control over L.Control.Locate to be able to
* call start() before adding the control (and thus the button) to the map. * call start() before adding the control (and thus the button) to the map.