View Full Version : Changing icons on the fly
04-05-2012, 08:12 PM
I am trying to extend MilStd2525IconRetriever to display a badge indicating the number of pieces of equipment that are contained inside the platform. Previously, I was doing this with UserFacingIcon. I've seen the lazy loading icon code, and I was wondering if there is a way to request a redraw of the icon... to make the createIcon method get called again. Also, I was wondering how to get new params to be passed into the createIcon upon subsequent calls. I'd like a param to indicate the number of pieces of equipment on the platform. Thank you!
update: I attached a screen shot to show you what I'm talking about... I have extended MilStd2525IconRetriever, and my badge code is in my createIcon(). I just don't know how to get the icon refreshed... I'll also need to get this refreshed if I change the alignment from Friendly to Hostile, etc.
04-05-2012, 11:51 PM
I got a bit further by overriding the layoutIcon method and forcing the creation of a new IconTexture when my badge requires a redraw. Also, I'm passing the number to be displayed in the badge as part of an AVList. This almost works... it makes my iconRetriever execute the createIcon method which modifies the buffered image with the badge, however I just can't seem to get the new texture to be rendered. Here is a snippet of code from my layoutIcon method:
AVList badgeParams = new AVListImpl();
AVList retrieverParams = this.assembleIconRetrieverParameters(bad geParams);
// Lazily create the symbol icon texture when either the IconRetriever, the symbol ID, or the retriever
// parameters change.
IconSource source = new IconSource(this.getIconRetriever(), this.getIdentifier(), retrieverParams);
if (this.iconTexture == null ||
!this.iconTexture.getImageSource().equal s(source) ||
this.iconTexture = new IconTexture(source);
In the LazilyLoadedTexture class, in the notifyTextureLaoded method, there is a line that fires a property change event, however I can't find anything that is looking for the a TEXTURE event:
this.listener.propertyChange(new PropertyChangeEvent(this, AVKey.TEXTURE, null, this));
04-07-2012, 06:55 PM
You should be able to do this by just overriding assembleIconRetrieverParams. You want to do something like this:
protected AVList assembleIconRetrieverParameters(AVList params)
AVList retrieverParams = super.assembleIconRetrieverParameters(pa rams);
retrieverParams.setValue(NUM_CHILDREN_KE Y, this.getChildMapObjects().size());
This method is called each frame, and World Wind compares the new parameters to the previous parameters to determine if the icon needs to be retrieved again. So whenever you change the NUM_CHILDREN_KEY it should result in an icon refresh.
04-09-2012, 03:09 PM
Thank you! Your suggestion worked perfectly. I didn't need to override layoutIcon. I just needed to override assembleIconRetrieverParameters. For others who might read this, I also overrode createIcon in an extension of SwarmMilStd2525IconRetriever so I could draw on the BufferedImage. Thanks again!
vBulletin® v3.7.1, Copyright ©2000-2013, Jelsoft Enterprises Ltd.