Select to view content in your preferred language

Converting a PictureMarkerSymbol to a swatch

753
3
11-19-2010 09:22 AM
TyroneLigon
Deactivated User
Using Flex API 1.3...

Based on posts from the previous forum, I wrote the following function to convert a map graphic to a swatch and add it to an InfoWindow:

function createSwatchFromGraphic(g:Graphic,m:Map):UIComponent {
  var swatch:UIComponent = new UIComponent;
  var sym:Symbol = g.symbol;

  sym.draw(swatch, new MapPoint(), null, m);
  swatch.x = swatch.y = 0;

  return swatch;
}

I use this for point markers; this function has worked great for simple markers and composite markers. However, it chokes on picture markers at the sym.draw function with a type coercion error - can't convert UIComponent to Graphic.

So I thought since the symbol apparently is a UIComponent, I could cast the symbol as a picture marker symbol, transfer its height and width properties to the sprite, set the sprite's x/y to 0, and add the symbol as a child of the sprite...yeah, that didn't work either (null pointer exception when the child was added to the swatch).

Any wisdom to impart?
Tags (2)
0 Kudos
3 Replies
DasaPaddock
Esri Regular Contributor
You could try just using a Flex Image to load the PictureMarkerSymbol's source.
0 Kudos
TyroneLigon
Deactivated User
Well DUH!!!

I'd be able to see the forest if all the trees weren't in the way.

So now, I determine if the graphic is a PictureMarkerSymbol - if so, I create an image object and use the graphic's source, otherwise I use the function.

I was just bent on forcing the issue.

Thanks, Dasa.
0 Kudos
ReneRubalcava
Esri Frequent Contributor
I have a utility function I use based on a lot what Robert Scheitlin did for his Legend tool that handles PictureMarkerSymbols as well.

https://github.com/odoe/FlexMapTools/blob/master/src/net/odoe/FlexMapTools/factories/SwatchFactory.a...
0 Kudos