类名 SketchEditor

# new SketchEditor(options)

草图编辑基类

参数:

名称 类型 描述
options Object

构造参数

view MapView | SceneView

地图视图对象

layer GraphicsLayer

草图图层管对象

sketchStyle SketchStyle

草图符号

snapOption Object

草图捕获配置项

查看源代码 common/sketchEditor/base/SketchEditor.js, line 22

支持如下方法:
[1、开始绘制草图]
[2、停止绘制]
[3、移除当前草图]
[4、更新当前草图]
[5、向当前线或面草图中插入新的顶点]
[6、更新草图图形的某个顶点]
[7、移除草图图形的某个顶点]
[8、获取草图图形类型]
[9、设置草图样式]
[10、获取草图样式]
[11、获取草图几何对象]
[12、合并多个区几何]
[13、分割草图对象或区几何对象]
[14、撤销当前编辑操作]
[15、恢复被撤销的草图]
[16、拓扑线造区]

示例
// ES5引入方式
const { SketchEditor } = Zondy
// ES6引入方式
import { SketchEditor } from "@mapgis/webclient-common"

继承关系

成员变量

Number

# _drawTool

草图绘制工具

查看源代码 leaflet/sketchEditor/SketchEditorLeaflet.js, line 113

Number

# _drawTool

当前选中草图绘制工具

查看源代码 common/sketchEditor/base/SketchEditor.js, line 140

Number

# _sketchDataType

草图绘制类型

查看源代码 leaflet/sketchEditor/SketchEditorLeaflet.js, line 118

Number

# _sketchDataType

草图绘制类型

查看源代码 common/sketchEditor/base/SketchEditor.js, line 145

Number

# _sketchDataType

草图捕获工具

查看源代码 common/sketchEditor/base/SketchEditor.js, line 150

Number

# _sketchTopologyTool

草图拓扑分析工具

查看源代码 common/sketchEditor/base/SketchEditor.js, line 155

Number

# measureOption

草图量算配置项

查看源代码 leaflet/sketchEditor/SketchEditorLeaflet.js, line 108

Number

# measureOption

草图量算配置项

查看源代码 common/sketchEditor/base/SketchEditor.js, line 135

Number

# snapAndReferGeometries

捕获和线造区边界参考几何图形集合

查看源代码 common/sketchEditor/base/SketchEditor.js, line 127

Object

# snapOption Optional

草图捕获配置项

查看源代码 leaflet/sketchEditor/SketchEditorLeaflet.js, line 98

Object

# snapOption Optional

草图捕获配置项

查看源代码 common/sketchEditor/base/SketchEditor.js, line 117

Strign

# undoRedoManager

草图撤销回退管理器

查看源代码 common/sketchEditor/base/SketchEditor.js, line 160

方法

# addVertex(point, index)

向当前线或区草图中插入新的顶点

参数:

名称 类型 描述
point Point

新增/插入顶点

index Number

新增/新增点的序号

查看源代码 common/sketchEditor/base/SketchEditor.js, line 421

改变后的图形几何

Geometry

# canRedo()

草图是否可执行恢复操作

查看源代码 common/sketchEditor/base/SketchEditor.js, line 658

Boolean

# canUndo()

草图是否可执行撤销操作

查看源代码 common/sketchEditor/base/SketchEditor.js, line 650

Boolean

# drawPolylineToPolygon(snapAndReferGeometries)

线拓扑造区

参数:

名称 类型 描述
snapAndReferGeometries Array.<Polygon>

捕获参考几何对象数组

查看源代码 common/sketchEditor/base/SketchEditor.js, line 584

分割后的几何对象

Array.<Polygon>

# getGeometry()

获取草图几何对象

查看源代码 common/sketchEditor/base/SketchEditor.js, line 757

Geometry

# getSketchDataType()

获取草图图形类型

查看源代码 common/sketchEditor/base/SketchEditor.js, line 451

SketchDataType

# getSketchStyle()

获取草图样式

查看源代码 common/sketchEditor/base/SketchEditor.js, line 467

SketchStyle

# getSnapAndReferGeometries()

获取捕捉配置项

查看源代码 common/sketchEditor/base/SketchEditor.js, line 794

捕捉配置项

Array.<Geometry>

# getSnapOption()

获取捕捉配置项

查看源代码 common/sketchEditor/base/SketchEditor.js, line 778

捕捉配置项

Object

# off(typesopt, fnopt, contextopt)

参数:

名称 类型 描述
types string

移除指定事件类型上绑定的回调函数
当类型为字符串时,可以移除单个或多个事件类型绑定的回调函数,单个事件:"click",多个事件:以空格分割:"click double-click";
当types为对象时,使用如下方式移除事件:{'click': onClickFun, 'mouse-move': onMouseMoveFun}

