Select to view content in your preferred language

Dynamic Layer won't appear

2063
4
11-14-2012 11:38 PM
Thu_GiangDang
Emerging Contributor
Hello,

I'm a newbie to ArcGIS JavaScript API. I'm following the training material provided by ESRI when I encounter a problem. I'm trying to add a cached layer as the basemap and a dynamic layer as the operational layer. The map spatial reference is defined accordingly to the base map SR and it's in WGS 1984 (wkid = 4326). However my dynamic layer is in a spatial reference with wkid = 4757. According to this llink, both of them will be displayed. However when I try:
map.addLayers([basemap, operationalLayer])

only the base map appears. I check the Export call using the developer tool of the browser, and find out that my dynamic layer has the following parameters:
dpi:96
transparent:true
format:png8
bbox:-19687.435903608326,15574.1782288986,79364.82173477553,50684.9208499972
bboxSR:4326
imageSR:4326
size:1041,369

Both bboxSR and imageSR is in the map spatial reference. Does it mean my dynamic layer never gets re-projected on the fly?

When I remove the base map and set the map SR to 4757, the dynamic layer appears just fine. I tried to set the imageSpatialRefernce in imageParameters of the dynamic layer to 4757, still it did not show.

What should I do?

Thanks for reading.
0 Kudos
4 Replies
JohnGravois
Deactivated User
in your export call, it is correct that the bboxSR and imageSR are listed as 4326 (to match your cached basemap), but the values being passed for the bounding box are not valid for WGS84.  (ie.  they need to be between -180 and 180 for x and between -90 and 90 for y.) 

come to think of it, since WKID:4757 is another geographic coordinate system, the bounding box values aren't valid for that projection either.

i'm not sure whats going on, but if i had to guess i would say that something is wrong with one of your published services.  i would start by substituting a different basemap and a different operational layer one at a time to see which one is more trustworthy.

can you post the section of code where you construct the map and add the layers?
0 Kudos
ShreyasVakil
Frequent Contributor
ArcGISDynamicMapServiceLayer gets reprojected on the fly. We do not have to take care for the projection of the dynamic map service.

Take a look at this simple applicaiton which adds a basemap and adds ArcGISDynamicMapServiceLayer on top of it.

Spatial Refrence:

ArcGISTiledMapServiceLayer : 102100
ArcGISDynamicMapServiceLayer : 4269

Still both shows up on the map.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples 
    on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <title>Map Zoom Rectangle Symbol</title>
    
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/dojo/dijit/themes/claro/claro.css">
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/esri/css/esri.css" />
     
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.2"></script>
    <script type="text/javascript">
      dojo.require("esri.map");

      function init() {
        //configure map zoom rectangle fill by setting style by calling esri.symbol.SimpleFillSymbol.toJson()
        var initExtent = new esri.geometry.Extent({"xmin":-13814922,"ymin":332653,"xmax":6222585,"ymax":10351408,"spatialReference":{"wkid":102100}});
        var map = new esri.Map("map",{extent:initExtent});       
 
 var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer");
        map.addLayer(basemap);
 
 var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer");
 map.addLayer(operationalLayer);
      }

      dojo.addOnLoad(init);
    </script>
  </head>
  <body class="claro">
    Configure map zoom rectangle symbol
    <div id="map" style="width:1024px; height:512px; border:1px solid #000;"></div>
  </body>
</html>
 



Copy this code and replace the URL for ArcGISDynamicMapServiceLayer with your URL and see if it shows up on the map.

Let me know.

-Shreyas
0 Kudos
Thu_GiangDang
Emerging Contributor
Thanks for your replies.

@jgravois: I have tried with a basemap in 102100 and a dynamic map in 4326, the export did not work either. Maybe it's really something wrong when I publish the map services. The map services work fine with Flex API though. Here's the code I used to create the layers. All the map services are published on my local server.
dojo.require("esri.map")
   
var map;
   
function init() {
 var initialExtent = new esri.geometry.Extent(2030.12314635761, 15574.1782288986, 57647.2626848096,50684.9208499972, 
 new esri.SpatialReference({"wkid":4326}));
   
 map = new esri.Map("map", {extent: initialExtent} );
    
 var basemapURL="http://esrisa-nb1116/ArcGIS/rest/services/ppg/SDCP_BH/MapServer";
 var basemap = new esri.layers.ArcGISTiledMapServiceLayer(basemapURL);
    

 var operationalLayer = new esri.layers.ArcGISDynamicMapServiceLayer
    ("http://esrisa-nb1116/ArcGIS/rest/services/isag/SPT/MapServer");
 map.addLayers([basemap, operationalLayer]);
}
   
dojo.addOnLoad(init);


@svakil: the code run just right. The sample code from the training runs okay as well. It's only when I use my own map services that it has problems.
0 Kudos
JohnGravois
Deactivated User
the initialExtent object you are creating has invalid x and y values (as i said before, the x's need to be between -180 and 180 and the y's need to be between -90 and 90 when working with any geographic coordinate system). 

please try the following to see if you can see both layers?

//var initialExtent = new esri.geometry.Extent(2030.12314635761, 15574.1782288986, 57647.2626848096,50684.9208499972, 
//new esri.SpatialReference({"wkid":4326}));
   
//map = new esri.Map("map", {extent: initialExtent} );
//create the map without setting the extent property.  this allows the initial extent to be determined by the first layer loaded.
//map = new esri.Map("map");
0 Kudos