I’ve been using the example AnimationMapGraphic
class and have been running into problems when the graphic is added to more
than one map. As I understand it (through debugging) there is only one
instance of the AnimationMapGraphic class created to handle drawing on all
maps. The MapGraphicContext is used to provide context to the draw
operation. The AnimationMapGraphic
example code only ever creates one animation - for the very first MapGraphicContext
object that is passed to draw().
I tried the obvious – creating a new CircleAnimation object
per MapGraphicContext:
private Map<MapGraphicContext,CircleAnimation> animations = new
HashMap<MapGraphicContext, CircleAnimation>();
public void
draw(MapGraphicContext context) {
if (this.animations.get(context) == null) {
ILayer layer = context.getLayer();
IBlackboard blackboard = layer.getBlackboard();
blackboard.putInteger("x", 0);
blackboard.putInteger("y", 50);
CircleAnimation animation = new CircleAnimation(layer, context);
AnimationUpdater.runTimer(context.getMapDisplay(),
animation);
animations.put(context, animation);
}
}
But this gave very strange results and didn’t work as
expected (lots of exceptions related to invalid SWT handles) and when it does
work the animation gets faster and faster until the machine locks up. There
seems to be some other issue that I don’t understand in the
AnimationUpdater logic.
So what is the best way to generalise the AnimationMapGraphic example
to resolve this problem? Is there any other example animation code
available?
PS: In the nextFrame() method the display can sometimes be null so
it should be checked for, e.g.:
if (display == null || x > display.getWidth()) {
x = 0;
}
Cheers,
Leigh Fitzgibbon
Eurobios Australia