fn function

事件回调函数,当types为字符串,且不指定要删除的回调函数时,删除该事件上的所有回调函数

context Object

事件回调函数的this关键字将指向的对象

Inherited From:

查看源代码 common/base/Evented.js, line 269

当前实例

Object
示例

移除一个事件的指定回调函数

// 一个事件的回调函数
const clickFunction = function (event) {
  console.log("点击事件:", event)
}
// 调用MapView或SceneView的off方法移除一个事件的回调函数
view.off('click', clickFunction)

移除一个事件的所有回调函数

// 一个事件的回调函数1
const clickFunction1 = function (event) {
  console.log("点击事件1:", event)
}

// 一个事件的回调函数2
const clickFunction2 = function (event) {
  console.log("点击事件2:", event)
}

// 调用MapView或SceneView的off方法移除一个事件的所有回调函数
// 不指定回调函数,则移除该事件上的所有绑定的回调函数
view.off('click')

移除多个事件的同一个指定的回调函数

// 多个事件的同一个回调函数
const eventFunction = function (event) {
  console.log("事件:", event)
}
// 调用MapView或SceneView的off方法移除多个事件的同一个指定的回调函数
view.off('click double-click', eventFunction)

移除多个指定事件的回调函数

// 一个事件的回调函数
const clickFunction = function (event) {
  console.log("click事件:", event)
}
// 调用MapView或SceneView的off方法移除多个指定事件的回调函数
view.off({
   // 移除click事件上一个指定的函数
  "click": clickFunction,
  // 移除double-click上所有指定的函数
  "double-click": undefined
})

删除时指定上下文 - types类型为字符串

// 一个事件的回调函数
const clickFunction = function (event) {
  console.log("点击事件:", event)
}
// 调用MapView或SceneView的off方法移除一个事件的回调函数
view.off('click', clickFunction, view)
// 调用MapView或SceneView的off方法移除一个事件的所有回调函数
view.off('click', undefined, view)

删除时指定上下文 - types类型为对象

// 一个事件的回调函数
const clickFunction = function (event) {
  console.log("click事件:", event)
}
// 调用MapView或SceneView的off方法移除多个指定事件的回调函数
view.off({
   // 移除click事件上一个指定的函数
  "click": clickFunction,
  // 移除double-click上所有指定的函数
  "double-click": undefined
}, view)

# on(typesopt, fnopt, contextopt)

参数:

名称 类型 默认值 描述
types String | Object null

事件类型
当types为字符串时,可以定义单个或多个事件,单个事件:"click",多个事件:以空格分割:"click double-click";
当types为对象时,使用如下方式指定事件:{'click': onClickFun, 'mouse-move': onMouseMoveFun}

fn function null

事件回调函数

context Object null

事件回调函数的this关键字将指向的对象

Inherited From:

查看源代码 common/base/Evented.js, line 173

当前实例

Object
示例

注册一个事件

// 初始化一个点击事件回调函数
const clickFunction = function (event) {
  console.log("点击事件:", event)
}
// 调用MapView或SceneView的on方法注册一个点击事件
view.on('click', clickFunction)

一次注册多个事件 - 同一个回调函数

// 初始化一个事件回调函数
const eventFunction = function (event) {
  console.log("事件:", event)
}

// 调用MapView或SceneView的on方法注册多个事件
// 多个事件类型使用同一个回调函数
view.on('click right-click-down', eventFunction)

一次注册多个事件 - 分别指回调应函数

// 初始化一个左键点击事件回调函数
const clickFunction = function (event) {
  console.log("click事件:", event)
}

// 初始化一个右键按下事件回调函数
const rightClickFunction = function (event) {
  console.log("right-click-down事件:", event)
}

// 调用MapView或SceneView的on方法注册多个事件
// 每一个事件类型,使用单独的回调函数
// 注意使用此种方式,一种类型的事件仅能指定一个回调函数
view.on({
  "click": clickFunction,
  "right-click-down": rightClickFunction
})

指定上下文 - types类型为字符串

// 初始化一个点击事件回调函数
const clickFunction = function (event) {
  console.log("点击事件:", event)
  console.log("上下文对象:", this)
}
// 调用MapView或SceneView的on方法注册一个点击事件
// 指定view为回调函数的上下文对象
view.on('click', clickFunction, view)

指定上下文 - types类型为对象

// 初始化一个点击事件回调函数
const clickFunction = function (event) {
  console.log("点击事件:", event)
  console.log("上下文对象:", this)
}
// 调用MapView或SceneView的on方法注册一个点击事件
// 指定view为回调函数的上下文对象
view.on({
  "click": clickFunction,
  "right-click-down": clickFunction
}, view)

