Polyline
Polyline
Construct a polyline object and specify its style via PolylineOptions
new AMap.Polyline(opts:PolylineOptions )Parameter
opts (PolylineOptions): Polyline parameters
Demo
//Configure polyline path
var path = [
new AMap.LngLat(100.207151, 13.965977),
new AMap.LngLat(100.286802, 13.648579),
new AMap.LngLat(100.771573, 13.681939),
new AMap.LngLat(100.823758, 13.804665),
];
//Create Polyline instance
var polyline = new AMap.Polyline({
path: path,
strokeWeight: 2,
strokeColor: "red",
lineJoin: "round",
});
map.add(polyline);Method
hide()
Hide polyline
Demo:
polyline.hide();show()
Show polyline
Demo:
polyline.show();getExtData()
Get user-defined attributes
return value: (Object) The value set in the extData property, returns an empty object if not set
Demo:
polyline.getExtData();getOptions()
Get the properties of the line
return value: (PolylineOptions) Properties of the line
Demo:
polyline.getOptions();getPath()
Get the array of nodes in the polyline path
return value: (Array<LngLat> | Array<Array<LngLat>>) Array of nodes in the polyline path
Demo:
polyline.getPath();setExtData(extData)
Set User-Defined Properties, Supporting Any Data Type in JavaScript API
Parameter: extData (Object) User-Defined Data
Demo:
polyline.setExtData({id:1});setHeight(height)
Set Polyline Height Above Ground (This method and related property height are applicable to JSAPI v2.1Beta and above)
Parameter: height (number) Polyline Height Above Ground
Demo:
polyline.setHeight(0);destroy()
Destroy Memory - Polyline
Demo:
polyline.destroy();getBounds()
Get the rectangular range object of the current polyline
return value: (Bounds) The rectangular range that completely contains the polyline (latitude and longitude coordinates of the southwest and northeast corners)
Demo:
polyline.getBounds();setPath(path?)
Set the node array that composes this polyline, supports single polyline (LngLatLike[]) and multiple polylines (LngLatLike[][])
Parameter: path (Array<LngLatLike> | Array<Array<LngLatLike>>) Polyline path, supports lineString and MultiLineString
Demo:
var path = [
new AMap.LngLat(116.368904, 39.913423),
new AMap.LngLat(116.382122, 39.901176),
new AMap.LngLat(116.387271, 39.912501),
new AMap.LngLat(116.398258, 39.9046),
];
polyline.setPath(path);moveWithPos(dx, dy)
Set the movement position of the line
Parameter:
dx (number) The distance moved on the x-axis (horizontal direction), where positive values indicate movement to the right and negative values indicate movement to the left
dy (number) The distance moved on the y-axis (vertical direction), where positive values indicate upward movement and negative values indicate downward movement
Demo:
polyline.moveWithPos(10, 10);getLength(isTerrain)
Get the total length of the polyline (in meters)
Parameter: isTerrain (boolean) Whether to measure distance based on terrain. Default: false
return value: (number) Return the total length of the polyline
Demo:
polyline.getLength(false);setOptions(optsArg)
Modify polyline properties (including nodes of the path, line style, whether to draw a geodesic line, etc. For details of the properties, refer to the PolylineOptions list). Modifying the path is not supported. To modify the path, call the setPath(path) method
Parameter: optsArg (PolylineOptions) Configured polyline properties
Demo:
polyline.setOptions({
strokeWeight: 5,
strokeColor: "#000",
});contains(point)
Determine whether the coordinate is within the polyline
Parameter: point(Vector2 | LngLat) The coordinate point to be judged, such as: AMap.LngLat(116.39,39.9) or [116.39, 39.9]
return value: (boolean) true included, false not included
Demo:
polyline.contains(new AMap.LngLat(116.39, 39.9));getPolylineHeight()
Get the current elevation value of Polyline (This method is applicable to JSAPI 2.1Beta and above)
return value: (number) Elevation value of Polyline
Demo:
polyline.getPolylineHeight();Event
For event object property descriptions, go to:MapsEvent