Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Using Leaflet, how can I reset a polyline to it's previous color after it was selected? I have the following function that has been applied to each polyline when constructed:

function onEachFeature(feature, layer) {

    layer.on({
        mouseover: highlightFeature,
        mouseout: resetHighlight    
    });    
}

When the polyline is selected I use the following approach to color it:

function highlightFeature(e) {
    var layer = e.target;

    layer.setStyle({
        weight: 12,
        color: 'gray',
        dashArray: '',
        fillOpacity: 0.7
    });

    if (!L.Browser.ie && !L.Browser.opera) {
        layer.bringToFront();
    }
}

And to remove the highlighting, I want to reset it to it's previous color (this is where I have a problem)

function resetHighlight(e) {
    var layer = e.target;
    console.log(layer)

    // my leaflet map object is called l_map
    l_map.polyline.resetStyle(e.target);

}

Is there is a simple way to remove the selection/color change from a polyline?

share|improve this question
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.