I have a map with a polygon layer and a marker layer. They are both derived from GeoJSONs, which are identical in every way except for the geometry (the marker layer is simply the centroids of the polygon layer). I currently have some functionality for the user to click on the polygon layer, and the selected polygon is coloured, added to some tracking arrays, and some summary information derived from the GeoJSON layer is displayed elsewhere.
The problem is that the associated marker layer is quite large, and makes it annoying to click on the polygons. (See image below)
Clicking on the markers does not count as a click on the polygon layer. Rather than having to write some new functions to deal with grabbing values from the marker layer and looking them up in the polygon layer to do the same thing, I would rather just somehow "click through" the marker layer directly onto the polygon layer underneath, or somehow forward the click coordinates to it.
I am aware of the fireEvent method in Leaflet, but I cannot seem to figure out a way to use it to send the click coordinates to the polygon layer. Has anybody done something like this before, or perhaps have a better approach?
By the way, I have already seen Trigger a click event on a leaflet map? which appears to be the same, but if you read the accepted answer, the author was simply overcomplicating a routine task, and so the question of "triggering a click event with coordinates" was never actually answered
This is the code I am working with now, it doesn't work, but I can't find any working examples of passing a click to a layer:
onEachFeature: function(feature, layer) {
layer.bindTooltip(feature.properties.name, {
sticky: true
});
layer.on('click', function (e) {
console.log(e);
var lat = e.latlng.lat;
var lng = e.latlng.lng;
var latlngPoint = new L.LatLng(lat, lng);
console.log(latlngPoint);
markerPolygonLayer.fireEvent('click', {
latlng: latlngPoint,
layerPoint: map.latLngToLayerPoint(latlngPoint),
containerPoint: map.latLngToContainerPoint(latlngPoint)
});
});
},
