<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Andrea,<br>
<br>
Andreas Hocevar wrote:
<blockquote
cite="mid:5b021dd0907060056i647dbfcdt9069c58d676f8cb4@mail.gmail.com"
type="cite">
<blockquote type="cite">
<pre wrap="">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 });
</pre>
</blockquote>
<pre wrap=""><!---->
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 <a class="moz-txt-link-freetext" href="http://docs.openlayers.org/library/spherical_mercator.html">http://docs.openlayers.org/library/spherical_mercator.html</a> for
explanation, tutorial and howto.
</pre>
</blockquote>
Thanks for pointing me to this documentation. I'm using Spherical
Mercator now but the underlying problem is still the same:<br>
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.<br>
<br>
Best regards,<br>
<br>
Axel<br>
<br>
<br>
Below is the relevant part of JS:<br>
<br>
<br>
function init() {<br>
map = new OpenLayers.Map('map', {<br>
projection: new OpenLayers.Projection("EPSG:900913"),<br>
displayProjection: new OpenLayers.Projection("EPSG:4326"),<br>
units: "m", <br>
controls: [<br>
new OpenLayers.Control.Navigation(),<br>
new OpenLayers.Control.PanZoomBar(),<br>
new
OpenLayers.Control.LayerSwitcher({'ascending':false}),<br>
new OpenLayers.Control.Permalink(),<br>
new OpenLayers.Control.ScaleLine(),<br>
new OpenLayers.Control.Permalink('permalink'),<br>
new OpenLayers.Control.MousePosition(),<br>
new OpenLayers.Control.OverviewMap(),<br>
]<br>
});<br>
<br>
var gMapLayer = new OpenLayers.Layer.Google("Google Maps",
{isBaseLayer: true, 'sphericalMercator': true });<br>
var osmLayer = new OpenLayers.Layer.OSM();<br>
map.addLayers([gMapLayer, osmLayer]);<br>
map.zoomTo(zoom);<br>
}<br>
<br>
function triggerUpdate() {<br>
triggerUpdateActive = true;<br>
window.setTimeout("update()", refreshSeconds * 1000);<br>
}<br>
<br>
function update() {<br>
triggerUpdate();<br>
if(rss != null) {<br>
rss.destroy();<br>
}<br>
rss = new OpenLayers.Layer.GeoRSS(trackingID, geoRssUrl,
{'projection': new OpenLayers.Projection("EPSG:4326")} );<br>
rss.events.register("loadend", window, populateMap);<br>
map.addLayer(rss);<br>
}<br>
<br>
function populateMap() {<br>
if(rss.markers.length >= 1) {<br>
var lastMarker=rss.markers[rss.markers.length-1];<br>
map.setCenter(lastMarker.lonlat, zoom);<br>
}<br>
map.raiseLayer(rss, 1);<br>
}<br>
<br>
</body>
</html>