Document Maps JavaScript API Reference Manual Tool Category PolygonEditor

PolygonEditor

AMap.PolygonEditor 

Polygon editing plugin, used to edit AMap.Polygon objects, supports adjusting the shape of polygons with the mouse. Construct a polygon editing plugin object.

new AMap.PolygonEditor(map: Map, polygon: Polygon?, opts: Object?)

Parameter

map (Map): Map instance

polygon (Polygon?): Edit object

opts (Object?): Set parameters

Attribute

Type

Description

createOptions

Object?

Newly created object style

editOptions

Object?

Edit style

controlPoint

Object?

Vertex style CircleMarkerOptions

midControlPoint

Object?

Midpoint style CircleMarkerOptions

Demo

//Import the polygon editor plugin
map.plugin(["AMap.PolygonEditor"], function () {
  //Instantiate the polygon editor, passing in the map instance and the polygon instance to be edited
  var polygonEditor = new AMap.PolygonEditor(map, polygon);
  //Enable Editing Mode
  polygonEditor.open();
});

Method

open()

Start Editing Object

Demo:

polygonEditor.open();

setTarget(tar, overlay)

Set Editing Object

Parameter:

tar (anyInstantiated Object of Editing

overlay (Polygon) Set Editing Style

Demo:

//Create a Polygon instance
var path = [
  new AMap.LngLat(116.368904, 39.913423),
  new AMap.LngLat(116.387271, 39.912501),
  new AMap.LngLat(116.398258, 39.9046),
];
var polygon = new AMap.Polygon({ path: path });
map.add(polygon);
//Instantiate the polygon editor, passing in the map instance and the polygon instance to be edited
var polygonEditor = new AMap.PolygonEditor(map);
//Set polygon as the polygon instance to be edited
polygonEditor.setTarget(polygon);
polygonEditor.open();

getTarget()

Get editing object

return value: (Polygon undefined) Polygon editing object

Demo:

polygonEditor.getTarget();

setAdsorbPolygons(list)

Set Snapping Polygon

Parameterlist (Polygon | Array<Polygon>)

Demo:

polygonEditor.setAdsorbPolygons([polygon1, polygon2]); //polygon1, polygon2 为多边形实例

clearAdsorbPolygons()

Clear All Snapping Polygons

Demo:

polygonEditor.clearAdsorbPolygons();

addAdsorbPolygons(list)

Add Snapping Polygon

Parameterlist (Polygon | Array<Polygon>)

Demo:

polygonEditor.addAdsorbPolygons([polygon1, polygon2]); //polygon1, polygon2 为多边形实例

removeAdsorbPolygons(list)

Delete Snapping Polygon

Parameterlist (Polygon | Array<Polygon>)

Demo:

polygonEditor.removeAdsorbPolygons(polygon1);

close()

Stop Editing Object

Demo:

polygonEditor.close();

Event

Event Name

Description

addnode

This event is triggered when adding a node

removenode

This event is triggered when removing a node

adjust

This event is triggered when adjusting a point on the polygon

add

This event is triggered after creating an overlay, and the target is the created object. When the editor's editing object is empty, call the open interface, and then click the screen again to 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