外观
自定义矢量图层
105字小于1分钟
2025-01-25
主要核心点
完全自定义图层时,注意 onAdd
、onRemove
这2个leaflet关键钩子方法的复写即可。
示例代码
class CustomLayer extends mars2d.layer.GraphicLayer {
onAdd(map) {
// this.isAutoEditing = this.options.isAutoEditing ?? true
// this.isContinued = this.options.isContinued ?? false
// this.isDblclickForDrawEnd = this.options.isDblclickForDrawEnd ?? true
super.onAdd(map)
this._map = map
}
onRemove(map) {
// this.off(EventType.drawCreated, this._onDrawCreatedHandler, this)
super.onRemove(map)
delete this._map
}
}
// 注册下,可以Map初始化时参数化创建
mars2d.LayerUtil.register("customLayer", CustomLayer)