I am facing a scenario where I have a map with a unique legend that is styled either as an SVG or a PNG. The legend is always positioned in the bottom left corner but can be quite large, as users have the option to toggle it on and off.
Additionally, the map contains numerous markers, each with a tooltip that can also be sizable. These tooltips are displayed when the mouse hovers over a marker. The issue arises when a user hovers over a marker close to the legend - the tooltip ends up hidden behind the legend. I aim to solve this problem by ensuring that the popups appear above the legend in the following order: marker, legend, marker popup.
You can see a demonstration of this situation on a JSFiddle https://jsfiddle.net/e51mydwa/9/. The legends are added in a similar manner, although the actual < div id="legend"> tag holds an < img> or < svg>.
<div id="map">
<div id="legend">
I am Legend
</div>
</div>
I've reviewed the example at http://leafletjs.com/examples/choropleth/, but upon inspecting the DOM, I noticed that it encounters the same issue. This is because the legend is inserted into the same div as the leaflet controls, which are always positioned above the map layers (as expected, controls should always be on top).
Moreover, I attempted placing the legend within a div on a sibling layer to the popup-containing layer. Although this resolved the z-index problem, the parent div of both these elements includes a transform that changes as users drag the map around, causing the legends to move as well and lose their static position.
I welcome any suggestions or ideas to address this matter.