解决OpenLayers postcompose事件event.vectorContext获取失败的问题?-灵析社区

米斯达

openlayers 使用地图postcompose事件event.vectorContext 为什么获取不到呢? 通过openlayers添加点然后实现点位闪烁效果 flash(feature) { var _this = this; var start = new Date().getTime(); var listenerKey; function animate(event) { debugger; var duration = 1000; var vectorContext = event.vectorContext; var frameState = event.frameState; var flashGeom = feature.getGeometry().clone(); var elapsed = frameState.time - start; var elapsedRatio = elapsed / duration; // var radius = ol.easing.easeOut(elapsedRatio) * 6 + 5; // var opacity = ol.easing.easeOut(1 - elapsedRatio); var radius = 10; var opacity = 1; console.log("radius:::" + radius + ":::opacity:::" + opacity) var style = new Style({ image: new Circle({ radius: radius, snapToPixel: false, stroke: new Stroke({ color: 'rgba(255, 0, 0, ' + opacity + ')', width: 0.25 + opacity }) }) }); vectorContext.setStyle(style); vectorContext.drawGeometry(flashGeom); if (elapsed > duration) { ol.Observable.unByKey(listenerKey); return; } _this.map.render(); } listenerKey = _this.map.on('postcompose', animate); }

阅读量:189

点赞量:0

问AI
"image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241001/48a64e3f4cbd409a1ca2d7e68f810ee5.png) 在ol6中,在图层上使用"postrender"事件,新的"getVectorContext"函数提供了对即时矢量渲染API的访问。 import {getVectorContext} from 'ol/render'; // construct your map and layers as usual layer.on('postrender', function(event) { const vectorContext = getVectorContext(event); // use any of the drawing methods on the vector context });