[OpenLayers-Users] setCenter does not work properly with an OSM layer?

Christopher Schmidt crschmidt at metacarta.com
Sun Mar 8 21:02:01 EDT 2009


On Mon, Mar 09, 2009 at 12:02:40AM +0100, Maarten Deen wrote:
> When I'm making a map with a WMS layer, then the .setCenter works as expected. 
> But when I replace the WMS layer with the OSM layer, than zooming with 
> .setCenter works, but the map is always centered at 0,0.

OSM units are projected. Read
http://docs.openlayers.org/library/spherical_mercator .

> Is it something I'm doing wrong?
> 
> The code I'm using is
>          var map;
> 
>          function init(){
>              map = new OpenLayers.Map('map', {
>                        controls:[new OpenLayers.Control.Navigation(),
>                                  new OpenLayers.Control.PanZoomBar(),
>                                  new OpenLayers.Control.ScaleLine(),
>                                  new OpenLayers.Control.MousePosition(),
>                                  new OpenLayers.Control.Permalink(),
>                                  new OpenLayers.Control.Attribution()
>                        ],
>                        maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
>                        displayProjection: new OpenLayers.Projection("EPSG:4326"),
> 	                  maxResolution:'auto'
> 	            });
>              layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
>                  "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
>              map.addLayer(layer);
> 
>              map.setCenter(new OpenLayers.LonLat(5.3,52.15),6);
> 
> or change the last lines to:
> 
>              layer = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
>              map.addLayer(layer);
> 
>              map.setCenter(new OpenLayers.LonLat(5.3,52.15),6);
> 
> (or complete html at http://www.maasluip.nl/ebt/georss-markers-wms.html and 
> http://www.maasluip.nl/ebt/georss-markers-osm.html)
> 
> Regards,
> Maarten
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users



More information about the Users mailing list