I created a Leaflet Map with a Legend. The goal would be to hover over the text element in the legend area and show a tooltip with a image.
Problem: hover is not showing up! I tried very different version. The easiest way which should usually work is this one:
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'}).addTo(map);
var marker = L.marker([51.5, -0.09]).addTo(map).bindPopup('Popup.');
var MyControl = L.Control.extend({
options: {
position: 'topleft'
},
onAdd: function (map) {
// create the control container with a particular class name
var container = L.DomUtil.create('div', 'my-custom-control');
container.innerHTML += '<div id="hoverhelp" title="">Image Hover Example Leaflet</div>';
L.DomEvent.disableClickPropagation(container);
return container;
}});
map.addControl(new MyControl());
$( "#hoverhelp" ).tooltip({ content: '<img src="https://www.google.com/logos/doodles/2020/mascha-kalekos-113th-birthday-6753651837108682-s.png" />' });
If someone wants to try: jsfiddle