Skip to content

绘制和编辑

用法

绘制和编辑操作使用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-
optionsopenlayers的ol/interaction/Draw实例配置Partial<DrawOptions>{}

drawTypeEnum = 'Point' | 'LineString' | 'Polygon' | 'Circle' | 'Square' | 'Box';

返回:

名称详情类型
drawInstance绘制实例Draw
setEventFunc设置事件回调函数function
remove移除绘制事件function

编辑

useModify(options)

创建编辑事件,无需配置,会将内置的highLightLayer图层作为编辑图层

名称详情类型默认
optionsopenlayers的ol/interaction/Modify实例配置ModifyOptions{}

返回:

名称详情类型
modifyInstanceol原生编辑实例Modify
setEventFunc设置事件回调函数function
remove移除编辑事件function