Get the current scale for sceneView

4455
1
Jump to solution
06-01-2016 12:50 PM
MichaelHeirendt
New Contributor

Hello,

I am currently updating nliu's TOC for version 3.16 here:

https://www.arcgis.com/home/item.html?id=9b6280a6bfb0430f8d1ebc969276b109

to be compatible with V 4.x. I have made some good progress, but am stuck on the scale property of the view.  In version 3.x, the map object had the method .getScale() to get the current scale. The TOC calls this method to know whether to display/block out scale dependent layers. However, the scene view has no such property, but in the documentation it claims:

'Traditional 2D mapping properties, such as scale, zoom, center and extent do not always work well in 3D. For example, a map's scale is not clear when viewed in the context of a globe. The SceneView therefore supports these properties on a best effort basis, with certain limitations'

Any ideas on how to get the value being used as 'scale' on the zoom event?

0 Kudos
1 Solution

Accepted Solutions
KristianEkenes
Esri Regular Contributor
> However, the scene view has no such property

The SceneView does have this property. See the documentation here - SceneView | API Reference | ArcGIS API for JavaScript 4.0

You can access the scale by simply referencing the property:

var view = new SceneView({
map: map,
container: "viewDiv"
});
console.log(view.scale);

You can even set the scale in the constructor:

var view = new SceneView({
map: map,
container: "viewDiv",
scale: 24000
});
console.log(view.scale);

You can also watch the scale and do something with it each time it changes:

var view = new SceneView({
map: map,
container: "viewDiv"
});
view.watch("scale", function(newScale){
console.log("scale: ", newScale);
});

> 'Traditional 2D mapping properties, such as scale, zoom, center and extent do not always work well in 3D. For example, a map's scale is not clear when viewed in the context of a globe. The SceneView therefore supports these properties on a best effort basis, with certain limitations'

This is talking about how a SceneView's actual scale will be different at any given point in the view. When we say SceneView.scale, what that actually refers to is the scale at the center of the view. This number does not reflect the scale at any other point in the view because of the earth's curvature. That's why working with scale in 3D can be problematic. Using SceneView.scale is still valid, but you should be aware of the issues surrounding scale in 3D.

View solution in original post

1 Reply
KristianEkenes
Esri Regular Contributor
> However, the scene view has no such property

The SceneView does have this property. See the documentation here - SceneView | API Reference | ArcGIS API for JavaScript 4.0

You can access the scale by simply referencing the property:

var view = new SceneView({
map: map,
container: "viewDiv"
});
console.log(view.scale);

You can even set the scale in the constructor:

var view = new SceneView({
map: map,
container: "viewDiv",
scale: 24000
});
console.log(view.scale);

You can also watch the scale and do something with it each time it changes:

var view = new SceneView({
map: map,
container: "viewDiv"
});
view.watch("scale", function(newScale){
console.log("scale: ", newScale);
});

> 'Traditional 2D mapping properties, such as scale, zoom, center and extent do not always work well in 3D. For example, a map's scale is not clear when viewed in the context of a globe. The SceneView therefore supports these properties on a best effort basis, with certain limitations'

This is talking about how a SceneView's actual scale will be different at any given point in the view. When we say SceneView.scale, what that actually refers to is the scale at the center of the view. This number does not reflect the scale at any other point in the view because of the earth's curvature. That's why working with scale in 3D can be problematic. Using SceneView.scale is still valid, but you should be aware of the issues surrounding scale in 3D.