Simple Yahoo! Maps Workaround

The Yahoo! Maps Flash Component and API is a nice system to work with. For a simple to use map plug in for flash that looks decent without much work, its the best there is. However I like to work with it and see what hidden gems I can find. Or, as is the case in this article, delve deep inside of it and try to find out how to make it work as I want it to. It's still technically beta, so it has it's own little quirks. …

As great as the Yahoo! Maps component is, it has one quirk I've run into a couple of times. If you unload the map while it is loading data and tiles it loads excruciatingly slow when you load the map again. In fact, it seems like it isn't loading at all. Usually when I've created a map for a web page or RIA, I create it as a separate SWF movie to be loaded at runtime. The fix for the problem in this situation is simple, if not obvious.

// make sure yahoo map library is removed from global namespace
// so that it will always reload.
this.yMap.onUnload = function()
{
    _global.com.yahoo = null;
}

Unfortunately, this is one of those wild ass guess debug moments – where you just try it and hope it works. I'm not sure what class in the yahoo tree is causing the problems but I figured something was so I just got rid of them all. It probably also helps that the entire yahoo map library is a larger chunk of data so making it all available for garbage collection in that way makes garbage collection actually occur.

Recently, I had a project where my boss wanted me to embed map movie clip in the main movie rather than load it in at runtime. I still had the same type of problem, where the map could get, and is like to be, unloaded while it is in the middle of a data/tile load cycle. Since the Yahoo! map library isn't getting loaded in as it does with an external SWF, deleting the library is worse than the original quirk. Then the map won't even show the copyright info.

So into the problem I dove. I tried everything I could think of. I looked in the classes that I unzipped from the components SWC file to see if I could make some adjustments to unofficial parameters on unload. I used wireshark to see if any HTML requests were missing when the quirk occurred. I even took the SWC apart with Buraks Actionscript Viewer and tried to sort through that mess of code to see if I could find the answer. While I made many interesting discoveries along the way, I made no difference in the issue at hand.

So I made my way to my boss's office to tell him the status. As I walked toward his office I knew he would have a very simple answer for me that would work. I'm stubborn. I'm a programmer. I like to do things my way. I want elegant solutions to my programming problems. He is a designer. He just wants it to work. He's not worried about how it works ( note to other programmers, most people are this way ). I walk into his office and tell him the news. He thinks about it for maybe one second and tells me not to unload it, just move it off the stage.

Don't unload it?! That's like going to a doctor and telling him, "it hurts when I do this." To which the doctor will respond, "Then don't do that." In other words, it makes perfect sense and I can't believe I didn't think about it. Maybe I should have taken a break instead of pushing on for as long as I did to figure it out.

Now, instead of moving it off the stage I just set it's _visible property to false. That just seems a bit more elegant to me, and it just works. In fact in this situation it works better than the other system. Anyone who has used the Yahoo! Maps component knows that before the first tiles load in there is nothing but copyright info. By doing it this way the map loads in the background so when a user click the button to see the map, it comes up instantly.

So to wrap things up, here are my lessons learned:

  • If you can't make it elegant, just make it work
  • Ask for help from people who don't think like you
  • Your mind needs a rest from time to time, take breaks
  • load Yahoo! Maps in the background – they work better that way
  • Sometimes the answers are simple, if you are racking your brain step back and look at things from different perspective

—-
Daryl "Deacon" Ducharme is currently Director of Application Development for the Interactive Agency Provis Media Group, LLC which helps organizations enhance identity, connect with customers and increase productivity.

2 thoughts on “Simple Yahoo! Maps Workaround”

  1. Augusto Pirovano writes:

    Hi, I've seen your blog post and it seems I'm experiencing the same problem (browsers hang when I refresh the page) although I'm using yahoo's ajax maps.I've tried your solution:// make sure yahoo map library is removed from global namespace // so that it will always reload. this.yMap.onUnload = function() { _global.com.yahoo = null; }but it doesn't work for me…can you give me some clues?

    Like

  2. I'm not sure how things work for the ajax version of the maps but it might be a similar problem. The problem seems to be that if there is a refresh in the midsts of loading already happening then things get bogged down. The best thing I could say is try to reduce the instances of refresh as much as possible.

    Like

Leave a comment