Hi,

Just in case somebody is having the same problem. Center/zoom works well for all layers using the code below:

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

       var osmLayer = new OpenLayers.Layer.OSM.Mapnik("OpenStreetMap");
       var gMapLayer = new OpenLayers.Layer.Google("Google", 
{sphericalMercator:true});
       var gPhysicalLayer = new OpenLayers.Layer.Google("Google Physical", 
{type: G_PHYSICAL_MAP, sphericalMercator:true});
       var gSatelliteLayer = new OpenLayers.Layer.Google("Google Satellite", 
{type: G_SATELLITE_MAP, sphericalMercator:true});
       map.addLayers([osmLayer, gMapLayer, gPhysicalLayer, gSatelliteLayer]);

       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() {
       map.zoomTo(zoom);

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


Regards,

Axel


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);
    }

------------------------------------------------------------------------

_______________________________________________
Users mailing list
[email protected]
http://openlayers.org/mailman/listinfo/users

_______________________________________________
Users mailing list
[email protected]
http://openlayers.org/mailman/listinfo/users

Reply via email to