chore: replace panel:xxx events

This commit is contained in:
Yohan Boniface 2024-03-15 17:04:01 +01:00
parent 581f7134fd
commit 46016cb10b
7 changed files with 36 additions and 47 deletions

View file

@ -80,7 +80,7 @@
background-position: -27px -120px; background-position: -27px -120px;
} }
.icon-settings { .icon-settings {
background-position: -27px -93px; background-position: -23px -97px;
} }
.icon-share { .icon-share {
background-position: 0px -120px; background-position: 0px -120px;

View file

@ -61,10 +61,6 @@ export default class Browser {
return `browse_data_datalayer_${L.stamp(datalayer)}` return `browse_data_datalayer_${L.stamp(datalayer)}`
} }
onDataLayerChanged(e) {
this.updateDatalayer(e.target)
}
addDataLayer(datalayer, parent) { addDataLayer(datalayer, parent) {
let className = `datalayer ${datalayer.getHidableClass()}` let className = `datalayer ${datalayer.getHidableClass()}`
if (this.map.panel.MODE !== 'condensed') className += ' show-list' if (this.map.panel.MODE !== 'condensed') className += ' show-list'
@ -73,10 +69,6 @@ export default class Browser {
container.id = this.datalayerId(datalayer) container.id = this.datalayerId(datalayer)
const ul = DomUtil.create('ul', '', container) const ul = DomUtil.create('ul', '', container)
this.updateDatalayer(datalayer) this.updateDatalayer(datalayer)
datalayer.on('datachanged', this.onDataLayerChanged, this)
this.map.ui.once('panel:closed', () => {
datalayer.off('datachanged', this.onDataLayerChanged, this)
})
} }
updateDatalayer(datalayer) { updateDatalayer(datalayer) {
@ -127,6 +119,14 @@ export default class Browser {
}) })
} }
update() {
if (!this.isOpen()) return
this.dataContainer.innerHTML = ''
this.map.eachBrowsableDataLayer((datalayer) => {
this.addDataLayer(datalayer, this.dataContainer)
})
}
open() { open() {
// Get once but use it for each feature later // Get once but use it for each feature later
this.filterKeys = this.map.getFilterKeys() this.filterKeys = this.map.getFilterKeys()
@ -137,7 +137,7 @@ export default class Browser {
DomUtil.createTitle(container, translate('Browse data'), 'layers') DomUtil.createTitle(container, translate('Browse data'), 'layers')
const formContainer = DomUtil.create('div', '', container) const formContainer = DomUtil.create('div', '', container)
const dataContainer = DomUtil.create('div', '', container) this.dataContainer = DomUtil.create('div', '', container)
const fields = [ const fields = [
['options.filter', { handler: 'Input', placeholder: translate('Filter') }], ['options.filter', { handler: 'Input', placeholder: translate('Filter') }],
@ -154,9 +154,7 @@ export default class Browser {
className: 'umap-browser', className: 'umap-browser',
}) })
this.map.eachBrowsableDataLayer((datalayer) => { this.update()
this.addDataLayer(datalayer, dataContainer)
})
} }
static backButton(map) { static backButton(map) {

View file

@ -5,8 +5,9 @@ export class Panel {
MODE = 'condensed' MODE = 'condensed'
CLASSNAME = 'left' CLASSNAME = 'left'
constructor(parent) { constructor(map) {
this.parent = parent this.parent = map._container
this.map = map
this.container = DomUtil.create('div', '', this.parent) this.container = DomUtil.create('div', '', this.parent)
DomEvent.disableClickPropagation(this.container) DomEvent.disableClickPropagation(this.container)
DomEvent.on(this.container, 'contextmenu', DomEvent.stopPropagation) // Do not activate our custom context menu. DomEvent.on(this.container, 'contextmenu', DomEvent.stopPropagation) // Do not activate our custom context menu.
@ -35,13 +36,8 @@ export class Panel {
} }
if (e.className) DomUtil.addClass(body, e.className) if (e.className) DomUtil.addClass(body, e.className)
const promise = new Promise((resolve, reject) => { const promise = new Promise((resolve, reject) => {
if (DomUtil.hasClass(this.container, 'on')) { DomUtil.addClass(this.container, 'on')
// Already open. resolve()
resolve()
} else {
DomEvent.once(this.container, 'transitionend', resolve)
DomUtil.addClass(this.container, 'on')
}
}) })
DomEvent.on(closeLink, 'click', this.close, this) DomEvent.on(closeLink, 'click', this.close, this)
DomEvent.on(resizeLink, 'click', this.resize, this) DomEvent.on(resizeLink, 'click', this.resize, this)
@ -63,6 +59,8 @@ export class Panel {
close() { close() {
if (DomUtil.hasClass(this.container, 'on')) { if (DomUtil.hasClass(this.container, 'on')) {
DomUtil.removeClass(this.container, 'on') DomUtil.removeClass(this.container, 'on')
this.map.invalidateSize({ pan: false })
this.map.editedFeature = null
} }
} }
} }

View file

@ -1298,10 +1298,7 @@ U.SearchControl = L.Control.extend({
this.map.fire('dataload', { id: id }) this.map.fire('dataload', { id: id })
}) })
this.search.resultsContainer = resultsContainer this.search.resultsContainer = resultsContainer
this.map.ui.once('panel:ready', () => { this.map.panel.open({ data: { html: container } }).then(input.focus)
input.focus()
})
this.map.panel.open({ data: { html: container } })
}, },
}) })

