Legacy
Mapbox.js is no longer in active development. To learn more about our newer mapping tools see Mapbox GL JS.
Polyline
A class for drawing polyline overlays on a map. Extends Path. Use Map#addLayer to add it to the map.
Usage example
// create a red polyline from an arrays of LatLng points
var polyline = L.polyline(latlngs, {color: 'red'}).addTo(map);
// zoom the map to the polyline
map.fitBounds(polyline.getBounds());
Creation
Factory | Description |
---|---|
L.polyline(
|
Instantiates a polyline object given an array of geographical points and optionally an options object. |
Options
You can use Path options and additionally the following options:
Option | Type | Default | Description |
---|---|---|---|
smoothFactor |
Number |
1.0 |
How much to simplify the polyline on each zoom level. More means better performance and smoother look, and less means more accurate representation. |
noClip |
Boolean |
false |
Disabled polyline clipping. |
Methods
You can use Path methods and additionally the following methods:
Method | Returns | Description |
---|---|---|
addLatLng(
|
this |
Adds a given point to the polyline. |
setLatLngs(
|
this |
Replaces all the points in the polyline with the given array of geographical points. |
getLatLngs() |
LatLng[] |
Returns an array of the points in the path. |
spliceLatLngs(
|
LatLng[] |
Allows adding, removing or replacing points in the polyline. Syntax is the same as in Array#splice. Returns the array of removed points (if any). |
getBounds() |
LatLngBounds |
Returns the LatLngBounds of the polyline. |
toGeoJSON() |
Object |
Returns a GeoJSON representation of the polyline (GeoJSON LineString Feature). |