ArcGIS API – How to Set Scale Range for a Graphic Layer

arcgis-javascript-apihtml5

I am trying to set a Scale Range for a graphic layer using ArcGIS API in HTML5, so that the graphic layer is not visible on zooming beyond that particular ScaleRange.

For the same I have googled and looked into the ArcGIS API Documentation and examples but I am not able to find the correct syntax to do it.

Can anyone please throw in some suggestions for the syntax that I can try?
Currently I have used syntax like:

  • graphics.setMinScale=20000000
  • graphics.minScale=20000000
  • esri.graphics.minScale=20000000
  • esri.graphics.setMinScale=20000000
  • graphics.setScaleRange=20000000, 40000000
  • esri.graphics.setScaleRange=20000000, 40000000

I don't know none of the above syntax seems to be working out.

Best Answer

All layers in Esri's JS API have minScale and maxScale properties. This includes graphics layers. Once you've created a layer, you can you set minScale and maxScale directly (probably not recommended) or use one of the methods like setMinScale, setMaxScale or setScaleRange.

It looks like you were getting close to this with the stuff in your bulleted list but you're confusing properties and methods. Properties can be assigned a value with the syntax object.something = value but you have have to call methods. For example, calling a method: object.setScaleRange(min, max). You could also use zoom levels if your basemap is cached.

Modified version of a sample that shows this (zoom in or out to get outside the visible scale range for the graphics layer): http://jsbin.com/cihuvi/1/

Related Question