Dynamic layer info minScale/maxScale bug in ArcGIS JavaScript API 3.0?

4884
9
Jump to solution
07-04-2012 01:45 PM
QuinWong
Occasional Contributor
Hi,

  I think I found a bug in ArcGIS JavaScript API 3.0 when using the dynamic layer info's minScale & maxScale properties.  Here are the steps:

  1) Create a new esri.layers.ArcGISDynamicMapServiceLayer (dynamicMapService)
  2) Create a new esri.layers.DynamicLayerInfo (dynamicLayerInfo)
  3) Set dynamicLayerInfo.minScale to something non-zero
  4) Set dynamicLayerInfo.maxScale to something non-zero
  5) Add dynamicLayerInfo to a new array (dynamicLayerInfoArray)
  6) Use dynamicMapService.setDynamicLayerInfos(dynamicLayerInfoArray) to set the map service's dynamic layer infos (you may also have to set the LayerDrawingOptions).
  7) Now, run your app and zoom in/out beyond the minScale/maxScale you chose

  Pow!  You get the following response:

  {"error":{"code":400,"message":"Missing 'source' in dynamic layer definition for 'id': -1.","details":[]}}

  If you examine the HTTP request sent to the server, it will look something like this:

  http://yourserver.com:6080/arcgis/rest/services/YourMapService/MapServer/export? ... dynamicLayers=[{}] ...

  I think it's because of those curly braces because if you get rid of them, it works just fine (although it should probably just omit the dynamicLayers parameter altogether).  I think in the Silverlight API, it simply refrains from sending the HTTP request when you zoom beyond the specified minScale/maxScale.

  Is anyone else experiencing this bug?  I don't think there's much I can do about it but if anyone has any ideas, I would very much appreciate it.  🙂

Cheers!
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Deactivated User
This will be fixed in the next release, which is probably ~2 months away since we released 3.1 today.

View solution in original post

0 Kudos
9 Replies
QuinWong
Occasional Contributor
Anyone...?
0 Kudos
QuinWong
Occasional Contributor
*A lone wolf howls in the distance*
0 Kudos
derekswingley1
Deactivated User
I'll try to take a look at this later today.

Two things for future reference:
�??instead of providing repro steps, repro code is preferred when reporting a bug
�??the official way to report a bug is to go through tech support, which you can do even when you do not pay for support; use this form and select "bug":  http://support.esri.com/en/webform/support/customerId/5753/chat/false
0 Kudos
derekswingley1
Deactivated User
This looks like a bug. I'll post back here once I can confirm.

One possible workaround is to use the minScale and maxScale properties at the ArcGISDynamicMapServiceLayer level. These properties are new with version 3.1 of the API. Here's an example:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <title></title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.1/js/dojo/dijit/themes/tundra/tundra.css" />
    <style>
      html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
      h3 { margin: 0 0 5px 0; border-bottom: 1px solid #444; text-align: center }
      .shadow {
        -moz-box-shadow: 0 0 5px #888;
        -webkit-box-shadow: 0 0 5px #888;
        box-shadow: 0 0 5px #888;
      }
      #map{ margin: 0; padding: 0; }
      #feedback {
        background: #fff;
        color: #444;
        position: absolute;
        font-family: arial;
        height: 40px;
        left: 30px;
        margin: 5px;
        padding: 10px;
        bottom: 30px;
        text-align: center;
        width: 320px;
        z-index: 40;
      }
      .note { font-size: 80%; padding: 0 0 10px 0; }
      #slider {
        color: #666; 
        margin: 5px auto;
        padding: 3px;
      }
      #appSliderLabel { padding: 0 0 10px 0; }
      #maxLabel { display: inline-block; margin: 0 0 0 -30px;}
      #minLabel { display: inline-block; margin: 0 0 0 30px;}
      #breakInfo { padding: 20px 0 0 0; }
      
    </style>
    <script>var dojoConfig = { parseOnLoad: true };</script>
    <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.1"></script>
    <script>
      dojo.require("dijit.layout.BorderContainer");
      dojo.require("dijit.layout.ContentPane");
      dojo.require("esri.map");

      // one global for persistent app variables
      var app = {};

      function init() {
        var ext, basemap, usaUrl;        
        ext = new esri.geometry.Extent({"xmin":-14332474,"ymin":3248843,"xmax":-8070752,"ymax":5464906,"spatialReference":{"wkid":102100}});
        
        app.map = new esri.Map("map", { 
          "extent": ext, 
          "slider": false
        });
        dojo.connect(app.map, "onLoad", function() {
          dojo.connect(dijit.byId("map"), "resize", app.map, app.map.resize);
          dojo.connect(app.map, "onZoomEnd", updateScale);
          updateScale();
        });

        basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer");
        app.map.addLayer(basemap);

        // set up a layer to show counties as a dynamic map service
        // set visible layers to [2]
        usaUrl = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer";
        app.usaLayer = new esri.layers.ArcGISDynamicMapServiceLayer(usaUrl, { 
          "id": "usa",
          "opacity": 0.7
        });
        dojo.connect(app.usaLayer, "onLoad", function() {
          app.usaLayer.setVisibleLayers([2]);
          app.usaLayer.maxScale = 10000000;
          app.usaLayer.minScale = 20000000;
          // console.log("set dyn layer infos...", infos);
        });
        app.map.addLayer(app.usaLayer);
      }

      function updateScale() {
        dojo.byId("map-scale").innerHTML = dojo.number.format(parseInt(app.map.getScale()));
      }

      function errorHandler(err) {
        console.log('Oops, error: ', err);
      }

      dojo.ready(init);
    </script>
  </head>

  <body class="tundra">
    <div data-dojo-type="dijit.layout.BorderContainer"
         data-dojo-props="design:'headline',gutters:false"
         style="width: 100%; height: 100%; margin: 0;">
      <div id="map"
           data-dojo-type="dijit.layout.ContentPane"
           data-dojo-props="region:'center'">

        <div id="feedback" class="shadow">
          Map scale: <span id="map-scale">unknown</span>
        </div>
      </div>
    </div>
  </body>
</html>


JSFiddle:  http://jsfiddle.net/MDvzT/
0 Kudos
QuinWong
Occasional Contributor
Thank you for looking into it.  I probably can't use your workaround in my particular case but thanks for the suggestion.

Any idea of when this might be fixed?
0 Kudos
derekswingley1
Deactivated User
This will be fixed in the next release, which is probably ~2 months away since we released 3.1 today.
0 Kudos
QuinWong
Occasional Contributor
That would be great - thank you.
0 Kudos
JoanneMcGraw
Frequent Contributor
swingley,

I noticed 3.2 was released on September 12, 2012. Did a fix to the bug noted in this post find it's way in there?

I believe I am having similar problems to those described in this thread, but the problem continues with 3.2. If a fix that addresses the bug noted in this thread is in there, then I'm probably not having the same problem after all.

(Added later: I take it back. The fix is in there and 3.2 has dealt with my problem.)
Cheers,
jtm
0 Kudos
derekswingley1
Deactivated User


Thanks for confirming!
0 Kudos