Hide Table of Contents
esri/dijit/util
esri/layer/pixelFilters
esri/process
esri/support
esri/workers
Class: Polyline

dojo.require("esri.geometry.Polyline")

Description

(Added at v1.0)
An array of paths where each path is an array of points.

Samples

Search for samples that use this class.

Class hierarchy

esri/geometry.Geometry
|_esri/geometry.Polyline

Constructors

NameSummary
new esri.geometry.Polyline(spatialReference)Creates a new Polyline object.
new esri.geometry.Polyline(json)Creates a new Polyline object using a JSON object.
new esri.geometry.Polyline(coordinates)Create a new polyline by providing an array of geographic coordinates.

Properties

NameTypeSummary
cacheObjectThe cache is used to store values computed from geometries that need to cleared or recomputed upon mutation.
pathsNumber[][][]An array of paths.
spatialReferenceSpatialReferenceThe spatial reference of the geometry.
typeStringThe type of geometry.

Methods

NameReturn typeSummary
addPath(path)PolylineAdds a path to the Polyline.
clearCache()NoneSets the cache property to undefined.
getCacheValue(name)ObjectReturns the value for a named property stored in the cache.
getExtent()ExtentReturns the extent of the Polyline.
getPoint(pathIndex, pointIndex)PointReturns a point specified by a path and point in the path.
insertPoint(pathIndex, pointIndex, point)PolylineInserts a new point into a polyline.
removePath(pathIndex)Point[]Removes a path from the Polyline.
removePoint(pathIndex, pointIndex)PointRemove a point from the polyline at the given pointIndex within the path identified by the given pathIndex.
setCacheValue(name, value)NoneSets the value for a named property stored in the cache.
setPoint(pathIndex, pointIndex, point)PolylineUpdates a point in a polyline.
setSpatialReference(sr)GeometrySets the spatial reference.
toJson()ObjectConverts object to its ArcGIS Server JSON representation.
Constructor Details

new esri.geometry.Polyline(spatialReference)

Creates a new Polyline object.
Parameters:
<SpatialReference> spatialReference Required Spatial reference of the geometry.
Sample:

new esri.geometry.Polyline(new esri.SpatialReference({wkid:4326}));

new esri.geometry.Polyline(json)

Creates a new Polyline object using a JSON object.
Parameters:
<Object> json Required JSON object representing the geometry.
Sample:

var polylineJson = {

  "paths":[[[-122.68,45.53], [-122.58,45.55],

  [-122.57,45.58],[-122.53,45.6]]],

  "spatialReference":{"wkid":4326}

};



var polyline = new esri.geometry.Polyline(polylineJson);

new esri.geometry.Polyline(coordinates)

Create a new polyline by providing an array of geographic coordinates. For a single path polyline provide an array of coordinate pairs. For a multi-path polyline provide an array of array coordinate pairs. (Added at v3.6)
Parameters:
<Number[][] | Number[][][]> coordinates Required An array of geographic coordinates that define the polyline.
Property Details

<Object> cache

The cache is used to store values computed from geometries that need to cleared or recomputed upon mutation. An example is the extent of a polygon. The default value is undefined. (Added at v3.13)
Default value: undefined

<Number[][][]> paths

An array of paths. Each path is made up of an array of two or more points.
See also: addPath()

<SpatialReference> spatialReference

The spatial reference of the geometry. See Projected Coordinate Systems and Geographic Coordinate Systems for the list of supported spatial references.

<String> type

The type of geometry.
Known values: point | multipoint | polyline | polygon | extent
Method Details

addPath(path)

Adds a path to the Polyline. When added the index of the path is incremented by one.
Return type: Polyline
Parameters:
<Point[] | Number[][]> path Required Path to add to the Polyline. Can be one of the following: an array of numbers or an array of points.
Sample:

Adding a path using Points:

polyline.addPath([new esri.geometry.Point(10,10), new esri.geometry.Point(20,20), new esri.geometry.Point(30,30)]);

Adding a path using an array of x,y coordinate pairs:

polyline.addPath([[-122.68,45.53], [-122.58,45.55],  [-122.57,45.58],[-122.53,45.60]]);
See also: paths

clearCache()

Sets the cache property to undefined. (Added at v3.13)

getCacheValue(name)

Returns the value for a named property stored in the cache. (Added at v3.13)
Return type: Object
Parameters:
<String> name Required The property name of the value to retrieve from the cache.

getExtent()

Returns the extent of the Polyline.
Return type: Extent

getPoint(pathIndex, pointIndex)

Returns a point specified by a path and point in the path.
Return type: Point
Parameters:
<Number> pathIndex Required The index of a path in a polyline.
<Number> pointIndex Required The index of a point in a path.

insertPoint(pathIndex, pointIndex, point)

Inserts a new point into a polyline. (Added at v1.4)
Return type: Polyline
Parameters:
<Number> pathIndex Required Path index to insert point.
<Number> pointIndex Required The index of the inserted point in the path.
<Point> point Required Point to insert into the path.

removePath(pathIndex)

Removes a path from the Polyline. The index specifies which path to remove.
Return type: Point[]
Parameters:
<Number> pathIndex Required The index of a path to remove.

removePoint(pathIndex, pointIndex)

Remove a point from the polyline at the given pointIndex within the path identified by the given pathIndex. (Added at v2.0)
Return type: Point
Parameters:
<Number> pathIndex Required The index of the path containing the point.
<Number> pointIndex Required The index of the point within the path.

setCacheValue(name, value)

Sets the value for a named property stored in the cache. (Added at v3.13)
Parameters:
<String> name Required The property name for the value Object to store in the cache.
<Object> value Required The value Object for a named property to store in the cache.

setPoint(pathIndex, pointIndex, point)

Updates a point in a polyline. (Added at v1.4)
Return type: Polyline
Parameters:
<Number> pathIndex Required Path index for updated point.
<Number> pointIndex Required The index of the updated point in the path.
<Point> point Required Point to update in the path.

setSpatialReference(sr)

Sets the spatial reference.
Return type: Geometry
Parameters:
<SpatialReference> sr Required Spatial reference of the geometry.

toJson()

Converts object to its ArcGIS Server JSON representation.
Return type: Object
Show Modal