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
Properties
Methods
Constructor Details
Creates a new Polyline object.
Sample:
require([
"esri/geometry/Polyline", "esri/SpatialReference", ...
], function(Polyline, SpatialReference, ... ) {
new Polyline(new SpatialReference({wkid:4326}));
...
});
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);
...
});
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)
Sample:
var singlePathPolyline = new Polyline([[-50, 0], [-120, -20], [-130, 0]]);
Property Details
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-vector",
center: [-122.45, 37.75], // longitude, latitude
zoom: 9
});
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;
}
});
});
});
An array of paths. Each path is made up of an array of two or more points.
The type of geometry.
Known values: point
| multipoint
| polyline
| polygon
| extent
Method Details
Adds a path to the Polyline. When added the index of the path is incremented by one.
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]]);
...
});
Sets the cache property to undefined
. (Added at v3.13)
Returns the value for a named property stored in the cache. (Added at v3.13)
Parameters:
<String > name |
Required |
The property name of the value to retrieve from the cache. |
Returns the extent of the Polyline.
Returns a point specified by a path and point in the path.
Parameters:
<Number > pathIndex |
Required |
The index of a path in a polyline. |
<Number > pointIndex |
Required |
The index of a point in a path. |
Inserts a new point into a polyline. (Added at v1.4)
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. |
Removes a path from the Polyline. The index specifies which path to remove.
Parameters:
<Number > pathIndex |
Required |
The index of a path to remove. |
Remove a point from the polyline at the given pointIndex within the path identified by the given pathIndex. (Added at v2.0)
Parameters:
<Number > pathIndex |
Required |
The index of the path containing the point. |
<Number > pointIndex |
Required |
The index of the point within the path. |
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. |
Updates a point in a polyline. (Added at v1.4)
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. |
Sets the spatial reference.