I have a button on a leaflet map that when clicked zooms the map to the users current location. This function is working properly.
<button type="button" id="locator" class="btn btn-primary btn-lg">
..
$("#locator").click(function() {
map.locate({
setView: true,
maxZoom: 16
});
Using the lat and long of the found location I would like to emulate a click event on the intersecting polygon layer. To perform this I use the maps 'locationfound' event to fire a click event at the found location (below). Nothing happens.
map.on('locationfound', function(e) {
var latlngPoint = new L.LatLng(e.latlng.lng, e.latlng.lat);
map.fireEvent('click', {
latlng: latlngPoint
});
});
The polygon layer has the following click event. The layer click event works fine when clicked manually, but does not execute via passing latlng pair.
var sections = L.geoJson(randall, {
style: featureStyle,
onEachFeature: onEachFeature
});
function onEachFeature(feature, featureLayer) {
featureLayer.bindPopup(feature.properties.ANUM);
featureLayer.on('click', function(e) {
console.log('Layer clicked!', e);
})
};
Heres my jsfiddle.