Select to view content in your preferred language

Map with initial extent and basemap not showing dynamic layer until after a map event

4281
1
12-10-2012 10:21 AM
DirkVandervoort
Frequent Contributor
Simple scenario:

I have a dynamic map service (operationalLayer) that I'd like to display on an ArcGIS basemap with the initial extent defined. The operationalLayer is secured and is on my server.

When I add the layers using the code below, the operationalLayer does not become visible until a map event - like a pan or zoom.

I've tried numerous permutations or this code bit still can not get the operationalLayer to be visible by default.

How can I get the operationalLayer to display?

    
<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() {
    var initExtent = new esri.geometry.Extent({"xmin":-12939189,"ymin":4198361,"xmax":-12713834,"ymax":4302895,"spatialReference":{"wkid":3421}});
    var map = new esri.Map("map"); 
    //var map = new esri.Map("map",{extent:initExtent}); // DOES NOT WORK, extent is correct for base map
                                                         // but the operationalLayer is not in the correct geography
    //map.setExtent(initExtent);  // This works BUT the 
                                  // operationalLayer doesn't display until a map event 
                                  // (e.g., pan or zoom)


   var basemap = new ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer");
    map.addLayer(basemap);  
    //map.setExtent(initExtent);  // This works BUT the 
                                  // operationalLayer doesn't display until a map event 
                                  // (e.g., pan or zoom)

   var operationalLayer = new ArcGISDynamicMapServiceLayer("http://MyServer/ArcGIS/rest/services/MyMapService/MapServer?token=someBigHugeGinormousRandomString");
   map.addLayer(operationalLayer);
   map.setExtent(initExtent);    // This works BUT the 
                                  // operationalLayer doesn't display until a map event 
                                  // (e.g., pan or zoom)
}

  dojo.addOnLoad(init);
</script>


What's really troublesome is that the code below (same scenario but without the secured map service) works.

    <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":0,"xmax":6222585,"ymax":5351408,"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>
0 Kudos
1 Reply
derekswingley1
Deactivated User
Since you're using an arcgis.com basemap, specify your initial extent in web mercator, not Nevada State Plane (wkid 3421).
0 Kudos