From f1febb5e37f8f33766aec4e4cc118f90b2871fa0 Mon Sep 17 00:00:00 2001 From: KatKatKateryna <89912278+KatKatKateryna@users.noreply.github.com> Date: Wed, 24 Jul 2024 11:54:28 +0200 Subject: [PATCH] set Relative to the ground Elevation prop (#57) Co-authored-by: Adam Hathcock --- .../Operations/Receive/HostObjectBuilder.cs | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Operations/Receive/HostObjectBuilder.cs b/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Operations/Receive/HostObjectBuilder.cs index 769096e38..a26fa9747 100644 --- a/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Operations/Receive/HostObjectBuilder.cs +++ b/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Operations/Receive/HostObjectBuilder.cs @@ -1,5 +1,7 @@ using System.Diagnostics.Contracts; +using ArcGIS.Core.CIM; using ArcGIS.Core.Geometry; +using ArcGIS.Desktop.Framework.Threading.Tasks; using ArcGIS.Desktop.Mapping; using Objects.GIS; using Speckle.Connectors.ArcGIS.Utils; @@ -223,7 +225,7 @@ public class ArcGISHostObjectBuilder : IHostObjectBuilder string shortName = nestedLayerName.Split("\\")[^1]; string nestedLayerPath = string.Join("\\", nestedLayerName.Split("\\").SkipLast(1)); - GroupLayer groupLayer = CreateNestedGroupLayer(nestedLayerPath, createdLayerGroups); + GroupLayer groupLayer = QueuedTask.Run(() => CreateNestedGroupLayer(nestedLayerPath, createdLayerGroups)).Result; // Most of the Speckle-written datasets will be containing geometry and added as Layers // although, some datasets might be just tables (e.g. native GIS Tables, in the future maybe Revit schedules etc. @@ -231,13 +233,46 @@ public class ArcGISHostObjectBuilder : IHostObjectBuilder // expensive, than assuming by default that it's a layer with geometry (which in most cases it's expected to be) try { - var layer = LayerFactory.Instance.CreateLayer(uri, groupLayer, layerName: shortName); - layer.SetExpanded(true); + MapMember layer = QueuedTask + .Run(() => + { + var layer = LayerFactory.Instance.CreateLayer(uri, groupLayer, layerName: shortName); + if (layer == null) + { + throw new SpeckleException($"Layer '{shortName}' was not created"); + } + + // if Scene + // https://community.esri.com/t5/arcgis-pro-sdk-questions/sdk-equivalent-to-changing-layer-s-elevation/td-p/1346139 + if (_contextStack.Current.Document.Map.IsScene) + { + var groundSurfaceLayer = _contextStack.Current.Document.Map.GetGroundElevationSurfaceLayer(); + var layerElevationSurface = new CIMLayerElevationSurface + { + ElevationSurfaceLayerURI = groundSurfaceLayer.URI, + }; + + // for Feature Layers + if (layer.GetDefinition() is CIMFeatureLayer cimLyr) + { + cimLyr.LayerElevation = layerElevationSurface; + layer.SetDefinition(cimLyr); + } + } + + layer.SetExpanded(true); + return layer; + }) + .Result; + return layer; } catch (ArgumentException) { - var table = StandaloneTableFactory.Instance.CreateStandaloneTable(uri, groupLayer, tableName: shortName); + StandaloneTable table = QueuedTask + .Run(() => StandaloneTableFactory.Instance.CreateStandaloneTable(uri, groupLayer, tableName: shortName)) + .Result; + return table; } }