Skip to content

ym.modules.provider.Polyline

Overview

This class is used to draw polylines on a map. It extends the class Path. Use Map.addLayer() to add a polyline to the map.

Example calls

// Create a red polyline from an array of LatLng points.
var polyline = ym.polyline(latlngs, {color: 'red'}).addTo(map);

// Zoom the map to the polyline.
map.fitBounds(polyline.getBounds());

Initialization

Factory: ym.polyline(latlngs, options)

Instantiates a polyline object with an array of geographic points and optionally an Options object.

Parameter Description Data type Default value
latlngs [required] LatLng[]
options [optional] PolylineOptions

Parameter: options

You can use Path-options and additionally the following options:

Name Description Data type Default value
smoothFactor Specifies how much the polyline should be simplified at each zoom level. More means better performance and smoother appearance, and less means more accurate display. int 1.0
noClip Disables the cutting of polylines. bool false

Methods

addLatLng(latlng)

Adds a specific point to the polyline.

Parameter Description Data type Default value
latlng LatLng
  • Return: this

setLatLngs(latlngs)

Replaces all points in the polyline with the specified array of geographic points.

Parameter Description Data type Default value
latlngs LatLng[]
  • Return: this

getLatLngs()

Returns an array of points in the path.

  • Return: LatLng[]

spliceLatLngs(index, pointsToRemove, latlng)

Allows to add, remove or replace points in the polyline. The syntax is the same as in Array.splice. Returns the array of removed points (if any).

Parameter Description Data type Default value
index [required] int
pointsToRemove [required] int
latlng [optional] LatLng
  • Return: LatLng[]

getBounds()

Returns the LatLngBounds of the polyline.

  • Return: LatLngBounds

toGeoJSON()

Returns a GeoJSON representation of the polyline (GeoJSON LineString feature).

  • Return: object