类名 SketchEditor3D

# new SketchEditor3D(options)

参数:

名称 类型 描述
options Object

构造参数

elevationInfo MapView | SceneView

草图图形高程模式参数

继承关系

成员变量

Boolean

# editable

草图是否可编辑。默认值为true,可编辑

Inherited From:
ElevationInfo

# elevationInfo

高程模式参数

Boolean

# isSimple

草图是否进行拓扑检查。默认值为false,不进行拓扑检查

Inherited From:
GraphicsLayer

# layer

草图图形图层

Inherited From:
Number

# measureOption

草图量算配置项

Inherited From:
Number

# sketchDataType

草图绘制类型

Inherited From:
SketchStyle

# sketchStyle

草图样式

Inherited From:
Array.<Geometry>

# snapAndReferGeometries

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

Inherited From:
Object

# snapOption Optional

草图捕获配置项

Inherited From:
MapView | SceneView

# view

地图视图

Inherited From:

方法

# addVertex(point, index)

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

参数:

名称 类型 描述
point Point

新增/插入顶点

index Number

新增/新增点的序号

Inherited From:

改变后的图形几何

Geometry

# canRedo()

草图是否可执行恢复操作

Inherited From:
Boolean

# canUndo()

草图是否可执行撤销操作

Inherited From:
Boolean

# destroy()

销毁草图编辑器

Inherited From:

# drawPolylineToPolygon(snapAndReferGeometries)

线拓扑造区

参数:

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

捕获参考几何对象数组

Inherited From:

分割后的几何对象

Array.<Polygon>

# getGeometry()

获取草图几何对象

Inherited From:
Geometry

# getSketchDataType()

获取草图图形类型

Inherited From:
SketchDataType

# getSketchStyle()

获取草图样式

Inherited From:
SketchStyle

# getSnapAndReferGeometries()

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

Inherited From:

捕捉配置项

Array.<Geometry>

# getSnapOption()

获取捕捉配置项

Inherited From:

捕捉配置项

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:

当前实例

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:

当前实例

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()

恢复被撤销的草图

Inherited From:

恢复后的几何对象

Geometry

# remove()

移除当前草图

Inherited From:

# removeVertex(index)

移除当前选中的线或区草图图形的某个顶点

参数:

名称 类型 描述
index Number

需更新的顶点的序号

Inherited From:

改变后的图形几何

Geometry

# setSketchStyle(sketchStyle)

设置草图样式

参数:

名称 类型 描述
sketchStyle SketchStyle
Inherited From:

# setSnapAndReferGeometries(geometries)

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

参数:

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

几何图形集合

Inherited From:

# setSnapOption()

设置捕捉配置项

参数:

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

是否自动捕捉顶点重合

snapOption.isSnapVertexInLine Boolean false

是否自动捕捉线上的点

snapOption.isSnapPerpendicular Boolean false

是否自动捕捉垂线垂点

snapOption.isSnapParallel Boolean false

是否自动捕捉平行线

snapOption.snapSketchGeometry Boolean false

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

snapOption.pixelTolerance Number 10

捕获像素容差

Inherited From:

# split(target, splitPolyline)

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

参数:

名称 类型 描述
target Polygon | SketchEditor

被分割的几何/草图对象

splitPolyline Polyline

线几何对象

Inherited From:

分割后的几何对象

Array.<Polygon>

# start(data, extensionOptions)

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

参数:

名称 类型 描述
data SketchDataType | Geometry

绘制的草图类型或几何对象

extensionOptions Object

草图编辑的扩展属性,可以通过该属性传入草图编辑额外需要的参数

vertexNumber Number

绘制线/区时的顶点限制数量。(例如绘制直线,则vertexNumber=2;绘制直三角形,则vertexNumber=3。)

Inherited From:

# startCustomDrawTool(CustomDrawTool)

开始(鼠标)绘制自定义草图图形

参数:

名称 类型 描述
CustomDrawTool Class.<SketchBaseDrawTool>

自定义草图图形工具类

Inherited From:

# stop()

停止鼠标绘制草图

Inherited From:

# undo()

撤销当前编辑操作

Inherited From:

撤销后的几何对象

Geometry

# union(polygons)

合并多个区几何

参数:

名称 类型 描述
polygons Polygon

被合并的区几何对象

Inherited From:

合并后的几何对象

Polygon

# updateVertex(point, index)

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

参数:

名称 类型 描述
point Point

新的顶点

index Number

需更新的顶点的序号

Inherited From:

改变后的图形几何

Geometry

事件

# 创建草图图形时事件

属性:
Name Type Description
event SketchEditorEvent

事件消息体对象

Inherited From:
示例

创建草图图形时事件

sketchEditor.on('create', (event) => {
  console.log("被选中事件:", event)
})

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

属性:
Name Type Attributes Default Description
event Object

事件对象

type LayerEventType <optional>
'drawn-vertex'

事件类型

geometry Geometry <optional>

绘制的几何对象

Inherited From:
示例

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

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

# 移除草图图形事件

属性:
Name Type Description
event SketchEditorEvent

事件消息体对象

Inherited From:
示例

移除草图图形事件

sketchEditor.on('remove', (event) => {
  console.log("被选中事件:", event)
})

# 编辑草图图形时事件

属性:
Name Type Description
event SketchEditorEvent

事件消息体对象

Inherited From:
示例

编辑草图图形时事件

sketchEditor.on('update', (event) => {
  console.log("编辑图形时事件:", event)
})

# 草图绘制完成事件

属性:
Name Type Attributes Default Description
eventName SketchEditorEventType <optional>

事件类型

event Object

事件对象

toolEventInfo Object <optional>
null

事件类型

toolEventInfo.type SketchEditorToolEventType <optional>
null

草图编辑工具事件类型

state SketchEditorState <optional>
SketchEditorState.create

创建或编辑时,草图图形子状态

feature Feature <optional>
null

要素对象

geometry Geometry <optional>

几何对象

Inherited From:
示例

鼠标绘制完成事件

sketchEditor.on(SketchEditorEventType.create, (event) => {
  console.log("绘制的要素对象:", event.feature)
})

# 草图绘制完成事件(废弃)

属性:
Name Type Attributes Default Description
event Object

事件对象

type LayerEventType <optional>
'drawn'

事件类型

geometry Geometry <optional>

绘制的几何对象

Inherited From:
示例

鼠标绘制完成事件

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

# 草图编辑器回退事件

属性:
Name Type Description
event SketchEditorEvent

事件消息体对象

Inherited From:
示例

草图编辑器回退事件

sketchEditor.on('redo', (event) => {
  console.log("被选中事件:", event.selectedSketch)
})

# 草图编辑器撤销事件

属性:
Name Type Description
event SketchEditorEvent

事件消息体对象

Inherited From:
示例

草图编辑器撤销事件

sketchEditor.on('undo', (event) => {
  console.log("被选中事件:", event)
})

# 草图被选中事件(废弃)

属性:
Name Type Attributes Default Description
event Object

事件对象

type LayerEventType <optional>
'selected'

事件类型

selectedSketch SketchEditorLeaflet | SketchEditorCesium <optional>

被选中的草图对象

Inherited From:
示例

草图被鼠标选中事件

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