Closing an InfoWindow deletes PictureMarkerSymbol

514
1
03-04-2013 07:04 AM
KennyHoran
New Contributor III
I've been chasing this issue for a while and have finally nailed it down.  I've built a FeatureLayer full of points and assigned each point a PictureMarkerSymbol, much like the Search widget.  Each symbol's built from a bitmap something like this:

[Embed(source="assets/images/myImage.png")]
private var myImage:Class;
...
...
var graphic:Graphic = new Graphic(myPoint);
graphic.symbol = new PictureMarkerSymbol(myImage, myImage.width, myImage.height);

// Note - This also works:
graphic.symbol = new PictureMarkerSymbol("assets/images/myImage.png", 16, 16);


Works great.  Now I need to enhance the symbol so I make a bitmap, tweak it, then build a PictureMarkerSymbol from that.  It seems to work but I have problems with the InfoWindow.  When I click the point it works fine, but when the window closes the point vanishes and can't be clicked again.  Here's a simple case to illustrate.

[Embed(source="assets/images/myImage.png)]
private var myImage:Class;
...
...
var graphic:Graphic = new Graphic(myPoint);
var bitmap:Bitmap = new myImage();
graphic.symbol = new PictureMarkerSymbol(bitmap, bitmap.width, bitmap.height);


I don't understand why this doesn't work.  I've tried all sorts of variations and no matter what I do, if I build a PictureMarkerSymbol from an in-memory Bitmap it won't work with an InfoWindow.

Any ideas what I might do differently?  If it helps, I've modified SearchWidget.mxml to reproduce this behavior.  Just run a search, view an InfoWindow, then watch your point vanish.
Tags (2)
0 Kudos
1 Reply
KennyHoran
New Contributor III
Alright, I give up.  I'm going back to this BitmapSymbol class.  I'm not the original author so I have no clue why it works, but it does.  Here's the code in case it's useful to someone else.  I think the original came from here.

public final class BitmapSymbol extends PictureMarkerSymbol
{
  public function BitmapSymbol(bitmap:Bitmap)
  {
    super(bitmap, bitmap.width, bitmap.height);
  }

  override public function draw(sprite:Sprite, geometry:Geometry, attributes:Object, map:Map):void
  {
    const point:MapPoint = geometry as MapPoint;
    sprite.x = toScreenX(map, point.x) - m_xoffset;
    sprite.y = toScreenY(map, point.y) - m_yoffset);

    clear(sprite);
    sprite.graphics.beginBitmapFill(source.bitmapData, null, false, true);
    sprite.graphics.drawRect(0, 0, source.width, source.height);
    sprite.graphics.endFill();
  }
}
0 Kudos