JavaScript API - ArcGISDynamicMapServiceLayer SubLayer Scale Dependency Visibility

3697
12
07-16-2014 10:19 AM
BrandonColeman
New Contributor III

Background:

I am building a JavaScript web app using ESRI's JavaScript API v3.8, and our ArcGIS Server v9.3.1. I have layers I am rendering using the ArcGISDynamicMapServiceLayer, and I have been trying to find a way to access scale dependency visibility and have only been able to access the defaultVisibility.

Not Preferred Solution:

Using FeatureLayer for each layer allows me to check the MinScale against the map's current scale to determine whether the layer can be visible at that scale. I am trying to find a way to do this comparison using an ArcGISDynamicMapServiceLayer since it renders symbology based off of my map template or MSD file.

I would prefer to avoid setting up a dozen or so layers using FeatureLayer because I have to render each layer's symbology individually, since I am using ArcGIS Server v9.3.1, and it does not render it for me like 10.x+. This becomes tedious when I have a dozen or so layers each with a few class divisions.

Goal

I am using checkboxes for layer visibility, and if the layer isn't visible at the current scale, I am disabling and clearing the checkbox. I am using this as a way to tell the user that the layer isn't visible at this scale. A disabled control should be easier to understand than having a 'checked' checkbox and no layer showing up.

Anyone run into a similar situation? I am just trying to avoid coding in the symbology for all the layers as FeatureLayers.

Thanks!

0 Kudos
12 Replies
NicholasHaney
New Contributor III

I'm having a little trouble understanding the question. Based upon my understanding you wish to set the visibility of individual layers in a ArcGISDynamicMapServiceLayer to false if the current map scale is larger than a layer's minimum scale? Let me know if this is correct and I can proceed to solve the issue.

0 Kudos
JeffPace
MVP Alum

If you are trying to control the DynamicLayer you can set minscale and maxscale when you define it.

If you are trying to determine the scale visibility of the DynamicLayer, that is determined on each layer within it (the feature classes)

Those scale dependencies can be accessed through the layerInfos property

layerinfo-amd | API Reference | ArcGIS API for JavaScript

0 Kudos
BrandonColeman
New Contributor III

Nicholas Haney --> that is the general idea.  I am trying to directly tie it to the checkboxes I am using.  Have my checkboxes disabled if the layer can't be viewed at that scale or enabled and checked/not checked if it can be visible at that scale.

Jeff Pace‌ --> That is what I thought.  Below are the properties I am able to access through the layerInfo.  I pulled this out through Chrome's dev tools.  I know the property has to be there somewhere, but I cannot find it for anything.  I looked at the documentation on layerInfos and the information should be there.  I don't know if it would have something to do with my server being 9.3.1, which I have already seen is missing some of the nicer options in the more up-to-date versions.

Object {id: 0, name: "PilotBoundary", parentLayerId: -1, defaultVisibility: true, subLayerIds: null…}

  1. defaultVisibility: true
  2. id: 0
  3. name: "PilotBoundary"
  4. parentLayerId: -1
  5. subLayerIds: null
  6. __proto__: Object
    1. __inherited: function l(a,b,c){var d,
    2. constructor: function (){var c=arguments,d=c,e=c[0];if(!(this instanceof c.callee))return v(c);b&&(e&&(e=e.preamble)&&(d=e.apply(this,d)||d),(e=this.preamble)&&e.apply(this,d));a&&a.apply(this,c);(e=this.postscript)&&e.apply(this,c)}
    3. declaredClass: "esri.layers.LayerInfo"
    4. getInherited: function r(a,c){return"string"==
    5. inherited: function l(a,b,c){var d,
    6. isInstanceOf: function f(a){for(var c=this.constructor._meta.bases,b=0,d=c.length;b<d;++b)if(c===a)return!0;return this instanceof a}
    7. toJson: function (){return h.fixJson({defaultVisibility:this.defaultVisibility,id:this.id,maxScale:this.maxScale,minScale:this.minScale,
    8. __proto__: Object
0 Kudos
JeffPace
MVP Alum

i am surprised sublayerIds is null.  Does this service only have one layer?

Can you show the rest url?

And i have to tell you this, but my guess is this will not work at 9.3.1

0 Kudos
BrandonColeman
New Contributor III

There are 6 layers in there.  The URL is UTC_Viewers/Louisville_Pilot (MapServer)‌.

When I go into the individual layers there, it will show the minScale/maxScale, but they probably aren't exposed to the ArcGISDynamicMapServiceLayer in 9.3.1.

0 Kudos
JeffPace
MVP Alum

ahhh.... get the layerInfo on the DynamicLayer (LouisvillePilot) not the sublayer (PilotBoundary).

0 Kudos
BrandonColeman
New Contributor III

When I get the layerInfo from the DynamicLayer, I get a collection of objects returned:

[

Object

  1. defaultVisibility: true
  2. id: 0
  3. name: "PilotBoundary"
  4. parentLayerId: -1
  5. subLayerIds: null
  6. __proto__: Object

,

Object

  1. defaultVisibility: true
  2. id: 1
  3. name: "Block Groups 2012"
  4. parentLayerId: -1
  5. subLayerIds: null
  6. __proto__: Object

,

Object

  1. defaultVisibility: true
  2. id: 2
  3. name: "Neighborhoods 2012"
  4. parentLayerId: -1
  5. subLayerIds: null
  6. __proto__: Object



etc.etc.etc.

I still don't get the minScale property though.  I have been drilling down the properties through Chrome Dev Tools, but I still haven't found that yet.

0 Kudos
JeffPace
MVP Alum

instead of just sniffing, can you

console.dir(layer.layerInfos);

0 Kudos
BrandonColeman
New Contributor III

Didn't know of that.  I have been playing around in the interactive console window though on Chrome Dev Tools instead of coding it in though. 

I will definitely keep the dir in mind though when I am debugging in code though.  Thanks for that.

0 Kudos