Skip to content

ShapeEdit ​

ShapeEdit ​

图形编辑器
注:目前仅测试版本(1.0.1)支持

Examples ​

javascript
// 以编辑多边形Polygon为例
window.DiMapLoader.load({
    key: "您申请的key",
    plugins: ["ShapeEdit"],
}).then(({ DiMap }) => {
    // 添加 控制按钮
    const anchor = document.createElement("div")
    anchor.className = "control"
    anchor.style.zIndex = "9999"
    anchor.innerHTML = "多边形"
    anchor.style.position = "absolute"
    anchor.style.top = "10px"
    anchor.style.left = "10px"        
    const mapContainer = map.getContainer()
    mapContainer.appendChild(anchor)

    // 创建图形编辑器
    const shapeEdit = new DiMap.ShapeEdit(map)

    anchor.onclick = () => {
      // 多边形编辑+吸附
      // 可编辑图形:多边形 Polygon、圆 Circle、线段 Line、矩形 Rectangle
      shapeEdit.edit("Polygon") 
    }
})

constructor ​

Parameters ​

参数名必选类型描述
map是Map地图实例
options否ShapeEditOptions编辑选项
ShapeEditOptions ​
参数名必选类型描述
middlePointState是"showing" | "default"中间点显示状态

edit ​

启动或结束编辑

Parameters ​

参数名必选类型描述
type是string编辑类型 "Polygon" | "Line" | "Circle" | "Rectangle"
options否EditOptions可选参数对象,默认值为 {}
EditOptions ​
参数名必选类型描述
editColor否string编辑颜色
doneColor否string完成颜色
shouldAdsor否boolean是否吸附
initCoords否[number, number][]初始坐标数组

Returns void

remove ​

删除选中的图形

Returns void

clearAll ​

删除地图上所有图形

Returns void

getSelectedPoints ​

获得当前编辑图形的点串

Returns (Array<[number, number]> | undefined)