move higlight() into Marker class

options.icon pointer is invalid after hide() show() cycle.
This commit is contained in:
Joachim Schleicher 2023-10-19 20:57:40 +02:00
parent 5778c4ff65
commit 88746d593c
2 changed files with 10 additions and 11 deletions

View file

@ -549,6 +549,14 @@ L.U.Marker = L.Marker.extend({
this.setIcon(this.getIcon())
},
highlight: function () {
L.DomUtil.addClass(this.options.icon.elements.main, 'umap-icon-active')
},
resetHighlight: function () {
L.DomUtil.removeClass(this.options.icon.elements.main, 'umap-icon-active')
},
addInteractions: function () {
L.U.FeatureMixin.addInteractions.call(this)
this.on(
@ -562,10 +570,8 @@ L.U.Marker = L.Marker.extend({
if (!this.isReadOnly()) this.on('mouseover', this._enableDragging)
this.on('mouseout', this._onMouseOut)
this._popupHandlersAdded = true // prevent Leaflet from binding event on bindPopup
this.once('add', () => {
this.on('popupopen', this.options.icon.highlight, this.options.icon)
this.on('popupclose', this.options.icon.resetHighlight, this.options.icon)
})
this.on('popupopen', this.highlight)
this.on('popupclose', this.resetHighlight)
},
hasGeom: function () {

View file

@ -38,13 +38,6 @@ L.U.Icon = L.DivIcon.extend({
formatUrl: function (url, feature) {
return L.Util.greedyTemplate(url || '', feature ? feature.extendedProperties() : {})
},
highlight: function () {
L.DomUtil.addClass(this.elements.main, 'umap-icon-active')
},
resetHighlight: function () {
L.DomUtil.removeClass(this.elements.main, 'umap-icon-active')
},
})
L.U.Icon.Default = L.U.Icon.extend({