I'm trying to determine layer types for the current map service.
The starter code here is great: https://developers.arcgis.com/web-appbuilder/api-reference/layerstructure.htm
I'm doing the following, which mostly works.
printLayerTree<SPAN class="punctuation token">:</SPAN><SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">// dont need to lang.hitch, but here because was calling into outside functions</SPAN>
<SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>layerStructure<SPAN class="punctuation token">.</SPAN><SPAN class="token function">traversal</SPAN><SPAN class="punctuation token">(</SPAN>lang<SPAN class="punctuation token">.</SPAN><SPAN class="token function">hitch</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>layerNode<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> indent <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">for</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> i <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN> i <SPAN class="operator token"><</SPAN> layerNode<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getNodeLevel</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> i<SPAN class="operator token">++</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>indent <SPAN class="operator token">+</SPAN><SPAN class="operator token">=</SPAN> <SPAN class="string token">" "</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="punctuation token">}</SPAN>
layerNode<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getLayerType</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">resolve</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">then</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>lt<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN>
console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN>indent<SPAN class="punctuation token">,</SPAN> layerNode<SPAN class="punctuation token">.</SPAN>title <SPAN class="operator token">+</SPAN> <SPAN class="string token">" >> "</SPAN> <SPAN class="operator token">+</SPAN> lt<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="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>However, for layers in group layers inside a map service, its failing to get type. From the below the first 2 are feature service layers, the 3rd is a map service (Gillnet is a single layer added to webmap directly), and the Coral and Commercial Fishery are entire map services that make use of Group Layers (the GL type shows up, but not the "Feature Layer/ Raster Layer").
DataViewerEditExample <SPAN class="operator token">-</SPAN> Resource Points <SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> FeatureLayer
DataViewerEditExample <SPAN class="operator token">-</SPAN> Shoreline <SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> FeatureLayer
Gillnet <SPAN class="number token">2012</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">2015</SPAN> <SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> FeatureLayer
Coral Conservation Protection <SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> ArcGISDynamicMapServiceLayer
Marine Protected Areas <SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> undefined
Provincial_Ecological_Reserves <SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> undefined
Other Effective Area<SPAN class="operator token">-</SPAN>Based Conservation Measure <SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> undefined
Commercial Fishery by Gear Type <SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> ArcGISDynamicMapServiceLayer
Fixed Gear <SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> GroupLayer
Gillnet <SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> GroupLayer
Gillnet <SPAN class="number token">2012</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">2015</SPAN> <SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> undefined
Gillnet <SPAN class="number token">2008</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">2011</SPAN> <SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> undefined
Longline <SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> GroupLayer
Longline <SPAN class="number token">2012</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">2015</SPAN> <SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> undefined
Longline <SPAN class="number token">2008</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">2011</SPAN> <SPAN class="operator token">></SPAN><SPAN class="operator token">></SPAN> undefined
<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>Further research:
- fails in the same way for both 10.4.1 and 10.6.1 (so it's not the server)
The layerNode._layerInfo.layerObject has a key/value of empty:true for layers that are returning undefined types. So I tried to getLayerObject(), but the results for these layers all return undefined as well. This seems related. Perhaps something isn't hydrated. But not sure how I can force it short of calling the functions I already am...
<SPAN class="keyword token">var</SPAN> def <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Deferred</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
layerNode<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getLayerObject</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">then</SPAN><SPAN class="punctuation token">(</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>layerObject<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
def<SPAN class="punctuation token">.</SPAN><SPAN class="token function">resolve</SPAN><SPAN class="punctuation token">(</SPAN>layerObject<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>Am I doing something wrong?
thanks