If i can get the current index of layer A, I think I add one to the int to move layer B directly beneath it.
I need to get layer A's index in the Contents pane.
Help is appreciated.
Hi Mike
Here is some code snippet that recursively checks through all the layers (including group layers) to move the layer.
In this example the layer I want to move is the "US Cities layer". I want to move this layer to be below US Counties layer.
Thanks
Uma
<SPAN class="keyword token">protected</SPAN> <SPAN class="keyword token">override</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">OnClick</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">var</SPAN> layerToMove <SPAN class="operator token">=</SPAN> MapView<SPAN class="punctuation token">.</SPAN>Active<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetLayersAsFlattenedList</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>OfType<SPAN class="operator token"><</SPAN>FeatureLayer<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">Where</SPAN><SPAN class="punctuation token">(</SPAN>f <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> f<SPAN class="punctuation token">.</SPAN>Name <SPAN class="operator token">==</SPAN> <SPAN class="string token">"U.S. Cities"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>layerToMove <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Layer U.S. Cities not found "</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">var</SPAN> moveBelowThisLayerName <SPAN class="operator token">=</SPAN> <SPAN class="string token">"U.S. Counties (Generalized)"</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//In order to move layerToMove, I need to know if the destination is a group layer and the zero based position it needs to move to.</SPAN> Tuple<SPAN class="operator token"><</SPAN>GroupLayer<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">int</SPAN><SPAN class="operator token">></SPAN> moveToLayerPosition <SPAN class="operator token">=</SPAN> <SPAN class="token function">FindLayerPosition</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">,</SPAN> moveBelowThisLayerName<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>moveToLayerPosition<SPAN class="punctuation token">.</SPAN>Item2 <SPAN class="operator token">==</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>$<SPAN class="string token">"Layer {moveBelowThisLayerName} not found "</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>moveToLayerPosition<SPAN class="punctuation token">.</SPAN>Item1 <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">//layer gets moved into the group</SPAN> moveToLayerPosition<SPAN class="punctuation token">.</SPAN>Item1<SPAN class="punctuation token">.</SPAN><SPAN class="token function">MoveLayer</SPAN><SPAN class="punctuation token">(</SPAN>layerToMove<SPAN class="punctuation token">,</SPAN> moveToLayerPosition<SPAN class="punctuation token">.</SPAN>Item2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="comment token">//Layer gets moved into the root</SPAN> MapView<SPAN class="punctuation token">.</SPAN>Active<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">MoveLayer</SPAN><SPAN class="punctuation token">(</SPAN>layerToMove<SPAN class="punctuation token">,</SPAN> moveToLayerPosition<SPAN class="punctuation token">.</SPAN>Item2<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">private</SPAN> Tuple<SPAN class="operator token"><</SPAN>GroupLayer<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">int</SPAN><SPAN class="operator token">></SPAN> <SPAN class="token function">FindLayerPosition</SPAN><SPAN class="punctuation token">(</SPAN>GroupLayer groupLayer<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">string</SPAN> moveToLayerNameBelow<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">int</SPAN> index <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">foreach</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> lyr <SPAN class="keyword token">in</SPAN> groupLayer <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="operator token">?</SPAN> groupLayer<SPAN class="punctuation token">.</SPAN>Layers <SPAN class="punctuation token">:</SPAN> MapView<SPAN class="punctuation token">.</SPAN>Active<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">.</SPAN>Layers<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> index<SPAN class="operator token">++</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>lyr <SPAN class="keyword token">is</SPAN> GroupLayer<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">//We descend into a group layer and search all the layers within.</SPAN> <SPAN class="keyword token">var</SPAN> result <SPAN class="operator token">=</SPAN> <SPAN class="token function">FindLayerPosition</SPAN><SPAN class="punctuation token">(</SPAN>lyr <SPAN class="keyword token">as</SPAN> GroupLayer<SPAN class="punctuation token">,</SPAN> moveToLayerNameBelow<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>result<SPAN class="punctuation token">.</SPAN>Item2 <SPAN class="operator token">>=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> result<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">continue</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>moveToLayerNameBelow <SPAN class="operator token">==</SPAN> lyr<SPAN class="punctuation token">.</SPAN>Name<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">//We have a match</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Tuple</SPAN><SPAN class="operator token"><</SPAN>GroupLayer<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">int</SPAN><SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN>groupLayer<SPAN class="punctuation token">,</SPAN> index<SPAN class="punctuation token">)</SPAN><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">new</SPAN> <SPAN class="token class-name">Tuple</SPAN><SPAN class="operator token"><</SPAN>GroupLayer<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">int</SPAN><SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="number token">1</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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
One way to do this is -
Well,
GVar<SPAN class="punctuation token">.</SPAN>index <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN> FeatureLayer layer_A <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">FindLayers</SPAN><SPAN class="punctuation token">(</SPAN>lyrname<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>OfType<SPAN class="operator token"><</SPAN>FeatureLayer<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> FeatureLayer<SPAN class="punctuation token">;</SPAN> GroupLayer grp <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">FindLayers</SPAN><SPAN class="punctuation token">(</SPAN>grplyrname<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>OfType<SPAN class="operator token"><</SPAN>GroupLayer<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> GroupLayer<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">int</SPAN> g <SPAN class="operator token">=</SPAN> grp<SPAN class="punctuation token">.</SPAN>Layers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">IndexOf</SPAN><SPAN class="punctuation token">(</SPAN>layer_A<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//when IN GroupLayer grp</SPAN> <SPAN class="keyword token">int</SPAN> m <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN>Layers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">IndexOf</SPAN><SPAN class="punctuation token">(</SPAN>layer_A<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//when merely in the active map</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>g <SPAN class="operator token">==</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">//g will return -1 as the index if it isn't inside the GroupLayer grp</SPAN> <SPAN class="punctuation token">{</SPAN> GVar<SPAN class="punctuation token">.</SPAN>index <SPAN class="operator token">=</SPAN> m<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//sets the index value of layer_A from the map</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN> GVar<SPAN class="punctuation token">.</SPAN>index <SPAN class="operator token">=</SPAN> g<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//otherwise sets the index value of layer_A from the GroupLayer grp</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">int</SPAN> cci <SPAN class="operator token">=</SPAN> GVar<SPAN class="punctuation token">.</SPAN>index <SPAN class="operator token">+</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//will be the index placment of Layer_B</SPAN> FeatureLayer layer_B <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetLayersAsFlattenedList</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>OfType<SPAN class="operator token"><</SPAN>FeatureLayer<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN>l <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> l<SPAN class="punctuation token">.</SPAN>Name <SPAN class="operator token">==</SPAN> <SPAN class="string token">"layer_B_name"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>g <SPAN class="operator token">==</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">MoveLayer</SPAN><SPAN class="punctuation token">(</SPAN>layer_B<SPAN class="punctuation token">,</SPAN> cci<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> grp<SPAN class="punctuation token">.</SPAN><SPAN class="token function">MoveLayer</SPAN><SPAN class="punctuation token">(</SPAN>layer_B<SPAN class="punctuation token">,</SPAN> cci<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>
This is good enough for now. However, If the user moves layer_A inside a group layer different from that specified, its index will default to -1 and place layer_B relative to its placement in the active map and not to the unspecified group layer. Further investigating Layer.Parent to identify the unspecified group layer in this scenario.
Thanks, Uma.
Uma,
I'm feeling pretty good about this approach. I was able to implement your footprint into my add-in tool.
I really appreciate your help.
<SPAN class="keyword token">private</SPAN> Tuple<SPAN class="operator token"><</SPAN>GroupLayer<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">int</SPAN><SPAN class="operator token">></SPAN> <SPAN class="token function">GetLyr_Loc</SPAN><SPAN class="punctuation token">(</SPAN>GroupLayer grplyr<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">string</SPAN> movebelowlayername<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> Map map <SPAN class="operator token">=</SPAN> MapView<SPAN class="punctuation token">.</SPAN>Active<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//solution footprint provided by Uma Harano, esristaff 2019</SPAN> <SPAN class="keyword token">int</SPAN> index <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">foreach</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> lyr <SPAN class="keyword token">in</SPAN> grplyr <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN> <SPAN class="operator token">?</SPAN> grplyr<SPAN class="punctuation token">.</SPAN>Layers <SPAN class="punctuation token">:</SPAN> map<SPAN class="punctuation token">.</SPAN>Layers<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> index<SPAN class="operator token">++</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>lyr <SPAN class="keyword token">is</SPAN> GroupLayer<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">//We descend into a group layer and search all the layers within.</SPAN> Tuple<SPAN class="operator token"><</SPAN>GroupLayer<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">int</SPAN><SPAN class="operator token">></SPAN> result <SPAN class="operator token">=</SPAN> <SPAN class="token function">GetLyr_Loc</SPAN><SPAN class="punctuation token">(</SPAN>lyr <SPAN class="keyword token">as</SPAN> GroupLayer<SPAN class="punctuation token">,</SPAN> movebelowlayername<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>result<SPAN class="punctuation token">.</SPAN>Item2 <SPAN class="operator token">>=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> result<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">continue</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>movebelowlayername <SPAN class="operator token">==</SPAN> lyr<SPAN class="punctuation token">.</SPAN>Name<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">//We have a match</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Tuple</SPAN><SPAN class="operator token"><</SPAN>GroupLayer<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">int</SPAN><SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN>grplyr<SPAN class="punctuation token">,</SPAN> index<SPAN class="punctuation token">)</SPAN><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">new</SPAN> <SPAN class="token class-name">Tuple</SPAN><SPAN class="operator token"><</SPAN>GroupLayer<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">int</SPAN><SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">async</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">cctvlstbx_MouseDoubleClick</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">object</SPAN> sender<SPAN class="punctuation token">,</SPAN> MouseEventArgs e<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">await</SPAN> <SPAN class="token function">ActMap</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> Map map <SPAN class="operator token">=</SPAN> MapView<SPAN class="punctuation token">.</SPAN>Active<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">;</SPAN> MapView MV <SPAN class="operator token">=</SPAN> MapView<SPAN class="punctuation token">.</SPAN>Active<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">string</SPAN> lyrname <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Sewer File Geodatabase"</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">string</SPAN> sublyrname <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Sewer Mains"</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Check for Sewer Mains in TOC</SPAN> <SPAN class="keyword token">string</SPAN> url <SPAN class="operator token">=</SPAN> GVar<SPAN class="punctuation token">.</SPAN>DL <SPAN class="operator token">+</SPAN> <SPAN class="string token">@"gisdata\layers\" + lyrname + "</SPAN><SPAN class="punctuation token">.</SPAN>lyr"<SPAN class="punctuation token">;</SPAN> Uri uri <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Uri</SPAN><SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">string</SPAN> cctvguide <SPAN class="operator token">=</SPAN> <SPAN class="string token">"ccTV Guide"</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">string</SPAN> url2 <SPAN class="operator token">=</SPAN> GVar<SPAN class="punctuation token">.</SPAN>DL <SPAN class="operator token">+</SPAN> <SPAN class="string token">@"gisdata\layers\" + cctvguide + "</SPAN><SPAN class="punctuation token">.</SPAN>lyr"<SPAN class="punctuation token">;</SPAN> Uri uri2 <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Uri</SPAN><SPAN class="punctuation token">(</SPAN>url2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> FeatureLayer lyrcheck3 <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetLayersAsFlattenedList</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>OfType<SPAN class="operator token"><</SPAN>FeatureLayer<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN>l <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> l<SPAN class="punctuation token">.</SPAN>Name <SPAN class="operator token">==</SPAN> sublyrname<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>lyrcheck3 <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">await</SPAN> QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> LayerFactory<SPAN class="punctuation token">.</SPAN>Instance<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CreateFeatureLayer</SPAN><SPAN class="punctuation token">(</SPAN>uri<SPAN class="punctuation token">,</SPAN> map<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> FeatureLayer ssmain_lyr <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">FindLayers</SPAN><SPAN class="punctuation token">(</SPAN>sublyrname<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>OfType<SPAN class="operator token"><</SPAN>FeatureLayer<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> FeatureLayer<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>ssmain_lyr<SPAN class="punctuation token">.</SPAN>IsVisible <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">await</SPAN> QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN> ssmain_lyr<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetVisibility</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">true</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> FeatureLayer lyrchck <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetLayersAsFlattenedList</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>OfType<SPAN class="operator token"><</SPAN>FeatureLayer<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN>l <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> l<SPAN class="punctuation token">.</SPAN>Name <SPAN class="operator token">==</SPAN> cctvguide<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>lyrchck <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>GVar<SPAN class="punctuation token">.</SPAN>cctvlyr <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">string</SPAN> message <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Would you like to add the ccTV Guide layer for reference?"</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">string</SPAN> caption <SPAN class="operator token">=</SPAN> <SPAN class="string token">" Add ccTV Guide?"</SPAN><SPAN class="punctuation token">;</SPAN> MessageBoxButtons buttons <SPAN class="operator token">=</SPAN> MessageBoxButtons<SPAN class="punctuation token">.</SPAN>YesNo<SPAN class="punctuation token">;</SPAN> MessageBoxIcon icon <SPAN class="operator token">=</SPAN> MessageBoxIcon<SPAN class="punctuation token">.</SPAN>Exclamation<SPAN class="punctuation token">;</SPAN> MessageBoxDefaultButton defbutton <SPAN class="operator token">=</SPAN> MessageBoxDefaultButton<SPAN class="punctuation token">.</SPAN>Button1<SPAN class="punctuation token">;</SPAN> MessageBoxOptions bxOpt <SPAN class="operator token">=</SPAN> MessageBoxOptions<SPAN class="punctuation token">.</SPAN>DefaultDesktopOnly<SPAN class="punctuation token">;</SPAN> DialogResult result<SPAN class="punctuation token">;</SPAN> result <SPAN class="operator token">=</SPAN> MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>message<SPAN class="punctuation token">,</SPAN> caption<SPAN class="punctuation token">,</SPAN> buttons<SPAN class="punctuation token">,</SPAN> icon<SPAN class="punctuation token">,</SPAN> defbutton<SPAN class="punctuation token">,</SPAN> bxOpt<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>result <SPAN class="operator token">==</SPAN> DialogResult<SPAN class="punctuation token">.</SPAN>Yes<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">await</SPAN> QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> LayerFactory<SPAN class="punctuation token">.</SPAN>Instance<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CreateFeatureLayer</SPAN><SPAN class="punctuation token">(</SPAN>uri2<SPAN class="punctuation token">,</SPAN> map<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">await</SPAN> MV<SPAN class="punctuation token">.</SPAN><SPAN class="token function">RedrawAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>result <SPAN class="operator token">==</SPAN> DialogResult<SPAN class="punctuation token">.</SPAN>No<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> GVar<SPAN class="punctuation token">.</SPAN>cctvlyr <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">false</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> FeatureLayer cctvlyr <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetLayersAsFlattenedList</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>OfType<SPAN class="operator token"><</SPAN>FeatureLayer<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN>l <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> l<SPAN class="punctuation token">.</SPAN>Name <SPAN class="operator token">==</SPAN> cctvguide<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>cctvlyr <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">//solution footprint provided by Uma Harano, esristaff 2019</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">//In order to move cctvlyr, I need to know if the destination is a group layer and the zero based position it needs to move to.</SPAN> Tuple<SPAN class="operator token"><</SPAN>GroupLayer<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">int</SPAN><SPAN class="operator token">></SPAN> MoveTo_Loc <SPAN class="operator token">=</SPAN> <SPAN class="token function">GetLyr_Loc</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">,</SPAN> sublyrname<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">await</SPAN> QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>MoveTo_Loc<SPAN class="punctuation token">.</SPAN>Item1 <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">//layer gets moved into the root</SPAN> <SPAN class="punctuation token">{</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">MoveLayer</SPAN><SPAN class="punctuation token">(</SPAN>cctvlyr<SPAN class="punctuation token">,</SPAN> MoveTo_Loc<SPAN class="punctuation token">.</SPAN>Item2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="comment token">//Layer gets moved into the group</SPAN> <SPAN class="punctuation token">{</SPAN> GVar<SPAN class="punctuation token">.</SPAN>containername <SPAN class="operator token">=</SPAN> MoveTo_Loc<SPAN class="punctuation token">.</SPAN>Item1<SPAN class="punctuation token">.</SPAN>Name<SPAN class="punctuation token">;</SPAN> MoveTo_Loc<SPAN class="punctuation token">.</SPAN>Item1<SPAN class="punctuation token">.</SPAN><SPAN class="token function">MoveLayer</SPAN><SPAN class="punctuation token">(</SPAN>cctvlyr<SPAN class="punctuation token">,</SPAN> MoveTo_Loc<SPAN class="punctuation token">.</SPAN>Item2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>cctvlyr<SPAN class="punctuation token">.</SPAN>IsVisible <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> cctvlyr<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetVisibility</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">true</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> GroupLayer sm_grp <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">FindLayers</SPAN><SPAN class="punctuation token">(</SPAN>GVar<SPAN class="punctuation token">.</SPAN>containername<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>OfType<SPAN class="operator token"><</SPAN>GroupLayer<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>sm_grp <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN> <SPAN class="operator token">&&</SPAN> sm_grp<SPAN class="punctuation token">.</SPAN>IsVisible <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">await</SPAN> QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN> sm_grp<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetVisibility</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">true</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="comment token">//further functions below...</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></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></SPAN>
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.