GEvent order of events

One of the nice features of the Google Map’s API is that you can add your own event listeners to do things when certain events are triggered on the map. It’s quite easy to do using either the GEvent.addListener() or the GEvent.bind() methods, but tying to guess the exact order the events will trigger is a whole different story.

I was recently working on a project that required the map to fetch points within the viewport after it had been moved or dragged. This is easy enough to do by adding a listener for the moveEnd event and using the GXmlHttp object to query the server, but things didn’t go so smoothly once I started zooming the map in and out. When zooming out, the points that cam back were only within the original window at the previous zoom, not the new zoom. I tracked the problem down to the fact that the map triggers the moveEnd event prior to triggering the zoom event so my map was fetching point before the zoom!

I started to wonder just what the order of events where so I whipped up this little map to capture the order. Basically it’s just has an event listener for each possible event so just click, move and zoom to see what happens. It can be very enlightening to see just what events are triggered at which times. (Just for fun I’ve also included some of the undocumented events)