GMap and Yahoo Maps for Flash CS3
I thought it was a very nice move from Yahoo to provide the community the free Astra project. I wanted to try their components, especially the YahooMap component because I wasn’t satisfied with the AFComponents’s GMap I used in some AS2 projects.
GMap shortcomings
I’ve come across several problems with the GMap component.
- The component is provided in an .mxp without sources and that led to the same problem as for the TXEFF component
- GMap can be animated and that’s very cool to zoom, pan with the map scaling and moving smoothly. Ok the fun stops here. Even though the concept is nice, it forces the component to preload tiles from different depths so that the zoom animation does not zoom on empty tiles. Same goes for panning. In AS2 there is no way to force a loader to stop loading something. GMap is in AS2. Loading too many tiles + can’t stop loading the useless tiles = whoops !
- GMap connects to proxies on afcomponents.com not on google.com. That leads to problems such as really slow loadings.
- GMap was sometimes refused imagery because Google blocked it upon too many requests.
“Too many requests from the same ip is interpreted as an automatic request, which makes it unable to bypass google’s security system”
GMap is a good component though. It is rather well documented and the forum is a big help for in-depth information search. It helped me not wasting time on drawing ugly maps on Illustrator (because maps weren’t something affordable for small/medium clients not so long ago). However, the lack of control upon the component and its inherent complexity makes it sometimes go haywire.
YahooMap in Flash CS3
Now let’s talk about YahooMap. I read rather quickly that there was a YahooMap component for AS3 so I downloaded it and what the hell ? It’s a Flex component. This is quite a problem since I’m on a project with Flash CS3. A quick google search and I found Josh Tynjala’s blog with an interesting solution.
Two good things about this. First I learnt about ApplicationDomain and how you can access to classes loaded dynamically from a swf. Second, I learnt that a .swc component is actually an archive file that you can decompress with something like PowerArchiver. I downloaded his code and files and integrated this concept in my current project. Then came the time when I wanted a custom marker on my map…
Custom markers for YahooMap
The problem with Josh’s temporary solution (they’re going to make a Flash CS3 component of the YahooMap soon) is that you have to browse the YahooMap documentation and find out how the classes are related, then import them dynamically and see what happens. It was a little struggle to understand how a Marker is built. I read somewhere that the markers are extensions of Sprite. Basically, for a custom marker you should extend the SimpleMarker or SearchMarker class, or implement the IMarker interface in your custom class. ARGH ! The former is impossible since you cannot extend a non-existing class (remember YahooMap’s classes are loaded dynamically from the library.swf). The latter would take too much time when I just want a custom image to show instead of the SimpleMarker.
This little ugly hack removes the graphics that the SimpleMarker generates 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 custom marker. Alright, it’s a shabby and desperate solution but I needed the component to work asap.
About this entry
You’re currently reading “GMap and Yahoo Maps for Flash CS3,” an entry on Théâtre magique
- Published:
- 03.21.08 / 3
- Category:
- Flash/Flex
No comments
Jump to comment form | comments rss [?] | trackback uri [?]