ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MapView Class / GetViewSize Method
Example

In This Topic
    GetViewSize Method (MapView)
    In This Topic
    Returns the current size of the view.
    Syntax
    public Size GetViewSize()
    Public Function GetViewSize() As Size

    Return Value

    The current size of the view.
    Example
    Use MapView Selection SelectFeaturesEx or GetFeaturesEx
    //var featSceneLayer = ...;
    var sname = featSceneLayer.Name;
    
    await QueuedTask.Run(() =>
    {
      //Select all features within the current map view
      var sz = MapView.Active.GetViewSize();
    
      var c_ll = new Coordinate2D(0, 0);
      var c_ur = new Coordinate2D(sz.Width, sz.Height);
      //Use screen coordinates for 3D selection on MapView
      var env = EnvelopeBuilderEx.CreateEnvelope(c_ll, c_ur);
    
      //HasAssociatedFeatureService does not matter for SelectFeaturesEx
      //or GetFeaturesEx
      var result = MapView.Active.SelectFeaturesEx(env);
      //var result = MapView.Active.GetFeaturesEx(env);
    
      //The list of object ids from SelectFeaturesEx
      //At 2.x - var oids1 = result.Where(kvp => kvp.Key.Name == sname).First().Value;
      var oids1 = result.ToDictionary().Where(kvp => kvp.Key.Name == sname).First().Value;
      //TODO - use the object ids
    
      MapView.Active.Map.ClearSelection();
    });
    
    Use Select or Search with a Spatial Query
    //var featSceneLayer = ...;
    //var sname = featSceneLayer.Name;
    await QueuedTask.Run(() =>
    {
      if (!featSceneLayer.HasAssociatedFeatureService)
        return;//no search or select
    
      //Select all features within the current map view
      var sz = MapView.Active.GetViewSize();
      var map_pt1 = MapView.Active.ClientToMap(new System.Windows.Point(0, sz.Height));
      var map_pt2 = MapView.Active.ClientToMap(new System.Windows.Point(sz.Width, 0));
    
      //Convert to an envelope
      var temp_env = EnvelopeBuilderEx.CreateEnvelope(map_pt1, map_pt2, MapView.Active.Map.SpatialReference);
    
      //Project if needed to the layer spatial ref
      SpatialReference sr = null;
      using (var fc = featSceneLayer.GetFeatureClass())
      using (var fdef = fc.GetDefinition())
        sr = fdef.GetSpatialReference();
    
      var env = GeometryEngine.Instance.Project(temp_env, sr) as Envelope;
    
      //Set up a query filter
      var sf = new SpatialQueryFilter()
      {
        FilterGeometry = env,
        SpatialRelationship = SpatialRelationship.Intersects,
        SubFields = "*"
      };
    
      //Select against the feature service
      var select = featSceneLayer.Select(sf);
      if (select.GetCount() > 0)
      {
        //enumerate over the selected features
        using (var rc = select.Search())
        {
          while (rc.MoveNext())
          {
            using (var feature = rc.Current as Feature)
            {
              var oid = feature.GetObjectID();
              //etc.
            }
          }
        }
      }
    
      MapView.Active.Map.ClearSelection();
    
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also