I'm trying to open a popup when clicking on a tooltip of a layer.
I try following code:
function add_layer_rescue_spot() {
rescue_spot_layer = new L.GeoJSON.AJAX(rescue_spot_path, {
style: label_style,
pane: 'label',
onEachFeature: on_each_rescue_spot_feature,
pointToLayer: function(feature, latlon) {
return point_to_label_layer(
'<i class="fa fa-plus-circle"></i>',
latlon, 'rescue_spot');
},
}).addTo(map);
rescue_spot_layer.on('data:loaded', function() {
rescue_spot_layer.getLayers().forEach(function(feature) {
tooltip = feature.getTooltip().getElement();
tooltip.addEventListener('click', function(e) {
console.log('test');
feature.openPopup();
});
tooltip.style.pointerEvents = 'auto';
});
});
}
function on_each_rescue_spot_feature(feature, layer) {
rescue_spot_popup(feature, layer);
}
function point_to_label_layer(text, latlon, class_name) {
var label = String(text);
return new L.CircleMarker(latlon, {
radius: 1,
}).bindTooltip(label, {
permanent: true,
direction: 'center',
className: class_name + '-label',
}).openTooltip();
}
function rescue_spot_popup(feature, layer) {
var properties = feature.properties;
var max_height = parseInt($('#map').height() * 0.95);
var popup_html = `
<h5>Test</h5>
<table class="popup-table">
<tr>
<td class="attrib-name">foo</td>
<td class="attrib-value">foo</td>
</tr>
<tr>
<td class="attrib-name">bar</td>
<td class="attrib-value">bar</td>
</tr>
</table>`;
layer.bindPopup(popup_html, {maxHeight: max_height});
}
So when I click on the tooltip, 'test' is logged and the map moves a bit like the popup would be opened. But the popup doesn't show up.
When I open the popup manually in the browser by typing:
rescue_spot_layer.getLayers()[0].openPopup()
the popup opens as expected.
Any ideas what I'm doing wrong?
point_to_label_layer
andrescue_spot_popup
). That would help pinponting the reason for popup not showing up.rescue_spot_popup
is a bit vital to this, to provide a complete answer