setCenter takes different coordinates/projection for WMS & OSM?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

setCenter takes different coordinates/projection for WMS & OSM?

John Yook
Hi all,
I'm trying to create a map with multiple layers, and initialize it by setting its center.

Code is:

//javascript + knockout.js
self.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

_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|

Re: setCenter takes different coordinates/projection for WMS & OSM?

John Yook
Non-knockout code that shows same behavior:

var map = new OpenLayers.Map('My-OpenLayers-Map');
if (!_epsg4326) {
_epsg4326 = new OpenLayers.Projection("EPSG:4326");
}
var arrayOSM = ["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"];

var baseOSM = new OpenLayers.Layer.OSM("osm", arrayOSM);
var baseWMS = new OpenLayers.Layer.WMS("wms","http://vmap0.tiles.osgeo.org/wms/vmap0",{layers: "basic"});


map.addLayer(baseOSM);

map.addLayer(baseWMS);

map.addControl(new OpenLayers.Control.LayerSwitcher());

map.setCenter(
new OpenLayers.LonLat(-121.4668,45.7153).transform(
_epsg4326, map.getProjectionObject()), 14
);





From: [hidden email]
To: [hidden email]
Date: Thu, 1 Oct 2015 13:53:46 -0400
Subject: [OpenLayers-Users] setCenter takes different coordinates/projection for WMS & OSM?

Hi all,
I'm trying to create a map with multiple layers, and initialize it by setting its center.

Code is:

//javascript + knockout.js
self.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

_______________________________________________ Users mailing list [hidden email] http://lists.osgeo.org/mailman/listinfo/openlayers-users

_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users