Document Maps JavaScript API Advanced Tutorial Line Polyline Editing Plugin

Polyline Editing Plugin

AMap.Polyline Editor Plugin,supports modifying existing polylines or dynamically drawing polylines directly on the map,allowing real-time editing and drawing by interactively adjusting the shape of the polyline.

Polyline Editing Example

After clicking to create a new Polyline, click anywhere on the map to start drawing the polyline.

1、Polyline Editor Polyline

1

1.1 Create a Polyline instance and add it to the Map

const map = new AMap.Map("container", {
  zoom: 10, 
  center: [100.491422, 13.749313],
  showOversea: true, //Enable world Map
  mapStyle: "amap://styles/whitesmoke", 
  viewMode: "2D", 
});
//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),
];
var polyline = new AMap.Polyline({
  path: path,
  strokeWeight: 2, 
  strokeColor: "red", 
  lineJoin: "round", //Polyline turning point connection style
});
map.add(polyline);
2

1.2 Construct the polyline editing object and enable the editing state of the polyline

//Import the polyline editor plugin
map.plugin(["AMap.PolylineEditor"], function () {
  //Instantiate the polyline editor, passing in the map instance and the polyline instance to be edited
  polylineEditor = new AMap.PolylineEditor(map, polyline);
  //Enable edit mode
  polylineEditor.open();
});
Prompt

polylineEditor.open() is the method to start editing an object, if you want to end the editing you can call the polylineEditor.close()method.