My leaflet project has a few user drawn shapes on it. When clicking on the shape, another element such as a sidebar will print out the stats. If I click on the map layer, the element is supposed to reset.
I tried using the map.on('click') event, but it listens to all user drawn layers as well as the map layer. I only want the event to listen to the map layer.
map.on('click', onBackgroundClick);
function onBackgroundClick(e)
{
let type = e.layerType;
if (type !== 'polygon' && type !== 'polyline' && type !== 'marker' && type != 'rectangle')
{
//reset sidebar state
}
}
What changes do I make to the event such that it only listens to the map layer. Is there a better approach to this problem?