polyline and zoom

24 views
Skip to first unread message

cyril guerin

unread,
Dec 4, 2016, 12:14:50 PM12/4/16
to Leaflet
hello,
I just want to know if it's possible to change the width of the polyline when I zoom in or zoom out?
Because I have some polylines with width=8 and when I zoom out, it become a big sh** at the middle of my map.

thank you for you help

Max Abou-Hagar

unread,
Dec 7, 2016, 12:16:57 PM12/7/16
to Leaflet
Yes, polylines to extend the abstract path class, so you can set the linewidth dynamically:
polyline.setStyle({weight: 5}); 
for example.

Here you can see a full example: http://plnkr.co/edit/NSFVOgT9Spq8SC3mSPWa?p=preview

You will also need to listen to the zoom events. Leaflet provides you with the "zoomend" event, so for example:

map.on('zoomend', function() { /* ... */ });
lets you act on zoom changes.

Max
Reply all
Reply to author
Forward
0 new messages