Select to view content in your preferred language

Problems with Open Street Map layer and a dynamic layer

1228
4
01-08-2013 10:09 AM
CraigPennington
Occasional Contributor
I am trying to display an Open Street Map (OSM) layer along with a dynamic layer. If I display just one of these, it works as expected. If I make the OSM layer the first layer and add a dynamic layer, both display, but any dragging or zooming makes the dynamic disappear. If I make the dynamic layer first, the OSM layer, which should be on top, does not show at all.

The coordinate systems of the two layers are different, and maybe that's the problem. I have not addressed that yet and suggestions on how to do that are welcome. The dynamic layer is the state of Hawaii. The extent I'm using is correct for it (Oahu), and the OSM layer shows an area in Africa for that extent, but I have not yet worried about that. Since the extent does show data for each layer, it seems that the combination of layers should at least both show.

The code is attached
0 Kudos
4 Replies
JeffJacobson
Frequent Contributor
You need to make sure you add the OSM layer first to set the map's spatial reference system to match your tiled layer. When your dynamic service is added, it will be projected on the fly to match.

require(["esri/map", "esri/layers/osm", "esri/layers/agsdynamic"], function() {

  var map, osmLayer, url, HISlayer;

  map = new esri.Map("map");
  osmLayer = new esri.layers.OpenStreetMapLayer({ id: "OSM" });
  
  var url = "http://mapsLiveCB.hawaiiinformation.com/ArcGIS/rest/services/HIS_BASE_Standard/MapServer";
  HISlayer = new esri.layers.ArcGISDynamicMapServiceLayer(url, { id: "standard" });
    
  map.addLayer(osmLayer);
  map.addLayer(HISlayer);
});
0 Kudos
CraigPennington
Occasional Contributor
Thanks for the reply.  It seems the only substantial changes you suggested were to start the layers visible and to load them separately with addLayer() instead of loading an array of layers with addLayers().  The program does load the OSM layer first in the OSM_HIS mode.  I've expanded the program (attached) to allow testing separate or array loads and found no difference.

When OSM is loaded first, and the extent for Oahu based on the dynamic HIS layer is set, the OSM layer shows Africa with Oahu from the dynamic layer on top (which disappears if panned or zoomed).  If it were projected on the fly, as you suggest it should be and I had hoped it would be, the dynamic Oahu should not have shown in Africa.  If I instead use an extent for Oahu on OSM, the OSM Oahu shows, but the dynamic Oahu is not there, again indicating the on-the-fly projecting is not taking place.

I wonder if I need some addtional setting/step to make the on-the-fly projection work.

Is on-the-fly projection of non-first layers expected to work only for tile layers?  The OSM layer class is a subclass of the tile class.
0 Kudos
DavideLimosani
Frequent Contributor
They must have the same datum to work properly.

you are projecting a dynamic layer with this coordinate system http://spatialreference.org/ref/epsg/3760/esriwkt/ 

DATUM["D_North_American_1983_HARN",SPHEROID["GRS_1980",6378137,298.257222101]]

on a basemap with this one http://spatialreference.org/ref/sr-org/7483/esriwkt/

DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]]


Davide
0 Kudos
JeffJacobson
Frequent Contributor
Thanks for the reply.  It seems the only substantial changes you suggested were to start the layers visible and to load them separately with addLayer() instead of loading an array of layers with addLayers().  The program does load the OSM layer first in the OSM_HIS mode.  I've expanded the program (attached) to allow testing separate or array loads and found no difference.

When OSM is loaded first, and the extent for Oahu based on the dynamic HIS layer is set, the OSM layer shows Africa with Oahu from the dynamic layer on top (which disappears if panned or zoomed).  If it were projected on the fly, as you suggest it should be and I had hoped it would be, the dynamic Oahu should not have shown in Africa.  If I instead use an extent for Oahu on OSM, the OSM Oahu shows, but the dynamic Oahu is not there, again indicating the on-the-fly projecting is not taking place.

I wonder if I need some addtional setting/step to make the on-the-fly projection work.

Is on-the-fly projection of non-first layers expected to work only for tile layers?  The OSM layer class is a subclass of the tile class.


I've got it running on jsFiddle. If you zoom in to Hawaii you'll see your layer overlapping the basemap.
0 Kudos