View file

@ -56,10 +56,10 @@ U.Map = L.Map.extend({
if (geojson.geometry) this.options.center = this.latLng(geojson.geometry) if (geojson.geometry) this.options.center = this.latLng(geojson.geometry)
this.urls = new U.URLs(this.options.urls) this.urls = new U.URLs(this.options.urls)
this.panel = new U.Panel(this._container) this.panel = new U.Panel(this)
if (this.hasEditMode()) { if (this.hasEditMode()) {
this.editPanel = new U.EditPanel(this._container) this.editPanel = new U.EditPanel(this)
this.fullPanel = new U.FullPanel(this._container) this.fullPanel = new U.FullPanel(this)
} }
this.ui = new U.UI(this._container) this.ui = new U.UI(this._container)
this.ui.on('dataloading', (e) => this.fire('dataloading', e)) this.ui.on('dataloading', (e) => this.fire('dataloading', e))
@ -149,14 +149,6 @@ U.Map = L.Map.extend({
this.options.onLoadPanel = 'datalayers' this.options.onLoadPanel = 'datalayers'
} }
this.ui.on(
'panel:closed',
function () {
this.invalidateSize({ pan: false })
},
this
)
let isDirty = false // self status let isDirty = false // self status
try { try {
Object.defineProperty(this, 'isDirty', { Object.defineProperty(this, 'isDirty', {
@ -208,13 +200,6 @@ U.Map = L.Map.extend({
this.initCaptionBar() this.initCaptionBar()
if (this.hasEditMode()) { if (this.hasEditMode()) {
this.editTools = new U.Editable(this) this.editTools = new U.Editable(this)
this.ui.on(
'panel:closed panel:open',
function () {
this.editedFeature = null
},
this
)
this.renderEditToolbar() this.renderEditToolbar()
} }
this.initShortcuts() this.initShortcuts()
@ -478,6 +463,11 @@ U.Map = L.Map.extend({
if (!pane.dataset || !pane.dataset.id) continue if (!pane.dataset || !pane.dataset.id) continue
this.datalayers_index.push(this.datalayers[pane.dataset.id]) this.datalayers_index.push(this.datalayers[pane.dataset.id])
} }
this.onDataLayersChanged()
},
onDataLayersChanged: function () {
if (this.browser) this.browser.update()
}, },
ensurePanesOrder: function () { ensurePanesOrder: function () {
@ -971,6 +961,7 @@ U.Map = L.Map.extend({
this.dirty_datalayers = [] this.dirty_datalayers = []
this.initTileLayers() this.initTileLayers()
this.isDirty = false this.isDirty = false
this.onDataLayersChanged()
}, },
checkDirty: function () { checkDirty: function () {

View file

@ -594,6 +594,7 @@ U.DataLayer = L.Evented.extend({
// Automatically, others will be shown manually, and thus will // Automatically, others will be shown manually, and thus will
// be in the "forced visibility" mode // be in the "forced visibility" mode
if (this.autoLoaded()) this.map.on('zoomend', this.onZoomEnd, this) if (this.autoLoaded()) this.map.on('zoomend', this.onZoomEnd, this)
this.on('datachanged', this.map.onDataLayersChanged, this.map)
}, },
render: function (fields, builder) { render: function (fields, builder) {
@ -845,6 +846,7 @@ U.DataLayer = L.Evented.extend({
if (L.Util.indexOf(this.map.datalayers_index, this) === -1) if (L.Util.indexOf(this.map.datalayers_index, this) === -1)
this.map.datalayers_index.push(this) this.map.datalayers_index.push(this)
} }
this.map.onDataLayersChanged()
}, },
_dataUrl: function () { _dataUrl: function () {
@ -1152,6 +1154,8 @@ U.DataLayer = L.Evented.extend({
delete this.map.datalayers[L.stamp(this)] delete this.map.datalayers[L.stamp(this)]
this.map.datalayers_index.splice(this.getRank(), 1) this.map.datalayers_index.splice(this.getRank(), 1)
this.parentPane.removeChild(this.pane) this.parentPane.removeChild(this.pane)
this.map.onDataLayersChanged()
this.off('datachanged', this.map.onDataLayersChanged, this.map)
this.fire('erase') this.fire('erase')
this._leaflet_events_bk = this._leaflet_events this._leaflet_events_bk = this._leaflet_events
this.map.off('moveend', this.onMoveEnd, this) this.map.off('moveend', this.onMoveEnd, this)
@ -1214,6 +1218,7 @@ U.DataLayer = L.Evented.extend({
L.DomUtil.createTitle(container, L._('Layer properties'), 'icon-layers') L.DomUtil.createTitle(container, L._('Layer properties'), 'icon-layers')
let builder = new U.FormBuilder(this, metadataFields, { let builder = new U.FormBuilder(this, metadataFields, {
callback: function (e) { callback: function (e) {
this.map.onDataLayersChanged()
if (e.helper.field === 'options.type') { if (e.helper.field === 'options.type') {
this.edit() this.edit()
} }

View file

@ -660,7 +660,7 @@ ul.photon-autocomplete {
display: inline-block; /* Prevents underline on hover. */ display: inline-block; /* Prevents underline on hover. */
} }
.umap-edit-enabled .leaflet-top { .umap-edit-enabled .leaflet-top {
top: 48px; top: 46px;
} }
.umap-caption-bar-enabled .umap-caption-bar { .umap-caption-bar-enabled .umap-caption-bar {
display: block; display: block;
@ -935,7 +935,7 @@ a.umap-control-caption,
.umap-browser.dark .datalayer li:nth-child(even) { .umap-browser.dark .datalayer li:nth-child(even) {
background-color: #2c3233; background-color: #2c3233;
} }
.umap-browser .datalayer i.feature-color { .umap-browser .datalayer .feature-color {
box-shadow: 0 0 2px 0 black inset; box-shadow: 0 0 2px 0 black inset;
cursor: inherit; cursor: inherit;
-moz-box-sizing:border-box; -moz-box-sizing:border-box;
@ -948,7 +948,7 @@ a.umap-control-caption,
text-align: center; text-align: center;
margin-left: 5px; margin-left: 5px;
} }
.umap-browser.dark .datalayer i.feature-color { .umap-browser.dark .datalayer .feature-color {
box-shadow: 0 0 2px 0 #999 inset; box-shadow: 0 0 2px 0 #999 inset;
} }
.umap-browser .datalayer .feature-color img { .umap-browser .datalayer .feature-color img {