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);
}
在ol6中,在图层上使用
postrender
事件,新的getVectorContext
函数提供了对即时矢量渲染API的访问。