2

In ArcGIS JS API, I would like to know and display the scale of a dynamic service layer by using the onExtentChange event, but the LOD argument is only valid for tile map services. Is there an equivalent way for dynamic map services?

2 Answers 2

1

The scale property applies to the map, not the individual layer, so you can use map.getScale() to display it.

You can get the map's level using map.getLevel(), but as you identified this only applies if there is a tiled layer in the map.

4
  • Thanks, Stephen.map.getScale() was introduced only in 3.1, and I am only using 2.8. Is there be an alternative way prior to 3.1? Oct 15, 2012 at 5:58
  • @NeoJigglypuff not sure, sorry. Is there any reason why you can't just upgrade? I've found it to be a very seamless process. Basically, you just need to change the reference from 2.8 to 3.x, noting that you'll need to use a local web server (rather than files in the file system) for local testing. See the migrating doco for details Oct 15, 2012 at 6:07
  • Upgrading from one version to another, though as simple as it may seem, will have an effect on all of our applications, with the retesting and QAs involved. Though it's good to know that a getScale method is present in 3.1. Thanks again. Oct 15, 2012 at 6:35
  • 2
    There's also esri.geometry.getScale which has been around longer than esri.Map.getScale: help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/… Oct 15, 2012 at 7:33
0

Instead of calculating scale on extentChange event , there is predefined scalebar in ArcGIS JS API, just add a scale bar widget while loading the map and give your map instance to ScaleBar widget like this ,

var scalebar = new Scalebar({
            map: this.currentMap,
            // "dual" displays both miles and kilometers
            // "english" is the default, which displays miles
            // use "metric" for kilometers
            scalebarUnit: "dual"
        });

https://developers.arcgis.com/javascript/3/jssamples/widget_scalebar.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.