Rectangle
AMap.Rectangle
Construct a rectangle object, specifying the rectangle style through RectangleOptions
new AMap.Rectangle(opts: RectangleOptions)Parameter
opts (RectangleOptions): Rectangle parameters
Demo
//Set the rectangular range, consisting of the latitude and longitude coordinates of the southwest and northeast corners
var southWest = new AMap.LngLat(100.456575, 13.74256); //Latitude and longitude coordinates of the southwest corner
var northEast = new AMap.LngLat(100.518716, 13.762569); //Latitude and longitude coordinates of the northeast corner
var bounds = new AMap.Bounds(southWest, northEast); //Create a latitude and longitude bounding box for a feature object
var rectangle = new AMap.Rectangle({
bounds: bounds,
});
map.add(rectangle);Method
contains(point)
determine whether the specified point coordinates are inside the rectangle
Parameter: point (LngLatLike) specified point coordinates
return value: (boolean) true (coordinates are inside the rectangle), false (coordinates are outside the rectangle)
Demo:
rectangle.contains(new AMap.LngLat(116.433322, 39.900255));setBounds(bounds)
Set the range of the rectangle
Parameter: bounds(Bounds) The range of the rectangle, composed of the latitude and longitude coordinates of the southwest and northeast
Demo:
//Set the rectangular range, consisting of the latitude and longitude coordinates of the southwest and northeast corners
var southWest = new AMap.LngLat(100.456575, 13.74256); //Latitude and longitude coordinates of the southwest corner
var northEast = new AMap.LngLat(100.518716, 13.762569); //Latitude and longitude coordinates of the northeast corner
var bounds = new AMap.Bounds(southWest, northEast); //Create a latitude and longitude bounding box for a feature object
rectangle.setBounds(bounds);setOptions(optsArg)
Modify rectangle properties (style, including nodes that compose the rectangle outline, outline style, etc.), setting the rectangle range is not supported
Parameter: optsArg (RectangleOptions) Properties of the rectangle
Demo:
rectangle.setOptions({
borderWeight: 3,
strokeColor: "#FF33FF",
});getPlaneHeight()
Get the current rectangular plane height value (This method is applicable to JSAPI 2.1Beta and above versions)
return value: (Number) The height value of the current plane
Demo:
rectangle.getPlaneHeight();hide()
Hide the rectangle
Demo:
rectangle.hide();setHeight(height)
Set the height of the rectangle above the ground (This method and the related property height are applicable to JSAPI v2.1Beta and above)
Parameter: height (Number) The height of the rectangle above the ground
Demo:
rectangle.setHeight(0);getCenter()
Get the center point of the rectangle
return value: (LngLat) Latitude and longitude information of the rectangle's center point
Demo:
rectangle.getCenter();show()
Display rectangle
Demo:
rectangle.show()getExtData()
Get user-defined properties
return value: (Object) The value set for the extData property, returns an empty object if not set
Demo:
rectangle.getExtData();setExtData(extData)
Set user-defined properties, supporting any data type in JavaScript API
Parameter: extData (Object) User-defined data
Demo:
rectangle.setExtData({id:1});destroy()
Destroy memory - rectangle
Demo:
rectangle.destroy();getArea()
Get the area of the rectangle, unit: square meters
return value: (number) Area of the rectangle
Demo:
rectangle.getArea();getOptions()
Get rectangle properties
return value: (RectangleOptions) Properties of Rectangle
Demo:
rectangle.getOptions();getPath()
Get Rectangle Outline Node Array
return value: (Array<LngLat> | Array<Array<LngLat>>) Return Path
Demo:
rectangle.getPath();Event
For event object property descriptions, go to:MapsEvent