new SketchEditor(options)
支持如下方法:
[1、开始绘制草图][2、停止绘制]
[3、移除当前草图]
[4、更新当前草图]
[5、向当前线或面草图中插入新的顶点]
[6、更新草图图形的某个顶点]
[7、移除草图图形的某个顶点]
[8、获取草图图形类型]
[9、设置草图样式]
[10、获取草图样式]
[11、获取草图几何对象]
[12、合并多个区几何]
[13、分割草图对象或区几何对象]
[14、撤销当前编辑操作]
[15、恢复被撤销的草图]
[16、拓扑线造区]
草图编辑基类
| Name | Type | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
构造参数
|
|||||||||||||||||||||
snapOption.isSnapVertexCoincident |
Boolean | false |
可选
是否自动捕捉顶点重合 |
||||||||||||||||||||
snapOption.isSnapVertexInLine |
Boolean | false |
可选
是否自动捕捉线上的点 |
||||||||||||||||||||
snapOption.isSnapPerpendicular |
Boolean | false |
可选
是否自动捕捉垂线垂点 |
||||||||||||||||||||
snapOption.isSnapParallel |
Boolean | false |
可选
是否自动捕捉平行线 |
||||||||||||||||||||
snapOption.snapSketchGeometry |
Boolean | false |
可选
是否捕捉正在绘制的图形的边界 |
||||||||||||||||||||
snapOption.pixelTolerance |
Number | 10 |
可选
捕捉像素容差 |
||||||||||||||||||||
options.editable |
Boolean | true |
可选
草图是否可编辑 |
||||||||||||||||||||
options.editOption |
Object |
可选
草图编辑配置项。默认开启图形整体编辑和顶点编辑
|
|||||||||||||||||||||
options.isSimple |
Boolean | false |
可选
草图是否进行拓扑检查 |
||||||||||||||||||||
options.isShowTip |
Boolean | true |
可选
是否显示草图提示文字。默认值为true,显示提示文字 |
Example
// ES5引入方式
const { SketchEditor } = zondy.tool.sketch
// ES6引入方式
import { SketchEditor } from "@mapgis/webclient-common"
Extends
Members
-
editableBoolean
-
草图是否可编辑。默认值为true,可编辑
-
editOptionObject
-
草图编辑配置项。默认开启图形整体编辑和顶点编辑
-
isShowTipBoolean
-
是否显示草图提示文字。默认值为true,显示提示文字
-
isSimpleBoolean
-
草图是否进行拓扑检查。默认值为false,不进行拓扑检查
-
layerGraphicsLayer
-
草图图形图层
-
measureOptionNumber
-
草图量算配置项
-
sketchDataTypeNumber
-
草图绘制类型
-
sketchStyleSketchStyle
-
草图样式
-
snapAndReferGeometriesArray.<Geometry>
-
捕获和线造区边界参考几何图形集合
-
snapOptionObject
-
草图捕获配置项
-
地图视图
Events
-
创建草图图形时事件
sketchEditor/base/SketchEditor.js, line 132 -
Properties:
Name Type Description eventSketchEditorEvent 事件消息体对象
Example
创建草图图形时事件 sketchEditor.on('create', (event) => { console.log("被选中事件:", event) }) -
标绘制线或区的一个顶点完成事件(废弃)
sketchEditor/base/SketchEditor.js, line 111 -
Properties:
Name Type Description eventObject 事件对象
Properties
Name Type Default Description typeLayerEventType 'drawn-vertex' 可选 事件类型
geometryGeometry 可选 绘制的几何对象
Example
鼠标绘制线或区的一个顶点完成事件 sketchEditor.on('drawn-vertex', (event) => { console.log("绘制的几何对象:", event.geometry) }) -
移除草图图形事件
sketchEditor/base/SketchEditor.js, line 150 -
Properties:
Name Type Description eventSketchEditorEvent 事件消息体对象
Example
移除草图图形事件 sketchEditor.on('remove', (event) => { console.log("被选中事件:", event) }) -
编辑草图图形时事件
sketchEditor/base/SketchEditor.js, line 141 -
Properties:
Name Type Description eventSketchEditorEvent 事件消息体对象
Example
编辑草图图形时事件 sketchEditor.on('update', (event) => { console.log("编辑图形时事件:", event) }) -
草图绘制完成事件
sketchEditor/base/SketchEditor.js, line 87 -
Properties:
Name Type Description eventNameSketchEditorEventType 可选 事件类型
eventObject 事件对象
Properties
Name Type Default Description toolEventInfoObject null 可选 事件类型
Properties
Name Type Default Description typeSketchEditorToolEventType null 可选 草图编辑工具事件类型
stateSketchEditorState SketchEditorState.create 可选 创建或编辑时,草图图形子状态
featureFeature null 可选 要素对象
geometryGeometry 可选 几何对象
Example
鼠标绘制完成事件 sketchEditor.on(SketchEditorEventType.create, (event) => { console.log("绘制的要素对象:", event.feature) }) -
草图绘制完成事件(废弃)
sketchEditor/base/SketchEditor.js, line 101 -
Properties:
Name Type Description eventObject 事件对象
Properties
Name Type Default Description typeLayerEventType 'drawn' 可选 事件类型
geometryGeometry 可选 绘制的几何对象
Example
鼠标绘制完成事件 sketchEditor.on('drawn', (event) => { console.log("绘制的几何对象:", event.geometry) }) -
草图编辑器回退事件
sketchEditor/base/SketchEditor.js, line 168 -
Properties:
Name Type Description eventSketchEditorEvent 事件消息体对象
Example
草图编辑器回退事件 sketchEditor.on('redo', (event) => { console.log("被选中事件:", event.selectedSketch) }) -
草图编辑器撤销事件
sketchEditor/base/SketchEditor.js, line 159 -
Properties:
Name Type Description eventSketchEditorEvent 事件消息体对象
Example
草图编辑器撤销事件 sketchEditor.on('undo', (event) => { console.log("被选中事件:", event) }) -
草图被选中事件(废弃)
sketchEditor/base/SketchEditor.js, line 121 -
Properties:
Name Type Description eventObject 事件对象
Properties
Name Type Default Description typeLayerEventType 'selected' 可选 事件类型
selectedSketchSketchEditorLeaflet | SketchEditorCesium 可选 被选中的草图对象
Example
草图被鼠标选中事件 sketchEditor.on('selected', (event) => { console.log("被选中事件:", event.selectedSketch) })
Methods
-
addVertex(point, index){Geometry}
sketchEditor/base/SketchEditor.js, line 603 -
Name Type Description pointPoint 新增/插入顶点
indexNumber 新增点的索引值,索引值从0开始
Returns:
Type Description Geometry 改变后的图形几何 -
canRedo(){Boolean}
sketchEditor/base/SketchEditor.js, line 1002 -
Returns:
Type Description Boolean -
canUndo(){Boolean}
sketchEditor/base/SketchEditor.js, line 994 -
Returns:
Type Description Boolean -
destroy()
sketchEditor/base/SketchEditor.js, line 1052 -
销毁草图编辑器
-
drawPolylineToPolygon(snapAndReferGeometries){Array.<Polygon>}
sketchEditor/base/SketchEditor.js, line 914 -
Name Type Description snapAndReferGeometriesArray.<Polygon> 捕获参考几何对象数组
Returns:
Type Description Array.<Polygon> 分割后的几何对象 -
getGeometry(){Geometry}
sketchEditor/base/SketchEditor.js, line 1395 -
Returns:
Type Description Geometry -
getLayer(){GraphicsLayer}
sketchEditor/base/SketchEditor.js, line 774 -
Returns:
Type Description GraphicsLayer -
getLayer(){GraphicsLayer}
sketchEditor/base/SketchEditor.js, line 804 -
Returns:
Type Description GraphicsLayer -
getSketchDataType(){SketchDataType}
sketchEditor/base/SketchEditor.js, line 633 -
Returns:
Type Description SketchDataType -
getSketchStyle(){SketchStyle}
sketchEditor/base/SketchEditor.js, line 723 -
Returns:
Type Description SketchStyle -
getSnapAndReferGeometries(){Array.<Geometry>}
sketchEditor/base/SketchEditor.js, line 1440 -
获取捕获和线造区边界参考几何图形集合
Returns:
Type Description Array.<Geometry> 捕捉配置项 -
getSnapOption(){Object}
sketchEditor/base/SketchEditor.js, line 1421 -
获取捕捉配置项
Returns:
Type Description Object 捕捉配置项 -
inherited off(types, fn, context){Object}
base/Evented.js, line 328 -
移除事件
示例如下:
[1、移除一个事件的指定回调函数]
[2、移除一个事件的所有回调函数]
[3、移除多个事件的同一个指定的回调函数]
[4、移除多个指定事件的回调函数]
[5、删除时指定上下文 - types类型为字符串]
[6、删除时指定上下文 - types类型为对象]Name Type Description typesstring 可选 移除指定事件类型上绑定的回调函数
当类型为字符串时,可以移除单个或多个事件类型绑定的回调函数,单个事件:"click",多个事件:以空格分割:"click double-click";
当types为对象时,使用如下方式移除事件:{'click': onClickFun, 'mouse-move': onMouseMoveFun}fnfunction 可选 事件回调函数,当types为字符串,且不指定要删除的回调函数时,删除该事件上的所有回调函数
contextObject 可选 事件回调函数的this关键字将指向的对象
Returns:
Type Description Object 当前实例 Examples
移除一个事件的指定回调函数
// 一个事件的回调函数 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) -
inherited on(types, fn, context){Object}
base/Evented.js, line 232 -
注册一个新的监听事件;
示例如下:
[1、注册一个事件]
[2、一次注册多个事件 - 同一个回调函数]
[3、一次注册多个事件 - 分别指回调应函数]
[4、当types为字符串时 - 指定上下文]
[5、当types为对象时 - 指定上下文]Name Type Default Description typesString | Object null 可选 事件类型
当types为字符串时,可以定义单个或多个事件,单个事件:"click",多个事件:以空格分割:"click double-click";
当types为对象时,使用如下方式指定事件:{'click': onClickFun, 'mouse-move': onMouseMoveFun}fnfunction null 可选 事件回调函数
contextObject null 可选 事件回调函数的this关键字将指向的对象
Returns:
Type Description Object 当前实例 Examples
注册一个事件
// 初始化一个点击事件回调函数 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(){Geometry}
sketchEditor/base/SketchEditor.js, line 975 -
Returns:
Type Description Geometry 恢复后的几何对象 -
remove()
sketchEditor/base/SketchEditor.js, line 556 -
-
removeVertex(index){Geometry}
sketchEditor/base/SketchEditor.js, line 624 -
Name Type Description indexNumber 需移除的顶点的索引值,索引值从0开始
Returns:
Type Description Geometry 改变后的图形几何 -
select(featureDef)
sketchEditor/base/SketchEditor.js, line 1010 -
Name Type Description featureDefFeature | String 要素对象或要素对象的ID
-
setIsShowTip(isShow)
sketchEditor/base/SketchEditor.js, line 782 -
Name Type Description isShowBoolean -
setLayer(sketchStyle)
sketchEditor/base/SketchEditor.js, line 731 -
Name Type Description sketchStyleGraphicsLayer -
setSketchStyle(sketchStyle)
sketchEditor/base/SketchEditor.js, line 641 -
Name Type Description sketchStyleSketchStyle -
setSnapAndReferGeometries(geometries)
sketchEditor/base/SketchEditor.js, line 1429 -
设置捕获和线造区边界参考几何图形集合
Name Type Description geometriesArray.<Geometry> 几何图形集合
-
setSnapOption()
sketchEditor/base/SketchEditor.js, line 1412 -
设置捕捉配置项
Name Type Default Description snapOption.isSnapVertexCoincidentBoolean false 可选 是否自动捕捉顶点重合
snapOption.isSnapVertexInLineBoolean false 可选 是否自动捕捉线上的点
snapOption.isSnapPerpendicularBoolean false 可选 是否自动捕捉垂线垂点
snapOption.isSnapParallelBoolean false 可选 是否自动捕捉平行线
snapOption.snapSketchGeometryBoolean false 可选 是否捕捉正在绘制的图形的边界
snapOption.pixelToleranceNumber 10 可选 捕获像素容差
-
split(target, splitPolyline){Array.<Polygon>}
sketchEditor/base/SketchEditor.js, line 856 -
Name Type Description targetPolygon | SketchEditor 被分割的几何/草图对象
splitPolylinePolyline 线几何对象
Returns:
Type Description Array.<Polygon> 分割后的几何对象 -
start(data, extensionOptions)
sketchEditor/base/SketchEditor.js, line 329 -
开始(鼠标)绘制草图 根据传入绘制草图类型,开始鼠标绘制。
绘制点图形,鼠标单击即绘制。
绘制线图形,鼠标单击绘制线的一个顶点;鼠标移动,延长线图形;鼠标双击,完成线图形绘制。
绘制区图形,鼠标单击绘制区的一个顶点;鼠标移动,区图形随鼠标位置变动;鼠标双击,完成区图形绘制。Name Type Description dataSketchDataType | Geometry 绘制的草图类型或几何对象
extensionOptionsObject 草图编辑的扩展属性,可以通过该属性传入草图编辑额外需要的参数
Name Type Description vertexNumberNumber 可选 绘制线/区时的顶点限制数量。(例如绘制直线,则vertexNumber=2;绘制直三角形,则vertexNumber=3。)
-
startCustomDrawTool(CustomDrawTool)
sketchEditor/base/SketchEditor.js, line 345 -
Name Type Description CustomDrawToolClass.<SketchBaseDrawTool> 自定义草图图形工具类
-
stop()
sketchEditor/base/SketchEditor.js, line 535 -
-
undo(){Geometry}
sketchEditor/base/SketchEditor.js, line 956 -
Returns:
Type Description Geometry 撤销后的几何对象 -
union(polygons){Polygon}
sketchEditor/base/SketchEditor.js, line 813 -
Name Type Description polygonsPolygon 被合并的区几何对象
Returns:
Type Description Polygon 合并后的几何对象 -
updateVertex(point, index){Geometry}
sketchEditor/base/SketchEditor.js, line 614 -
Name Type Description pointPoint 新的顶点
indexNumber 需更新的顶点的索引值,索引值从0开始
Returns:
Type Description Geometry 改变后的图形几何