Skip to content

Commit

Permalink
Trigger event on attribut click #1067
Browse files Browse the repository at this point in the history
  • Loading branch information
Viglino committed Jun 19, 2024
1 parent c9acc22 commit 9ca2774
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions examples/popup/map.popup.feature.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ <h2>Options:</h2>
});
map.addOverlay (popup);

// Event on attribute click
popup.on('attribute', console.log)

</script>

</body>
Expand Down
14 changes: 11 additions & 3 deletions src/overlay/PopupFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import ol_ext_element from '../util/element.js'
* @fires show
* @fires hide
* @fires select
* @fires attribute
* @param {} options Extend Popup options
* @param {String} options.popupClass the a class of the overlay to style the popup.
* @param {bool} options.closeBox popup has a close box, default false.
Expand Down Expand Up @@ -173,7 +174,7 @@ var ol_Overlay_PopupFeature = class olOverlayPopupFeature extends ol_Overlay_Pop
var tr, table = ol_ext_element.create('TABLE', { parent: html });
var atts = this._attributeObject(template);
var featureAtts = feature.getProperties();
for (var att in atts) {
Object.keys(atts).forEach(function(att) {
if (featureAtts.hasOwnProperty(att)) {
var a = atts[att];
var content, val = featureAtts[att];
Expand All @@ -191,8 +192,14 @@ var ol_Overlay_PopupFeature = class olOverlayPopupFeature extends ol_Overlay_Pop
}

if (visible) {
tr = ol_ext_element.create('TR', { parent: table });
tr = ol_ext_element.create('TR', {
click: function(e) {
this.dispatchEvent({ type: 'attribute', attribute: att, originalEvent: e })
}.bind(this),
parent: table
});
ol_ext_element.create('TD', {
className: 'ol-label',
html: a ? a.title || att : att,
parent: tr
});
Expand All @@ -216,12 +223,13 @@ var ol_Overlay_PopupFeature = class olOverlayPopupFeature extends ol_Overlay_Pop

// Add value
ol_ext_element.create('TD', {
className: 'ol-value',
html: content,
parent: tr
});
}
}
}
}.bind(this))
}
// Zoom button
ol_ext_element.create('BUTTON', { className: 'ol-zoombt', parent: html })
Expand Down

0 comments on commit 9ca2774

Please sign in to comment.