[OpenLayers-Users] Google Maps map does not reflect zoom level change

Axel Müller axel.mueller at avanux.de
Mon Jul 6 14:46:20 EDT 2009


Andrea,

Andreas Hocevar wrote:
>> Based on some parameters I change the zoom level using
>> map.setCenter(lonlat, zoom).
>> This works perfectly for OSM Mapnik layer but not for Google layer where
>> the pan zoom bar reflects the new zoom level but the map itself still
>> shows the previous zoom level. Am I missing something?
>>
>> osmLayer = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
>> gMapLayer = new OpenLayers.Layer.Google("Google Maps", {numZoomLevels:
>> 20, isBaseLayer: true });
>>     
>
> Using Google layers like this only works in a few use cases. You have
> to use Spherical Mercator to make it behave like you are expecting.
> See http://docs.openlayers.org/library/spherical_mercator.html for
> explanation, tutorial and howto.
>   
Thanks for pointing me to this documentation. I'm using Spherical 
Mercator now but the underlying problem is still the same:
While being on the Google layer, a call to 
map.setCenter(lastMarker.lonlat, zoom) causes the zoom bar to show the 
new zoom level but the map is still displayed for the previously 
selected zoom level.  If I switch to OSM layer and back to Google layer, 
the map in the Google layer is shown with the correct zoom level, 
matching the zoom level indicated by the zoom bar.

Best regards,

Axel


Below is the relevant part of JS:


    function init() {
        map = new OpenLayers.Map('map', {
            projection: new OpenLayers.Projection("EPSG:900913"),
            displayProjection: new OpenLayers.Projection("EPSG:4326"),
            units: "m",           
            controls: [
                new OpenLayers.Control.Navigation(),
                new OpenLayers.Control.PanZoomBar(),
                new OpenLayers.Control.LayerSwitcher({'ascending':false}),
                new OpenLayers.Control.Permalink(),
                new OpenLayers.Control.ScaleLine(),
                new OpenLayers.Control.Permalink('permalink'),
                new OpenLayers.Control.MousePosition(),
                new OpenLayers.Control.OverviewMap(),
            ]
        });

        var gMapLayer = new OpenLayers.Layer.Google("Google Maps", 
{isBaseLayer: true, 'sphericalMercator': true });
        var osmLayer = new OpenLayers.Layer.OSM();
        map.addLayers([gMapLayer, osmLayer]);
        map.zoomTo(zoom);
    }

    function triggerUpdate() {
        triggerUpdateActive = true;
        window.setTimeout("update()", refreshSeconds * 1000);
    }

    function update() {
        triggerUpdate();
        if(rss != null) {
            rss.destroy();
        }
        rss = new OpenLayers.Layer.GeoRSS(trackingID, geoRssUrl, 
{'projection': new OpenLayers.Projection("EPSG:4326")} );
        rss.events.register("loadend", window, populateMap);
        map.addLayer(rss);
    }

    function populateMap() {
        if(rss.markers.length >= 1) {
            var lastMarker=rss.markers[rss.markers.length-1];
            map.setCenter(lastMarker.lonlat, zoom);
       }
       map.raiseLayer(rss, 1);
    }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090706/21d3961a/attachment.html


More information about the Users mailing list