Developer
Developer

Reputation: 265

Changing the Length of drawn polyline : leaflet

I am fairly new in using leaflet. Can someone tell me how to change the length of already drawn polyline in leaflet?. I want to make its length small or large depending on zoom level.

Upvotes: 0

Views: 912

Answers (1)

Anton Stepanenkov
Anton Stepanenkov

Reputation: 1036

Leaflet polyline is a array of points, each of them consist of lat and lng. To change it's size you need to update this array and change distance between points width setLatLngs() method.

If you want to fit the screen you need to get screen bounding box width map.getBounds() get lat or lng from bbox and update your line width it.

So it will be something like this:

 map.on('zoomend', function(){
   var bounds = map.getBounds();
   line.setLatLngs(bounds[0],bounds[1]);
 })

Upvotes: 1

Related Questions