OpenLayers绘制图形后drawend事件触发图形消失问题求助
OpenLayers 绘制图形后自动消失问题
问题说明
使用基础示例无法在地图上添加元素,drawend事件触发后绘制的图形会消失,但在drawend监听器中可以确认元素是存在的。即使使用官方默认示例代码,也会出现同样的问题。
相关代码
private map: OlMap; private drawSource: VectorSource = new VectorSource({ wrapX: false }); private drawLayer: VectorLayer<VectorSource> = new VectorLayer({ source: this.drawSource }); private raster = new TileLayer({ source: new OSM() }); private drawAction: Draw; private snap: Snap; constructor() { } ngOnInit(): void { this.initMap(); this.startDraw(); } private initMap(): void { const mapCentre: number[] = fromLonLat(this.defaultMapCenter); this.map = new OlMap({ layers: [ this.drawLayer, this.raster ], target: 'map', view: new View({ center: mapCentre, zoom: 8, maxZoom: 22, }), controls: [], }); this.map.addLayer(basemapLayer); } private startDraw() { this.drawAction = new Draw({ source: this.drawSource, type: 'Polygon' }); this.map.addInteraction(this.drawAction); this.snap = new Snap({source: this.drawSource}); this.map.addInteraction(this.snap); }
效果截图
- 绘制前状态:

- 绘制后状态:

内容的提问来源于stack exchange,提问作者Maksym
相关产品推荐
相关产品推荐

