1

I have a very simple leaflet map which has a set of easy buttons whose function is to add and remove layers from the map.

I'd like to set tooltip or mouseover or hover so when the user moves the mouse over the buttons they get a message. Simple.

Here's an example of the code for the layers, then for the buttons:

//layer coding

var buildings = L.geoJson(buildings,{
 style: function(feature, layer){
    return { 
        color: "purple",
        fillOpacity: 9,
        weight: 2
    };
},

}).addTo(map);


//button coding

L.easyButton('<img class="icon" src="icons/house.png">',

function(btn, map){

if (map.hasLayer(buildings)){
    map.removeLayer(buildings);
} else {
    map.addLayer(buildings);
};

}).addTo( map );
2

Modifying the last line works for me.

//layer coding

var buildings = L.geoJson(buildings,{
 style: function(feature, layer){
    return { 
        color: "purple",
        fillOpacity: 9,
        weight: 2
    };
},

}).addTo(map);


//button coding

L.easyButton('<img class="icon" src="icons/house.png">',

function(btn, map){

if (map.hasLayer(buildings)){
    map.removeLayer(buildings);
} else {
    map.addLayer(buildings);
};

},'Interact with the map').addTo(map);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.