Zoom to Selected Globe Features

public void ZoomToSelectedGlobeFeatures(ESRI.ArcGIS.GlobeCore.IGlobe globe)
{
        ESRI.ArcGIS.GlobeCore.IGlobeDisplay globeDisplay = globe.GlobeDisplay;
        ESRI.ArcGIS.Analyst3D.ISceneViewer sceneViewer = globeDisplay.ActiveViewer;
        ESRI.ArcGIS.Analyst3D.ICamera camera = sceneViewer.Camera;
        ESRI.ArcGIS.GlobeCore.IGlobeCamera globeCamera = (ESRI.ArcGIS.GlobeCore.IGlobeCamera)camera; // Explicit Cast
        ESRI.ArcGIS.Analyst3D.IScene scene = globeDisplay.Scene;
        ESRI.ArcGIS.Carto.IEnumLayer enumLayer = scene.get_Layers(null, true);

        ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
        envelope.SetEmpty();
        ESRI.ArcGIS.Geometry.IEnvelope layersExtentEnvelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
        layersExtentEnvelope.SetEmpty();
        ESRI.ArcGIS.Geometry.IZAware ZAware = (ESRI.ArcGIS.Geometry.IZAware)envelope; // Explicit Cast
        ZAware.ZAware = (true);

        ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
        ESRI.ArcGIS.Geometry.ISpatialReference spatialReference = scene.SpatialReference;
        System.Boolean haveFeatures = false;
        enumLayer.Reset();

        ESRI.ArcGIS.Carto.ILayer layer;
        while ((layer = enumLayer.Next()) != null)
        {
                if (layer == null)
                        break;


                if (layer is ESRI.ArcGIS.Carto.IFeatureLayer)
                {
                        ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = (ESRI.ArcGIS.Carto.IFeatureLayer)layer; // Explicit Cast
                        ESRI.ArcGIS.Carto.IFeatureSelection featureSelection = (ESRI.ArcGIS.Carto.IFeatureSelection)layer; // Explicit Cast
                        ESRI.ArcGIS.Geodatabase.ISelectionSet selectionSet = featureSelection.SelectionSet;
                        ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureLayer.FeatureClass;
                        System.String shapeField = featureClass.ShapeFieldName;
                        spatialFilter.GeometryField = shapeField;
                        spatialFilter.set_OutputSpatialReference(shapeField, spatialReference);

                        // The next 2 lines of code are different from many other ArcObjects programming techniques in that the
                        // ICursor Interface variable 'cursor' is initialized to a Null value. It is set by reference with the
                        // call to the Search method; hence the need for the 'out' argument (see MSDN for more information).
                        ESRI.ArcGIS.Geodatabase.ICursor cursor;
                        selectionSet.Search(spatialFilter, true, out cursor);

                        ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = (ESRI.ArcGIS.Geodatabase.IFeatureCursor)cursor; // Explicit Cast

                        System.Boolean getLayerExtent = true;
                        ESRI.ArcGIS.Geodatabase.IFeature feature;  // Automatically initialized to null. Used to test existence of a feature in the featureCursor
                        while ((feature = featureCursor.NextFeature()) != null)
                        {
                                ESRI.ArcGIS.Geometry.IGeometry geometry = feature.Shape;
                                ESRI.ArcGIS.Geometry.IEnvelope featureExtent = geometry.Envelope;
                                envelope.Union(featureExtent);
                                haveFeatures = true;

                                if (getLayerExtent)
                                {
                                        ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset = (ESRI.ArcGIS.Geodatabase.IGeoDataset)featureLayer; // Explicit Cast
                                        if (geoDataset != null)
                                        {
                                                ESRI.ArcGIS.Geometry.IEnvelope layerExtent = geoDataset.Extent;
                                                layersExtentEnvelope.Union(layerExtent);
                                        }
                                        getLayerExtent = false;
                                }
                        }
                }
        }

        // Since the size of points is very small, we use a special case to zoom in closer

        System.Double width = envelope.Width;
        System.Double height = envelope.Height;
        if (width == 0.0 && height == 0.0)  // Must be a single point, Zoom to 1 x 1 degree area,
        {                                   // or lets say 1/20th of layer extent, whichever is smallest.
                System.Double dim = 1.0;

                System.Boolean bEmpty = layersExtentEnvelope.IsEmpty;
                if (!bEmpty)
                {
                        System.Double layerWidth = layersExtentEnvelope.Width;
                        System.Double layerHeight = layersExtentEnvelope.Height;
                        System.Double layerDim = System.Math.Max(layerWidth, layerHeight) * 0.05;
                        if (layerDim > 0.0)
                                dim = System.Math.Min(1.0, layerDim);
                }

                System.Double xMin = envelope.XMin;
                System.Double yMin = envelope.YMin;

                ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass();
                point.X = xMin;
                point.Y = yMin;

                envelope.Width = dim;
                envelope.Height = dim;
                envelope.CenterAt(point);
        }
        else if (width == 0.0 || height == 0.0)
        {
                System.Double maxDim = System.Math.Max(width, height);
                envelope.Width = maxDim;
                envelope.Height = maxDim;
        }

        globeCamera.SetToZoomToExtents(envelope, globe, sceneViewer);
        sceneViewer.Redraw(true);
} 


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下 4载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下载 4使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下载 4使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值