I create a rather ugly workaround. Using the "moveend" event seemed
like a clean option, but it is somewhat tricky. The problem is that
you can't tell when panning will actually happen, so you can't depend
on the "moveend" event always firing. Since the map can't pan less
than a pixel you can not simply compare map center to marker center.
Ideally you could calculate the pixel to degrees mapping at a given
zoom level and know when the map will scroll, but there may also be
some minimum scroll distance built into google's code.  In the end I
found the following fudge values seem to work:

If you want to use this, you'll have to adjust it to your code. Note
the use of a closure to remember local variables.

Location.prototype.selectMarker = function() {
    map.getInfoWindow().hide();

    var marker = this.marker;
    var content = this.info_content;

    var map_center = map.getCenter();
    var mrk_center = this.marker.getLatLng();

    // Approx. lat/long tolerance before panning starts
    var zoom = map.getZoom();
    var error = 0.0001;
    if(zoom <= 3)
        error = 0.75;
    else if(zoom <= 4)
        error = 0.1;
    else if(zoom <= 11)
        error = 0.05;
    else if(zoom <= 13)
        error = 0.01;
    else if(zoom <= 15)
        error = 0.005;

    if(Math.abs(map_center.lat() - mrk_center.lat()) > error ||
       Math.abs(map_center.lng() - mrk_center.lng()) > error   )
    {
        var handler = GEvent.addListener(map, 'moveend',
            function(){
                marker.openInfoWindow(content, {suppressMapPan:true});
                GEvent.removeListener(handler);
        });

        map.panTo(this.marker.getLatLng());
    }
    else
    {
        marker.openInfoWindow(content);
    }
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to