# redo()

恢复被撤销的草图

查看源代码 common/sketchEditor/base/SketchEditor.js, line 636

恢复后的几何对象

Geometry

# removeVertex(index)

移除草图图形的某个顶点

参数:

名称 类型 描述
index Number

需更新的顶点的序号

查看源代码 common/sketchEditor/base/SketchEditor.js, line 442

改变后的图形几何

Geometry

# setSketchStyle(sketchStyle)

设置草图样式

参数:

名称 类型 描述
sketchStyle SketchStyle

查看源代码 common/sketchEditor/base/SketchEditor.js, line 459

# setSnapAndReferGeometries(geometries)

设置捕获和线造区边界参考几何图形集合

参数:

名称 类型 描述
geometries Array.<Geometry>

几何图形集合

查看源代码 common/sketchEditor/base/SketchEditor.js, line 786

# setSnapOption()

设置捕捉配置项

参数:

名称 类型 默认值 描述
snapOption.isSnapVertexCoincident Boolean false

是否自动捕捉顶点重合

snapOption.isSnapVertexInLine Boolean false

是否自动捕捉线上的点

snapOption.isSnapPerpendicular Boolean false

是否自动捕捉垂线垂点

snapOption.isSnapParallel Boolean false

是否自动捕捉平行线

snapOption.snapSketchGeometry Boolean false

是否捕捉正在绘制的图形的边界

查看源代码 common/sketchEditor/base/SketchEditor.js, line 769

# split(target, splitPolyline)

分割草图对象或区几何对象

参数:

名称 类型 描述
target Polygon | SketchEditor

被分割的几何/草图对象

splitPolyline Polyline

线几何对象

查看源代码 common/sketchEditor/base/SketchEditor.js, line 526

分割后的几何对象

Array.<Polygon>

# start(dataType)

开始(鼠标)绘制草图 根据传入绘制草图类型,开始鼠标绘制。
绘制点图形,鼠标单击即绘制。
绘制线图形,鼠标单击绘制线的一个顶点;鼠标移动,延长线图形;鼠标双击,完成线图形绘制。
绘制区图形,鼠标单击绘制区的一个顶点;鼠标移动,区图形随鼠标位置变动;鼠标双击,完成区图形绘制。

参数:

名称 类型 描述
dataType SketchDataType

绘制的草图类型

查看源代码 common/sketchEditor/base/SketchEditor.js, line 202

# undo()

撤销当前编辑操作

查看源代码 common/sketchEditor/base/SketchEditor.js, line 622

撤销后的几何对象

Geometry

# union(polygons)

合并多个区几何

参数:

名称 类型 描述
polygons Polygon

被合并的区几何对象

查看源代码 common/sketchEditor/base/SketchEditor.js, line 491

合并后的几何对象

Polygon

# updateVertex(point, index)

更新当前选中或区草图图形的某个顶点

参数:

名称 类型 描述
point Point

新的顶点

index Number

需更新的顶点的序号

查看源代码 common/sketchEditor/base/SketchEditor.js, line 432

改变后的图形几何

Geometry

事件

# 标绘制线或区的一个顶点完成事件

属性:
Name Type Attributes Default Description
event Object

事件对象

type LayerEventType <optional>
'drawn-vertex'

事件类型

geometry Geometry <optional>

绘制的几何对象

查看源代码 common/sketchEditor/base/SketchEditor.js, line 66

示例

鼠标绘制线或区的一个顶点完成事件

sketchEditor.on('drawn-vertex', (event) => {
  console.log("绘制的几何对象:", event.geometry)
})

# 草图绘制完成事件

属性:
Name Type Attributes Default Description
event Object

事件对象

type LayerEventType <optional>
'drawn'

事件类型

geometry Geometry <optional>

绘制的几何对象

查看源代码 common/sketchEditor/base/SketchEditor.js, line 56

示例

鼠标绘制完成事件

sketchEditor.on('drawn', (event) => {
  console.log("绘制的几何对象:", event.geometry)
})

# 草图被选中事件

属性:
Name Type Attributes Default Description
event Object

事件对象

type LayerEventType <optional>
'selected'

事件类型

selectedSketch SketchEditorLeaflet | SketchEditorCesium <optional>

被选中的草图对象

查看源代码 common/sketchEditor/base/SketchEditor.js, line 76

示例

草图被鼠标选中事件

sketchEditor.on('selected', (event) => {
  console.log("被选中事件:", event.selectedSketch)
})
构造函数
成员变量
方法
事件