Select to view content in your preferred language

How to get elevation at points/paths in a polyline Sketch in arcGIS JavascriptSDK?

162
3
Wednesday
Sparkles
New Contributor

I want the natural elevation at each point in a polyline (using SketchWidget in arcGIS SDK for Javascript). For example if the polyline runs over a mountain , I'd want the z values of each point in the polyline to be different, to reflect the natural elevation

I tried changing the elevationInfo mode of the GraphicsLayer for the SketchWidget to all of the possible settings.

With "absolute-height" - the elevation of the first point in the polyline is set as the z value of all the points (even though the elevation changes as my polyline runs over mountains)...

With "relative-to-ground", "relative-to-scene", and "on-the-ground", the z value of each point is 0. (Which makes sense, as it is giving the altitude RELATIVE to the terrain...)

No option seems to give the natural terrain elevation at each point.

Thanks for the help!

0 Kudos
3 Replies
Sparkles
New Contributor

Also, is there a callback that gets triggered at each point in the polyline? Sketch.on("create") only gets triggered at the first point. Thanks!

0 Kudos
JamesIng
New Contributor III

@Sparkles 

Someone else had a similar question around getting elevation for a point / polyline which I answered in this link:

https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-know-the-altitude-of-a-poi...

As for your question about callback there is also Sketch.on("update") which will trigger per update to the sketch.
You can then grab the latest sketch from that from the event graphic array.

The last set of co-ordinates in your path would be the last drawn point in a polyline.

e.g:

...
sketchViewModel.on(["update"], onGraphicUpdate);

function onGraphicUpdate(event) {
const graphic = event.graphics[0];
console.log('graphic', graphic)

}





James from www.landkind.com
0 Kudos
GreteSoosalu
Esri Contributor

Hi @Sparkles 

Are you experiencing this while drawing a new line?

In this case the "problem" is that the elevation constraint gets applied. This makes all vertices be drawn at the elevation of the first one. You can disable the elevation constraint by enabling the tooltips, using Tab  to enter the tooltips' input mode, and clicking on the lock icon next to the elevation/z field. Note that this needs to be done per feature. 

From the SketchViewModel documentation: 

When sketching polygons or polylines, the elevation constraint is applied by default. This means that all vertices use the z-value of the first vertex. To unlock the elevation constraint while sketching, make sure the tooltips and their inputs are enabled, and activate the input mode with the Tab key.


This behavior got introduced with version 4.29 in order to unify the drawing experience of polylines and polygons. But when drawing both, it is now possible to opt-out from this planar drawing mode. 

Hope this helps you further. Let me know in case you have any other questions. 

0 Kudos