Skip to content

Commit

Permalink
separate struct for MapMembers
Browse files Browse the repository at this point in the history
  • Loading branch information
KatKatKateryna committed Jun 28, 2024
1 parent 882057d commit 79e22de
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ private async void HighlightObjectsOnView(List<ObjectID> objectIds)
await QueuedTask
.Run(() =>
{
List<ObjectID> objectIdAndMapMembers = GetMapMembers(objectIds, mapView);
List<MapMemberFeature> mapMembersFeatures = GetMapMembers(objectIds, mapView);
ClearSelectionInTOC();
ClearSelection();
SelectMapMembersInTOC(objectIdAndMapMembers);
SelectMapMembersAndFeatures(objectIdAndMapMembers);
SelectMapMembersInTOC(mapMembersFeatures);
SelectMapMembersAndFeatures(mapMembersFeatures);
mapView.ZoomToSelected();
})
.ConfigureAwait(false);
}

private List<ObjectID> GetMapMembers(List<ObjectID> objectIds, MapView mapView)
private List<MapMemberFeature> GetMapMembers(List<ObjectID> objectIds, MapView mapView)
{
List<ObjectID> objectIdAndMapMembers = new();
List<MapMemberFeature> mapMembersFeatures = new();

foreach (ObjectID objectId in objectIds)
{
Expand All @@ -119,16 +119,13 @@ private List<ObjectID> GetMapMembers(List<ObjectID> objectIds, MapView mapView)
{
mapMember = mapView.Map.FindStandaloneTable(objectId.MappedLayerURI);
}
if (mapMember is null)
if (mapMember is not null)
{
continue;
MapMemberFeature mapMembersFeat = new(mapMember, objectId.FeatureId);
mapMembersFeatures.Add(mapMembersFeat);
}

ObjectID newObjectId = new(objectId.MappedLayerURI, objectId.FeatureId, mapMember);
objectIdAndMapMembers.Add(newObjectId);
}

return objectIdAndMapMembers;
return mapMembersFeatures;
}

private void ClearSelection()
Expand All @@ -148,19 +145,14 @@ private void ClearSelectionInTOC()
MapView.Active.ClearTOCSelection();
}

private void SelectMapMembersAndFeatures(List<ObjectID> objectIdAndMapMembers)
private void SelectMapMembersAndFeatures(List<MapMemberFeature> mapMembersFeatures)
{
foreach (ObjectID objectId in objectIdAndMapMembers)
foreach (MapMemberFeature mapMemberFeat in mapMembersFeatures)
{
if (objectId.MapMember == null)
{
continue;
}

MapMember member = objectId.MapMember;
MapMember member = mapMemberFeat.MapMember;
if (member is FeatureLayer layer)
{
if (objectId.FeatureId == null)
if (mapMemberFeat.FeatureId == null)
{
// select full layer if featureID not specified
layer.Select();
Expand All @@ -169,26 +161,21 @@ private void SelectMapMembersAndFeatures(List<ObjectID> objectIdAndMapMembers)
{
// query features by ID
var objectIDfield = layer.GetFeatureClass().GetDefinition().GetObjectIDField();
QueryFilter anotherQueryFilter = new() { WhereClause = $"{objectIDfield} = {objectId.FeatureId + 1}" };
QueryFilter anotherQueryFilter = new() { WhereClause = $"{objectIDfield} = {mapMemberFeat.FeatureId + 1}" };
using (Selection onlyOneSelection = layer.Select(anotherQueryFilter, SelectionCombinationMethod.New)) { }
}
}
}
}

private void SelectMapMembersInTOC(List<ObjectID> objectIdAndMapMembers)
private void SelectMapMembersInTOC(List<MapMemberFeature> mapMembersFeatures)
{
List<Layer> layers = new();
List<StandaloneTable> tables = new();

foreach (ObjectID objectId in objectIdAndMapMembers)
foreach (MapMemberFeature mapMemberFeat in mapMembersFeatures)
{
if (objectId.MapMember == null)
{
continue;
}

MapMember member = objectId.MapMember;
MapMember member = mapMemberFeat.MapMember;
if (member is Layer layer)
{
if (member is not GroupLayer) // group layer selection clears other layers selection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private void AddResultsFromTracker(ObjectConversionTracker trackerItem, List<Rec
}
else
{
ObjectID objectId = new(trackerItem.MappedLayerURI, trackerItem.DatasetRow, null);
ObjectID objectId = new(trackerItem.MappedLayerURI, trackerItem.DatasetRow);
if (trackerItem.HostAppGeom != null) // individual hostAppGeometry
{
results.Add(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using ArcGIS.Desktop.Mapping;

namespace Speckle.Connectors.ArcGIS.Utils;

public readonly struct MapMemberFeature
{
public int? FeatureId { get; }
public MapMember MapMember { get; }

public MapMemberFeature(MapMember mapMember, int? featureId)
{
MapMember = mapMember;
FeatureId = featureId;
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using ArcGIS.Desktop.Mapping;

namespace Speckle.Connectors.ArcGIS.Utils;

public struct ObjectID
{
private const string FEATURE_ID_SEPARATOR = "__speckleFeatureId__";
public string MappedLayerURI { get; }
public int? FeatureId { get; }
public MapMember? MapMember { get; set; }

public ObjectID(string encodedId)
{
Expand All @@ -20,11 +17,10 @@ public ObjectID(string encodedId)
}
}

public ObjectID(string layerId, int? featureId, MapMember? mapMember)
public ObjectID(string layerId, int? featureId)
{
MappedLayerURI = layerId;
FeatureId = featureId;
MapMember = mapMember;
}

public readonly string ObjectIdToString()
Expand Down

0 comments on commit 79e22de

Please sign in to comment.