Skip to content

Commit

Permalink
CNX-9501 agis highlighting loaded elements (#3443)
Browse files Browse the repository at this point in the history
* get URIs of received layers

* add TOC selection (highlight) - because non-feature layers and multipatch feature layers will not be visible on the canvas. Also there might be multiple layers with the same shapes but different properties, just canvas selection might not be helpful

* select features from the entire layer

* conflicts

---------

Co-authored-by: Alan Rynne <[email protected]>
  • Loading branch information
KatKatKateryna and AlanRynne authored May 30, 2024
1 parent 5469a12 commit 0920d7c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Reflection;
using ArcGIS.Core.Data;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
Expand Down Expand Up @@ -85,7 +83,9 @@ await QueuedTask
.Run(() =>
{
List<MapMember> mapMembers = GetMapMembers(objectIds, mapView);
ClearSelectionInTOC();
ClearSelection();
SelectMapMembersInTOC(mapMembers);
SelectMapMembers(mapMembers);
mapView.ZoomToSelected();
})
Expand Down Expand Up @@ -125,26 +125,39 @@ private void ClearSelection()
}
}

private void ClearSelectionInTOC()
{
MapView.Active.ClearTOCSelection();
}

private void SelectMapMembers(List<MapMember> mapMembers)
{
foreach (var member in mapMembers)
{
if (member is FeatureLayer featureLayer)
if (member is FeatureLayer layer)
{
layer.Select();
}
}
}

private void SelectMapMembersInTOC(List<MapMember> mapMembers)
{
List<Layer> layers = new();
List<StandaloneTable> tables = new();

foreach (MapMember member in mapMembers)
{
if (member is Layer layer)
{
layers.Add(layer);
}
else if (member is StandaloneTable table)
{
using RowCursor rowCursor = featureLayer.Search();
while (rowCursor.MoveNext())
{
using (var row = rowCursor.Current)
{
if (row is not Feature feature)
{
continue;
}
Geometry geometry = feature.GetShape();
MapView.Active.SelectFeatures(geometry, SelectionCombinationMethod.Add);
}
}
tables.Add(table);
}
}
MapView.Active.SelectLayers(layers);
// MapView.Active.SelectStandaloneTables(tables); // clears previous selection, not clear how to ADD selection instead
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,27 @@ List<string> objectIds
return (objPath, converted);
}

public void AddDatasetsToMap((string, string) databaseObj, string databasePath)
public string AddDatasetsToMap((string, string) databaseObj, string databasePath)
{
try
{
LayerFactory.Instance.CreateLayer(
new Uri($"{databasePath}\\{databaseObj.Item2}"),
_contextStack.Current.Document,
layerName: databaseObj.Item1
);
return LayerFactory.Instance
.CreateLayer(
new Uri($"{databasePath}\\{databaseObj.Item2}"),
_contextStack.Current.Document,
layerName: databaseObj.Item1
)
.URI;
}
catch (ArgumentException)
{
StandaloneTableFactory.Instance.CreateStandaloneTable(
new Uri($"{databasePath}\\{databaseObj.Item2}"),
_contextStack.Current.Document,
tableName: databaseObj.Item1
);
return StandaloneTableFactory.Instance
.CreateStandaloneTable(
new Uri($"{databasePath}\\{databaseObj.Item2}"),
_contextStack.Current.Document,
tableName: databaseObj.Item1
)
.URI;
}
}

Expand Down Expand Up @@ -177,6 +181,7 @@ CancellationToken cancellationToken
}

int bakeCount = 0;
List<string> bakedLayersURIs = new();
onOperationProgressed?.Invoke("Adding to Map", bakeCount);
// 3. add layer and tables to the Table Of Content
foreach ((string, string) databaseObj in convertedGISObjects)
Expand All @@ -186,12 +191,19 @@ CancellationToken cancellationToken
// POC: QueuedTask
var task = QueuedTask.Run(() =>
{
AddDatasetsToMap(databaseObj, databasePath);
try
{
bakedLayersURIs.Add(AddDatasetsToMap(databaseObj, databasePath));
}
catch (Exception e) when (!e.IsFatal())
{
// log error ("Layer X couldn't be added to Map"), but not cancel all operations
}
onOperationProgressed?.Invoke("Adding to Map", (double)++bakeCount / convertedGISObjects.Count);
});
task.Wait(cancellationToken);
}

return objectIds;
return bakedLayersURIs;
}
}

0 comments on commit 0920d7c

Please sign in to comment.