Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArcGIS GroupLayers #293

Merged
merged 5 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
using ArcGIS.Desktop.Mapping;
using ArcGIS.Desktop.Mapping.Events;
using Speckle.Connectors.ArcGIS.Utils;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;

namespace Speckle.Connectors.ArcGIS.Bindings;

public class ArcGISSelectionBinding : ISelectionBinding
{
private readonly MapMembersUtils _mapMemberUtils;
public string Name => "selectionBinding";
public IBrowserBridge Parent { get; }

public ArcGISSelectionBinding(IBrowserBridge parent)
public ArcGISSelectionBinding(IBrowserBridge parent, MapMembersUtils mapMemberUtils)
{
_mapMemberUtils = mapMemberUtils;
Parent = parent;
var topLevelHandler = parent.TopLevelExceptionHandler;

Expand Down Expand Up @@ -52,14 +55,8 @@ public SelectionInfo GetSelection()
List<MapMember> allNestedMembers = new();
foreach (MapMember member in selectedMembers)
{
if (member is GroupLayer group)
{
GetLayersFromGroup(group, allNestedMembers);
}
else
{
allNestedMembers.Add(member);
}
var layerMapMembers = _mapMemberUtils.UnpackMapLayers(selectedMembers);
allNestedMembers.AddRange(layerMapMembers);
}

List<string> objectTypes = allNestedMembers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Speckle.Connectors.ArcGIS.Filters;
using Speckle.Connectors.ArcGIS.Utils;
using Speckle.Connectors.Common.Caching;
using Speckle.Connectors.Common.Cancellation;
using Speckle.Connectors.Common.Operations;
Expand Down Expand Up @@ -54,6 +55,7 @@ public sealed class ArcGISSendBinding : ISendBinding

private List<FeatureLayer> SubscribedLayers { get; set; } = new();
private List<StandaloneTable> SubscribedTables { get; set; } = new();
private readonly MapMembersUtils _mapMemberUtils;

public ArcGISSendBinding(
DocumentModelStore store,
Expand All @@ -64,7 +66,8 @@ public ArcGISSendBinding(
ISendConversionCache sendConversionCache,
IOperationProgressManager operationProgressManager,
ILogger<ArcGISSendBinding> logger,
IArcGISConversionSettingsFactory arcGisConversionSettingsFactory
IArcGISConversionSettingsFactory arcGisConversionSettingsFactory,
MapMembersUtils mapMemberUtils
)
{
_store = store;
Expand All @@ -76,6 +79,7 @@ IArcGISConversionSettingsFactory arcGisConversionSettingsFactory
_logger = logger;
_topLevelExceptionHandler = parent.TopLevelExceptionHandler;
_arcGISConversionSettingsFactory = arcGisConversionSettingsFactory;
_mapMemberUtils = mapMemberUtils;

Parent = parent;
Commands = new SendBindingUICommands(parent);
Expand Down Expand Up @@ -275,36 +279,14 @@ private async Task GetIdsForStandaloneTablesRemovedEvent(StandaloneTableEventArg
await RunExpirationChecks(true).ConfigureAwait(false);
}

private void AddChangedNestedObjectIds(GroupLayer group)
{
ChangedObjectIds[group.URI] = 1;
foreach (var member in group.Layers)
{
if (member is GroupLayer subGroup)
{
AddChangedNestedObjectIds(subGroup);
}
else
{
ChangedObjectIds[member.URI] = 1;
}
}
}

private async Task GetIdsForMapPropertyChangedEvent(MapPropertyChangedEventArgs args)
{
foreach (Map map in args.Maps)
{
foreach (MapMember member in map.Layers)
List<MapMember> allMapMembers = _mapMemberUtils.GetAllMapMembers(map);
foreach (MapMember member in allMapMembers)
{
if (member is GroupLayer group)
{
AddChangedNestedObjectIds(group);
}
else
{
ChangedObjectIds[member.URI] = 1;
}
ChangedObjectIds[member.URI] = 1;
}
}
await RunExpirationChecks(false).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ private void ProcessFeatureLayerColors(FeatureLayer layer, int displayPriority)
int count = 1;
using (RowCursor rowCursor = layer.Search())
{
// if layer doesn't have a valid data source (and the conversion likely failed), don't create a colorProxy
if (rowCursor is null)
{
return;
}
Comment on lines +320 to +323
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that we can skip an item in a layer if it's null?

Could this happen for a valid layer with valid fields?

Maybe I'm understanding this wrong 😅 but if this is the case we should at least log it somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a comment 🙌

while (rowCursor.MoveNext())
{
string elementAppId = $"{layer.URI}_{count}";
Expand Down Expand Up @@ -451,6 +456,11 @@ private bool TryGetUniqueRendererColor(
out int color
)
{
if (uniqueRenderer.DefaultSymbol is null)
{
color = RbgToInt(255, 255, 255, 255);
return false;
}
if (!TryGetSymbolColor(uniqueRenderer.DefaultSymbol.Symbol, out color)) // get default color
{
return false;
Expand Down Expand Up @@ -493,6 +503,11 @@ out int color
// set the group color to class symbol color if conditions are met
if (groupConditionsMet)
{
if (groupClass.Symbol is null)
{
color = RbgToInt(255, 255, 255, 255);
return false;
}
if (!TryGetSymbolColor(groupClass.Symbol.Symbol, out color))
{
return false;
Expand Down Expand Up @@ -544,6 +559,11 @@ private bool TryGetGraduatedRendererColor(
out int color
)
{
if (graduatedRenderer.DefaultSymbol is null)
{
color = RbgToInt(255, 255, 255, 255);
return false;
}
if (!TryGetSymbolColor(graduatedRenderer.DefaultSymbol.Symbol, out color)) // get default color
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task<RootObjectBuilderResult> Build(

List<SendConversionResult> results = new(objects.Count);
var cacheHitCount = 0;
List<(GroupLayer, Collection)> nestedGroups = new();
List<(ILayerContainer, Collection)> nestedGroups = new();

// reorder selected layers by Table of Content (TOC) order
List<(MapMember, int)> layersWithDisplayPriority = _mapMemberUtils.GetLayerDisplayPriority(
Expand Down Expand Up @@ -112,7 +112,7 @@ public async Task<RootObjectBuilderResult> Build(

// don't use cache for group layers
if (
mapMember is not GroupLayer
mapMember is not ILayerContainer
&& _sendConversionCache.TryGetValue(sendInfo.ProjectId, applicationId, out ObjectReference? value)
)
{
Expand All @@ -121,7 +121,7 @@ mapMember is not GroupLayer
}
else
{
if (mapMember is GroupLayer group)
if (mapMember is ILayerContainer group)
{
// group layer will always come before it's contained layers
// keep active group last in the list
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using ArcGIS.Desktop.Internal.Mapping;
using ArcGIS.Desktop.Mapping;

namespace Speckle.Connectors.ArcGIS.Utils;
Expand Down Expand Up @@ -28,21 +27,13 @@ public List<MapMember> UnpackMapLayers(IEnumerable<MapMember> mapMembersToUnpack
List<MapMember> mapMembers = new();
foreach (var layer in mapMembersToUnpack)
{
mapMembers.Add(layer);
switch (layer)
{
case GroupLayer subGroup:
mapMembers.Add(layer);
var subGroupMapMembers = UnpackMapLayers(subGroup.Layers);
mapMembers.AddRange(subGroupMapMembers);
break;
case ILayerContainerInternal subLayerContainerInternal:
mapMembers.Add(layer);
var subLayerMapMembers = UnpackMapLayers(subLayerContainerInternal.InternalLayers);
case ILayerContainer subGroup:
var subLayerMapMembers = UnpackMapLayers(subGroup.Layers);
mapMembers.AddRange(subLayerMapMembers);
break;
default:
mapMembers.Add(layer);
break;
}
}

Expand Down
Loading