Tuesday, July 15, 2008

Google Flash Map

Well, my flash map toy works pretty well recently till i found a tiny problem when writing my own map control.

Basically my control does a simple thing: display lat and lng values when you navigate the map. This is done simply by registering a event listener to Map Move Event, more specifically MapMoveEvent.MOVE_STEP.

For example,

public class ControlLatLng extends ControlBase {
...
public override function initControlWithMap(map:IMap):void {
var latLabel:TextField = new TextField();
...
latLabel.addEventListener(MapMoveEvent.MOVE_STEP,
function(event:MapMoveEvent):void {
latLabel.text = _map.getCenter().lat().toString();
...
}
);
...
}
...
}

Well, gotta say this is what i thought at first that my label listens to Map Event directly. Then once there is a move, label text will be updated correspondingly. However if you add and run this code, you will find it is totally wrong: the listener does not work at all.

Back and forth, forth and back, i was jumping everywhere to find the answer: why doesn't it work? I even analyzed Flex event's 3 different stages but in the end i found answer from the discussion group that i gotta use _map to register this listener instead of my "local" label. But why!?

Back to Google Flash Map official tutorial, i found this:

"The Google Maps API for Flash adds to this event model by defining custom events for objects within the API. It is important to note that the Maps API for Flash events are separate and distinct from the standard Flash events. Note that MapEvent events may bubble up from target objects to container objects, though events in the Google Maps API for Flash are generally designed with specific targets in mind."


Clearly by this, a tiny little piece of my mind reminds me: Flex events, for example, mouse events can not be utilized directly; instead, we have to use Map Events, Map Move Events etc. One thing after another, i remember in Google Developer Day, the map presenter did state that Flash Map is actually loading "an extra" swf into your client app. Meanwhile, i found Ted's blog:

"The Google Maps Flash API is the first major component to work distributed as the core logic remains on google servers and the API you program with is just a simple proxy loading the remote SWF and that SWF talks back to Google to get data and tiles as a service."

And from Francesco Rapanà that

2) Pay attention to the events: you can't use the standard Flex events but you need that ones provided by the Google SDK, such as MapMouseEvent.CLICK.


So from here, the answer might be clear: events that Google Map has are different and can not be utilized directly in our "local" flex app -- obviously they are two separated applications and utilizes "the internal API" to glue them together.

So what the architecture of Google Flash Map? Hmmm gotta say i couldn't find any answer from Google (of course, damn). But look at this from Google IO:









This might not clear enough, but this one maybe better:















1.1swf is embedded in client HTML.

OK gonna stop here but i wish they will open-source this project soon.

No comments: