Hello, I have create a custom elevation layer based on the Custom ElevationLayer Example with TypeScript, here is my code:
<SPAN class="keyword token">import</SPAN> <SPAN class="punctuation token">{</SPAN>
subclass<SPAN class="punctuation token">,</SPAN> declared<SPAN class="punctuation token">,</SPAN> property
<SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">from</SPAN> <SPAN class="string token">"esri/core/accessorSupport/decorators"</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">import</SPAN> BaseElevationLayer <SPAN class="operator token">=</SPAN> <SPAN class="token function">require</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'esri/layers/BaseElevationLayer'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">import</SPAN> ElevationLayer <SPAN class="operator token">=</SPAN> <SPAN class="token function">require</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'esri/layers/ElevationLayer'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
@<SPAN class="token function">subclass</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'beginor.ExaggeratedElevationLayer'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">ExaggeratedElevationLayer</SPAN> <SPAN class="keyword token">extends</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">declared</SPAN><SPAN class="punctuation token">(</SPAN>BaseElevationLayer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
@<SPAN class="token function">property</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">public</SPAN> exaggeration<SPAN class="punctuation token">:</SPAN> number<SPAN class="punctuation token">;</SPAN>
@<SPAN class="token function">property</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">public</SPAN> url<SPAN class="punctuation token">:</SPAN> string<SPAN class="punctuation token">;</SPAN>
@<SPAN class="token function">property</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">get</SPAN> <SPAN class="token function">type</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> string <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="string token">'exaggerated-elevation'</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">private</SPAN> elevation<SPAN class="punctuation token">:</SPAN> ElevationLayer<SPAN class="punctuation token">;</SPAN>
<SPAN class="token function">constructor</SPAN><SPAN class="punctuation token">(</SPAN>properties<SPAN class="punctuation token">:</SPAN> ExaggeratedElevationLayerProperties<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">super</SPAN><SPAN class="punctuation token">(</SPAN>properties<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="operator token">!</SPAN><SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>exaggeration<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>exaggeration <SPAN class="operator token">=</SPAN> <SPAN class="number token">1.0</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">public</SPAN> <SPAN class="token function">load</SPAN><SPAN class="punctuation token">(</SPAN>signal<SPAN class="punctuation token">:</SPAN> AbortSignal<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> IPromise<SPAN class="operator token"><</SPAN>any<SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>elevation <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">ElevationLayer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN>
url<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>url
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">addResolvingPromise</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>elevation<SPAN class="punctuation token">.</SPAN><SPAN class="token function">load</SPAN><SPAN class="punctuation token">(</SPAN>signal<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="token function">fetchTile</SPAN><SPAN class="punctuation token">(</SPAN>
level<SPAN class="punctuation token">:</SPAN> number<SPAN class="punctuation token">,</SPAN>
row<SPAN class="punctuation token">:</SPAN> number<SPAN class="punctuation token">,</SPAN>
column<SPAN class="punctuation token">:</SPAN> number<SPAN class="punctuation token">,</SPAN>
options<SPAN class="punctuation token">:</SPAN> __esri<SPAN class="punctuation token">.</SPAN>ElevationLayerFetchTileOptions
<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> IPromise<SPAN class="operator token"><</SPAN>__esri<SPAN class="punctuation token">.</SPAN>ElevationTileData<SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>elevation<SPAN class="punctuation token">.</SPAN><SPAN class="token function">fetchTile</SPAN><SPAN class="punctuation token">(</SPAN>level<SPAN class="punctuation token">,</SPAN> row<SPAN class="punctuation token">,</SPAN> column<SPAN class="punctuation token">,</SPAN> options<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">then</SPAN><SPAN class="punctuation token">(</SPAN>
data <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">const</SPAN> exag <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>exaggeration<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">for</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">let</SPAN> i <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN> i <SPAN class="operator token"><</SPAN> data<SPAN class="punctuation token">.</SPAN>values<SPAN class="punctuation token">.</SPAN>length<SPAN class="punctuation token">;</SPAN> i<SPAN class="operator token">++</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
data<SPAN class="punctuation token">.</SPAN>values<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> data<SPAN class="punctuation token">.</SPAN>values<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">*</SPAN> exag<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">return</SPAN> data<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">interface</SPAN> <SPAN class="token class-name">ExaggeratedElevationLayerProperties</SPAN> <SPAN class="keyword token">extends</SPAN> <SPAN class="token class-name">__esri<SPAN class="punctuation token">.</SPAN>BaseElevationLayerProperties</SPAN> <SPAN class="punctuation token">{</SPAN>
url<SPAN class="punctuation token">:</SPAN> string<SPAN class="punctuation token">;</SPAN>
exaggeration<SPAN class="operator token">?</SPAN><SPAN class="punctuation token">:</SPAN> number<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">export</SPAN> <SPAN class="operator token">=</SPAN> ExaggeratedElevationLayer<SPAN class="punctuation token">;</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>And I can use it in a webscene like this:
<SPAN class="keyword token">import</SPAN> WebScene <SPAN class="operator token">=</SPAN> <SPAN class="token function">require</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'esri/Map'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">import</SPAN> SceneView <SPAN class="operator token">=</SPAN> <SPAN class="token function">require</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'esri/views/SceneView'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">import</SPAN> externalRenderers <SPAN class="operator token">=</SPAN> <SPAN class="token function">require</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'esri/views/3d/externalRenderers'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">import</SPAN> ExaggeratedElevationLayer <SPAN class="operator token">=</SPAN> <SPAN class="token function">require</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'beginor/ExaggeratedElevationLayer'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">const</SPAN> map <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">WebScene</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN>
basemap<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'streets'</SPAN><SPAN class="punctuation token">,</SPAN>
ground<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN>
layers<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN>
<SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">ExaggeratedElevationLayer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN>
url<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer'</SPAN><SPAN class="punctuation token">,</SPAN>
exaggeration<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">5</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">]</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">const</SPAN> view <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">SceneView</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN>
map<SPAN class="punctuation token">:</SPAN> map<SPAN class="punctuation token">,</SPAN>
container<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'viewDiv'</SPAN><SPAN class="punctuation token">,</SPAN>
center<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">113.2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">23.4</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
zoom<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">13</SPAN><SPAN class="punctuation token">,</SPAN>
camera<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN>
position<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN>
spatialReference<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN> wkid<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">102100</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
x<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">12601020.732296046</SPAN><SPAN class="punctuation token">,</SPAN>
y<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">2661706.7320940713</SPAN><SPAN class="punctuation token">,</SPAN>
z<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">10515.040601080284</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
heading<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN>
tilt<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">60</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>But when I want to change the exaggeration at runtime, I have tried find the exaggerated elevation layer from the ground , change the exaggeration property, but this does not work.
The only way I found is remove the exaggerated vation layer from the ground, and recreate a new exaggerated elevation layer , and add it the the ground's layers, like this:
<SPAN class="keyword token">var</SPAN> btnTgl <SPAN class="operator token">=</SPAN> document<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getElementById</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'eleTgl'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> HTMLButtonElement<SPAN class="punctuation token">;</SPAN>
btnTgl<SPAN class="punctuation token">.</SPAN><SPAN class="token function">addEventListener</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'click'</SPAN><SPAN class="punctuation token">,</SPAN> e <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">const</SPAN> ground <SPAN class="operator token">=</SPAN> view<SPAN class="punctuation token">.</SPAN>map<SPAN class="punctuation token">.</SPAN>ground<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> eleLayer <SPAN class="operator token">=</SPAN> ground<SPAN class="punctuation token">.</SPAN>layers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getItemAt</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
ground<SPAN class="punctuation token">.</SPAN>layers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">remove</SPAN><SPAN class="punctuation token">(</SPAN>eleLayer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">let</SPAN> exLayer <SPAN class="operator token">=</SPAN> eleLayer <SPAN class="keyword token">as</SPAN> any <SPAN class="keyword token">as</SPAN> ExaggeratedElevationLayer<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>exLayer<SPAN class="punctuation token">.</SPAN>exaggeration <SPAN class="operator token">==</SPAN> <SPAN class="number token">5</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
exLayer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">ExaggeratedElevationLayer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN>
exaggeration<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN>
url<SPAN class="punctuation token">:</SPAN> exLayer<SPAN class="punctuation token">.</SPAN>url
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN>
exLayer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">ExaggeratedElevationLayer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN>
exaggeration<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">5</SPAN><SPAN class="punctuation token">,</SPAN>
url<SPAN class="punctuation token">:</SPAN> exLayer<SPAN class="punctuation token">.</SPAN>url
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
ground<SPAN class="punctuation token">.</SPAN>layers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">add</SPAN><SPAN class="punctuation token">(</SPAN>exLayer <SPAN class="keyword token">as</SPAN> any<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>This works, but I think it is not the mose efficient way, because it will reload lots of elevation data from server again.
So my question is: Is there a more efficient way to change elevation aggeration at runtime?