chore: remove calls to L. from browser.js

This commit is contained in:
Yohan Boniface 2024-03-15 18:00:30 +01:00
parent 2c248ea124
commit c9acb22d64

View file

@ -1,4 +1,4 @@
import { DomUtil, DomEvent } from '../../vendors/leaflet/leaflet-src.esm.js' import { DomUtil, DomEvent, stamp } from '../../vendors/leaflet/leaflet-src.esm.js'
import { translate } from './i18n.js' import { translate } from './i18n.js'
export default class Browser { export default class Browser {
@ -16,14 +16,26 @@ export default class Browser {
if (filter && !feature.matchFilter(filter, this.filterKeys)) return if (filter && !feature.matchFilter(filter, this.filterKeys)) return
if (this.options.inBbox && !feature.isOnScreen(this.bounds)) return if (this.options.inBbox && !feature.isOnScreen(this.bounds)) return
const row = DomUtil.create('li', `${feature.getClassName()} feature`) const row = DomUtil.create('li', `${feature.getClassName()} feature`)
const zoom_to = DomUtil.createButtonIcon(row, 'icon-zoom', translate('Bring feature to center')) const zoom_to = DomUtil.createButtonIcon(
const edit = DomUtil.createButtonIcon(row, 'show-on-edit icon-edit', translate('Edit this feature')) row,
const del = DomUtil.createButtonIcon(row, 'show-on-edit icon-delete', translate('Delete this feature')) 'icon-zoom',
translate('Bring feature to center')
)
const edit = DomUtil.createButtonIcon(
row,
'show-on-edit icon-edit',
translate('Edit this feature')
)
const del = DomUtil.createButtonIcon(
row,
'show-on-edit icon-delete',
translate('Delete this feature')
)
const colorBox = DomUtil.create('i', 'icon icon-16 feature-color', row) const colorBox = DomUtil.create('i', 'icon icon-16 feature-color', row)
const title = DomUtil.create('span', 'feature-title', row) const title = DomUtil.create('span', 'feature-title', row)
const symbol = feature._getIconUrl const symbol = feature._getIconUrl
? U.Icon.prototype.formatUrl(feature._getIconUrl(), feature) ? U.Icon.prototype.formatUrl(feature._getIconUrl(), feature)
: null : null
title.textContent = feature.getDisplayName() || '—' title.textContent = feature.getDisplayName() || '—'
const bgcolor = feature.getDynamicOption('color') const bgcolor = feature.getDynamicOption('color')
colorBox.style.backgroundColor = bgcolor colorBox.style.backgroundColor = bgcolor
@ -31,24 +43,11 @@ export default class Browser {
const icon = U.Icon.makeIconElement(symbol, colorBox) const icon = U.Icon.makeIconElement(symbol, colorBox)
U.Icon.setIconContrast(icon, colorBox, symbol, bgcolor) U.Icon.setIconContrast(icon, colorBox, symbol, bgcolor)
} }
DomEvent.on( const viewFeature = (e) => {
zoom_to, feature.zoomTo({...e, callback: feature.view})
'click', }
function (e) { DomEvent.on(zoom_to, 'click', viewFeature)
e.callback = L.bind(this.view, this) DomEvent.on(title, 'click', viewFeature)
this.zoomTo(e)
},
feature
)
DomEvent.on(
title,
'click',
function (e) {
e.callback = L.bind(this.view, this)
this.zoomTo(e)
},
feature
)
DomEvent.on(edit, 'click', feature.edit, feature) DomEvent.on(edit, 'click', feature.edit, feature)
DomEvent.on(del, 'click', feature.confirmDelete, feature) DomEvent.on(del, 'click', feature.confirmDelete, feature)
// HOTFIX. Remove when this is released: // HOTFIX. Remove when this is released:
@ -58,7 +57,7 @@ export default class Browser {
} }
datalayerId(datalayer) { datalayerId(datalayer) {
return `browse_data_datalayer_${L.stamp(datalayer)}` return `browse_data_datalayer_${stamp(datalayer)}`
} }
addDataLayer(datalayer, parent) { addDataLayer(datalayer, parent) {
@ -158,13 +157,13 @@ export default class Browser {
} }
static backButton(map) { static backButton(map) {
const button = L.DomUtil.create('li', '') const button = DomUtil.create('li', '')
L.DomUtil.create('i', 'icon icon-16 icon-back', button) DomUtil.create('i', 'icon icon-16 icon-back', button)
button.title = L._('Back to browser') button.title = translate('Back to browser')
// Fixme: remove me when this is merged and released // Fixme: remove me when this is merged and released
// https://github.com/Leaflet/Leaflet/pull/9052 // https://github.com/Leaflet/Leaflet/pull/9052
L.DomEvent.disableClickPropagation(button) DomEvent.disableClickPropagation(button)
L.DomEvent.on(button, 'click', map.openBrowser, map) DomEvent.on(button, 'click', map.openBrowser, map)
return button return button
} }
} }