Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide and show a polyline in leaflet?

I'm using leaflet for show raw itinerary to go to some markers. I'm showing my itinerary with a leaflet polyline. But I would like to be able to

How to hide and show a polyline in leaflet ?

I can do this :

$('.leaflet-overlay-pane').hide();

and

$('.leaflet-overlay-pane').show();

But this will show and hide all my polyline. I would like to be able to hide and show them separately.

Thanks.

like image 292
Baptiste Metge Avatar asked Oct 17 '13 09:10

Baptiste Metge


1 Answers

If you have a reference to the polyline

var polyline = L.polyline(...);

Then you can use

map.addLayer(polyline);//For show
map.removeLayer(polyline);// For hide

at the moment I think there is no native method to only hide/show, maybe in the 0.7 version

Other solution is to access to the object container, in a old commet from the maintainer

I don't think there's an easy solution, for tile layers at least. :( I'll try to handle this sooner.
For vectors, you can change path._container.style.display, and for markers - marker._image.style.display and marker._shadow.style.display.
like image 70
Edu Avatar answered Sep 28 '22 15:09

Edu