绘制和编辑
用法
绘制和编辑操作使用hook函数
js
// 创建draw事件和修改事件,这两个事件都是用的highlightLayer图层,绘制之后可以直接编辑
let draw = _olHelper.useDraw(drawType);
let modify = _olHelper.useModify();
// 设置绘制事件回调函数
draw.setEventFunc((event) => {
// 这个回调在上图层之前,所以如果需要操作绘制图层,请使用setTimeout
setTimeout(() => {
}, 100);
});
// 编辑同理
modify.setEventFunc((event) => {
setTimeout(() => {
}, 100);
});绘制
useDraw(type,options)
创建绘制事件,会将内置的highLightLayer图层作为编辑图层
| 名称 | 详情 | 类型 | 默认 |
|---|---|---|---|
| type | 可以绘制的类型 | drawTypeEnum | - |
| options | openlayers的ol/interaction/Draw实例配置 | Partial<DrawOptions> | {} |
drawTypeEnum = 'Point' | 'LineString' | 'Polygon' | 'Circle' | 'Square' | 'Box';
返回:
| 名称 | 详情 | 类型 |
|---|---|---|
| drawInstance | 绘制实例 | Draw |
| setEventFunc | 设置事件回调函数 | function |
| remove | 移除绘制事件 | function |
编辑
useModify(options)
创建编辑事件,无需配置,会将内置的highLightLayer图层作为编辑图层
| 名称 | 详情 | 类型 | 默认 |
|---|---|---|---|
| options | openlayers的ol/interaction/Modify实例配置 | ModifyOptions | {} |
返回:
| 名称 | 详情 | 类型 |
|---|---|---|
| modifyInstance | ol原生编辑实例 | Modify |
| setEventFunc | 设置事件回调函数 | function |
| remove | 移除编辑事件 | function |