[OpenLayers-Users] setCenter takes different coordinates/projection for WMS & OSM?

John Yook jbyook at hotmail.com
Thu Oct 1 10:53:46 PDT 2015


Hi all,I'm trying to create a map with multiple layers, and initialize it by setting its center.
Code is:
//javascript + knockout.jsself.initialize = function() {      self.epsg4326(new OpenLayers.Projection("EPSG:4326"));  //self.epsg4326 declared as an observable elsewhere
      self.map = new OpenLayers.Map('Little basic map');
      self.map.addLayer(new OpenLayers.Layer.OSM("osm",["http://otile1.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg",													  "http://otile2.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg",													  "http://otile3.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg",													  "http://otile4.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg"]));				      self.map.addLayer(new OpenLayers.Layer.WMS("wms","http://vmap0.tiles.osgeo.org/wms/vmap0",{layers: "basic"}));				      self.map.addControl(new OpenLayers.Control.LayerSwitcher());
      self.map.setCenter(new OpenLayers.LonLat(-105.0000,37.2500).transform(self.epsg4326(), self.getProjection()), 9);      //alternatively:      //self.map.setCenter(new OpenLayers.LonLat(-105.0000,37.2500), 9);}
With the transform, the osm layer is displayed correctly. Centered above Southern Colorado in North America. But, the wms layer is just blank. No "broken link" tile icons, even.
On the other hand, if I use LonLat without transforming it, the osm map starts out centered around 0,0: somewhere in the Gulf of Guinea. The wms layer works, however. It now starts out centered over Southern Colorado.
I have similar problems with other Layer types, like Google (which behaves like OSM) & ArcGIS93Rest (which behaves like WMS).
I've looked at the OpenLayers (2) documentation for Layer.OSM, WMS etc, but it doesn't shed any light on this.
Has anyone run into a similar problem, or can see what I'm doing wrong?
Thanks,
John 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20151001/f1356a4b/attachment.html>


More information about the Users mailing list