How to draw polyline using leaflet

For creating polyline we need to have at least two points.

So we first create two points.

    var point1 = new L.LatLng(50.5, 77.00);
    var point2 = new L.LatLng(51.5, 78);

Polyline needs an array of points to be entered, so will create array for this points.

var pointsArray = [point1, point2];

Now we will create between these two points.

var myPolyLine = new L.Polyline(pointsArray).addTo(map);

We can add different properties like weight, colour, opacity, smoothFactor, etc. to polyline also.
See bellow example

var myPolyLine = new L.Polyline(pointsArray, {
color: 'red',
weight: 3,
opacity: 1,
smoothFactor: 1


  • Ladislav

    Nice, it is easy, but how to make more polylines and after delete one, more or all…?