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

require(["esri/geometry/Polyline"], function(Polyline) { /* code goes here */ });

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 Polyline(spatialReference)Creates a new Polyline object.
new Polyline(json)Creates a new Polyline object using a JSON object.
new 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 Polyline(spatialReference)

Creates a new Polyline object.
Parameters:
<SpatialReference> spatialReference Required Spatial reference of the geometry.
Sample:
require([
  "esri/geometry/Polyline", "esri/SpatialReference", ... 
], function(Polyline, SpatialReference, ... ) {
  new Polyline(new SpatialReference({wkid:4326}));
  ...
});

new Polyline(json)

Creates a new Polyline object using a JSON object.
Parameters:
<Object> json Required JSON object representing the geometry.
Sample:
require([
  "esri/geometry/Polyline", ... 
], function(Polyline, ... ) {
  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 Polyline(polylineJson);
  ...
});

new 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.
Sample:
var singlePathPolyline = new Polyline([[-50, 0], [-120, -20], [-130, 0]]);
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
Sample:
var map;

require([
  "esri/InfoTemplate",
  "esri/layers/FeatureLayer",
  "esri/map",
  "esri/tasks/query", "dojo/domReady!"
], function (InfoTemplate, FeatureLayer, Map, Query){

  map = new Map("map", {
    basemap: "topo",
    center: [-122.45, 37.75], // longitude, latitude
    zoom: 10
  });

  var infoTemplate = new InfoTemplate("Attributes", "${*}");

  var countiesFeatureLayer = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/3",
    {
      mode: FeatureLayer.MODE_ONDEMAND,
      infoTemplate: infoTemplate,
      outFields: ['*']
    });
  var highwaysFeatureLayer = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/1",
    {
      mode: FeatureLayer.MODE_ONDEMAND,
      infoTemplate: infoTemplate,
      outFields: ['*']
    });

  map.on("load", function (){
    map.addLayer(countiesFeatureLayer);
    map.addLayer(highwaysFeatureLayer);

    var query = new Query();
    query.geometry = map.extent;
    query.spatialRelationship = Query.SPATIAL_REL_ENVELOPEINTERSECTS;
    query.returnGeometry = true;
    query.outFields = ["*"];

    countiesFeatureLayer.queryFeatures(query, function (featureSet){
      var polygon = featureSet.features[0].geometry;
      // populate the Geometry cache by calling getExtent()
      var polygonExtent = polygon.getExtent();
      console.log("polygonExtent", polygonExtent);
      console.log("polygon.cache._extent", polygon.cache._extent);

      for (var i = 0; i < featureSet.features.length; i  ) {
        var feature = featureSet.features[i];
        console.log("Polygon geometry cache, %o", feature.geometry.cache);
        feature.geometry.clearCache();
        console.log("Polygon geometry clear cache, %o", feature.geometry.cache);
        // Break out of the loop after the first result
        break;
      }
    });

    highwaysFeatureLayer.queryFeatures(query, function (featureSet){
      var line = featureSet.features[0].geometry;
      // populate the Geometry cache by calling getExtent()
      var lineExtent = line.getExtent();
      console.log("lineExtent", lineExtent);
      console.log("line.cache._extent", line.cache._extent);

      for (var i = 0; i < featureSet.features.length; i  ) {
        var feature = featureSet.features[i];
        console.log("Line geometry cache, %o", feature.geometry.cache);
        feature.geometry.clearCache();
        console.log("Line geometry clear cache, %o", feature.geometry.cache);
        // Break out of the loop after the first result
        break;
      }
    });

  });
});

<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:
require([
  "esri/geometry/Point", ... 
], function(Point, ... ) {
Adding a path using Points:
  polyline.addPath([new Point(10,10), new Point(20,20), new 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