MapQuest Flex / AS3 API - How to retrieve custom icons from the map and use them elsewhere
The trouble I ran into with the MapQuest Flex API is that any objects you create in Adobe's Flex are pass by reference, therefore retrieving custom icons from the Map Object can be head scratching. How can you retrieve the custom icons being displayed on the map for use in a custom control such as a map legend without removing them from the map itself?
Without a built in copy function to retrieve the MapIcon object and use it elsewhere here is a simple little trick to "copy" the Custom Icon displayed on the map. As a matter of fact this will retrieve any icons associated with a poi on the Map Object using a little bit of bitmap drawing functionality built into Flex.
****************************************************************
Retrieve the Image component from the Poi you would like to copy the icon from:
//Create a Display Object from the Image Component Of the Poi MapIcon
var mi:DisplayObject = poi.getIcon().getImage();
// Create a BitMap Data Object with the following parameters
// Width of the Image
// Height of the Image
// Transparency Support = True
// Fill Color of the Bitmap Data - can be anything will be replaced by the icon image
var bd:BitmapData = new BitmapData(mi.width, mi.height, true, 0x00ffffff);
// Draw the contents of the Display Object onto the BitMapData Object
bd.draw(mi);
//Create a Bitmap from the BitMapData
var poiImage:Bitmap = new Bitmap(bd);
****************************************************************
There you have it, now you can create a Map Legend using custom icons used in your map pois without having your map icons dissapear.

26 weeks 5 days ago
27 weeks 3 days ago
27 weeks 5 days ago
27 weeks 6 days ago
27 weeks 6 days ago
28 weeks 15 hours ago
28 weeks 16 hours ago
28 weeks 16 hours ago