Document Maps JavaScript API Reference Manual Tool Category RectangleEditor

RectangleEditor

AMap.RectangleEditor

Construct a rectangle editing plugin object

new AMap.RectangleEditor(map: Map, rect: Rectangle?, opts: Object?)

Parameter

map (Map) Instance of AMap.Map

rect (Rectangle?) Instance of AMap.Rectangle

opts (Object?) Set parameters

Attribute

Type

Description

createOptions

Object?

Newly created object style

editOptions

Object?

Edit style

southWestPoint

Object?

Southwest point style MarkerOptions

northEastPoint

Object?

Northeast point style MarkerOptions

Demo

//Introduce the rectangle editor plugin
map.plugin(["AMap.RectangleEditor"], function () {
  //Instantiate the rectangle editor, passing in the map instance and the rectangle instance to be edited
  var rectangleEditor = new AMap.RectangleEditor(map, rectangle);
  //Enable edit mode
  rectangleEditor.open();
});

Method

setTarget(overlay?)

Set editing object

Parameteroverlay (Rectangle?) Edit object

Demo:

//Create a Rectangle instance
var rectangle = new AMap.Rectangle({
  bounds: new AMap.Bounds(
    new AMap.LngLat(116.356449, 39.859008),
    new AMap.LngLat(116.417901, 39.893797)
  ),
});
map.add(rectangle);
//Instantiate the rectangle editor, passing in the map instance and the rectangle instance to be edited
var rectangleEditor = new AMap.RectangleEditor(map);
//Set rectangle as the rectangular instance to be edited
rectangleEditor.setTarget(rectangle);
rectangleEditor.open();

getTarget()

Get editing object

return value: (Rectangle undefined) Current editing object

Demo:

rectangleEditor.getTarget();

open()

Start editing object

Demo:

rectangleEditor.open();

close()

Stop editing object

Demo:

rectangleEditor.close();

Event

Event Name

Description

adjust

This event is triggered when adjusting the rectangular range

move

This event is triggered when moving the overlay

add

This event is triggered after creating an overlay, and the target is the created object. When the editor's editing object is empty, calling the open interface and clicking the screen once will create a new overlay object

end

This event is triggered after calling close, and the target is the edited overlay object

For event object property descriptions, go to:MapsEvent