[OpenLayers-Users] Fixing Google Layers, OL SVN + OL <= 2.4

Christopher Schmidt crschmidt at metacarta.com
Tue Sep 18 15:50:03 EDT 2007


If you are using a Layer.Google class, please read this! Your
application may be broken!

(This content is also available online at 
http://trac.openlayers.org/wiki/GoogleMapsFailure .)

OpenLayers has, for a long time, used an internal assumption about the
Google Maps API structure due to a lack of functionality in the API.

The behavior that OpenLayers depends on has changed, and is no longer
the same. We have fixed this functionality in OpenLayers SVN, and it
will be shortly released in OpenLayers 2.5 RC2.

If you are using an earlier OpenLayers release, you can work around the
issue by adding the following code:

GMap2.prototype.fromLatLngToContainerPixel = function(gLatLng) {

    // first we translate into "DivPixel"
    var gPoint = this.fromLatLngToDivPixel(gLatLng);

    // locate the sliding "Div" div
    var div = this.getContainer().firstChild.firstChild;

    // adjust by the offset of "Div" and voila!
    gPoint.x += div.offsetLeft;
    gPoint.y += div.offsetTop;

    return gPoint;
};  

This code snippet should be added *after* your GMap script is loaded,
but before any Google Layers are initialized. In general, this means it
should be at the beginning of your initialization function which is
called on loading of the page.

There is also a patch available:
http://trac.openlayers.org/attachment/ticket/994/google.patch 

This patch is for 2.5, but applies cleanly to all previous copied of
OpenLayers affected by the bug.

More information on this problem is available in #994, for interested
parties.

(This bug was first brought to the attention of the developers
approximately 3 hours ago, and was fixed approximately 2 hours later in
SVN. The power of Open Source. Thanks for the feedback, everyone.)  

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list