Skip to content

Commit

Permalink
[ADD] drawing event to change object style #1036
Browse files Browse the repository at this point in the history
  • Loading branch information
Viglino committed Mar 12, 2024
1 parent c4a8660 commit ffcd66c
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions src/featureanimation/FeatureAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ol_ext_getVectorContextStyle from '../util/getVectorContextStyle.js'
* @fires animationstart
* @fires animating
* @fires animationend
* @fires drawing
* @param {ol_featureAnimationOptions} options
* @param {Number} options.duration duration of the animation in ms, default 1000
* @param {bool} options.revers revers the animation direction
Expand Down Expand Up @@ -60,21 +61,34 @@ var ol_featureAnimation = class olfeatureAnimation extends ol_Object {
* @private
*/
drawGeom_(e, geom, shadow) {
// Drawing event
this.dispatchEvent({
type: 'drawing',
time: e.time,
feature: e.feature,
start: e.start,
stop: e.stop,
style: e.rotation,
style: e.style,
extra: e.extra
})
// Draw
if (this.fade_) {
e.context.globalAlpha = this.fade_(1 - e.elapsed)
}
var style = e.style
var style = (e.style instanceof Array) ? e.style : [e.style];
for (var i = 0; i < style.length; i++) {
// Prevent crach if the style is not ready (image not loaded)
try {
var vectorContext = e.vectorContext || ol_render_getVectorContext(e)
var s = ol_ext_getVectorContextStyle(e, style[i])
vectorContext.setStyle(s)
if (s.getZIndex() < 0)
if (s.getZIndex() < 0) {
vectorContext.drawGeometry(shadow || geom)
else
} else {
vectorContext.drawGeometry(geom)
} catch (e) { /* ok */ }
}
} catch (error) { /* ok */ }
}
}
/** Function to perform manipulations onpostcompose.
Expand Down Expand Up @@ -202,6 +216,24 @@ ol_layer_Base.prototype.animateFeature = function(feature, fanim, useFilter) {
e.context.globalAlpha = this.getOpacity();
}

// Before anim
/*
var beforeEvent = {
type: 'beforeanim',
step: step,
start: event.start,
time: event.time,
elapsed: event.elapsed,
rotation: event.rotation||0,
geom: event.geom,
coordinate: event.coord,
feature: feature,
extra: event.extra || {},
style: flashStyle
};
fanim[step].dispatchEvent(beforeEvent);
self.dispatchEvent(beforeEvent);
*/

// Stop animation?
if (!fanim[step].animate(event)) {
Expand Down Expand Up @@ -230,7 +262,8 @@ ol_layer_Base.prototype.animateFeature = function(feature, fanim, useFilter) {
geom: event.geom,
coordinate: event.coord,
feature: feature,
extra: event.extra || {}
extra: event.extra || {},
style: flashStyle
};
fanim[step].dispatchEvent(animEvent);
self.dispatchEvent(animEvent);
Expand Down

0 comments on commit ffcd66c

Please sign in to comment.