GMap and Yahoo Maps for Flash CS3

I thought it was a very nice move from Yahoo to pro­vide the com­mu­nity the free Astra project. I wanted to try their com­po­nents, espe­cially the YahooMap com­po­nent because I wasn’t sat­is­fied with the AFComponents’s GMap I used in some AS2 projects.

GMap short­com­ings

I’ve come across sev­eral prob­lems with the GMap component.

  • The com­po­nent is pro­vided in an .mxp with­out sources and that led to the same prob­lem as for the TXEFF com­po­nent
  • GMap can be ani­mated and that’s very cool to zoom, pan with the map scal­ing and mov­ing smoothly. Ok the fun stops here. Even though the con­cept is nice, it forces the com­po­nent to pre­load tiles from dif­fer­ent depths so that the zoom ani­ma­tion does not zoom on empty tiles. Same goes for pan­ning. In AS2 there is no way to force a loader to stop load­ing some­thing. GMap is in AS2. Load­ing too many tiles + can’t stop load­ing the use­less tiles = whoops !
  • GMap con­nects to prox­ies on afcomponents.com not on google.com. That leads to prob­lems such as really slow load­ings.
  • GMap was some­times refused imagery because Google blocked it upon too many requests.
    “Too many requests from the same ip is inter­preted as an auto­matic request, which makes it unable to bypass google’s secu­rity system”

GMap is a good com­po­nent though. It is rather well doc­u­mented and the forum is a big help for in-depth infor­ma­tion search. It helped me not wast­ing time on draw­ing ugly maps on Illus­tra­tor (because maps weren’t some­thing afford­able for small/medium clients not so long ago). How­ever, the lack of con­trol upon the com­po­nent and its inher­ent com­plex­ity makes it some­times go haywire.

YahooMap in Flash CS3

Now let’s talk about YahooMap. I read rather quickly that there was a YahooMap com­po­nent for AS3 so I down­loaded it and what the hell ? It’s a Flex com­po­nent. This is quite a prob­lem since I’m on a project with Flash CS3. A quick google search and I found Josh Tynjala’s blog with an inter­est­ing solu­tion.

Two good things about this. First I learnt about Appli­ca­tion­Do­main and how you can access to classes loaded dynam­i­cally from a swf. Sec­ond, I learnt that a .swc com­po­nent is actu­ally an archive file that you can decom­press with some­thing like Pow­er­Ar­chiver. I down­loaded his code and files and inte­grated this con­cept in my cur­rent project. Then came the time when I wanted a cus­tom marker on my map…

Cus­tom mark­ers for YahooMap

The prob­lem with Josh’s tem­po­rary solu­tion (they’re going to make a Flash CS3 com­po­nent of the YahooMap soon) is that you have to browse the YahooMap doc­u­men­ta­tion and find out how the classes are related, then import them dynam­i­cally and see what hap­pens. It was a lit­tle strug­gle to under­stand how a Marker is built. I read some­where that the mark­ers are exten­sions of Sprite. Basi­cally, for a cus­tom marker you should extend the Sim­ple­Marker or Search­Marker class, or imple­ment the IMarker inter­face in your cus­tom class. ARGH ! The for­mer is impos­si­ble since you can­not extend a non-existing class (remem­ber YahooMap’s classes are loaded dynam­i­cally from the library.swf). The lat­ter would take too much time when I just want a cus­tom image to show instead of the SimpleMarker.

This lit­tle ugly hack removes the graph­ics that the Sim­ple­Marker gen­er­ates and lets you add your own images/shapes/whatnot.

// We cannot strong type "marker" here
var marker = new SimpleMarker();
marker.latlon = new LatLon(lat, lon);
_map.markerManager.addMarker(marker);
 
// Remove the black shape
marker.removeChildAt(0);
 
// Remove the remaining grey shape
marker.removeChildAt(0);
 
var yourCustomMarkerGraphics:Sprite= new Sprite();
marker.addChild(yourCustomMarkerGraphics);

That’s it ! You got your cus­tom marker. Alright, it’s a shabby and des­per­ate solu­tion but I needed the com­po­nent to work asap.


About this entry