Exclude map layers from SetClipGeometry

431
2
Jump to solution
01-25-2022 02:47 PM
LesleyBross1
New Contributor III

There is an example of clipping map layers to a polygon in the ProSnippets for Map Authoring using the SetClipGeometry method. Is there also an API to exclude map layers from the clipping? The ArcGIS Pro map Clip Layers tab provides this capability. 

0 Kudos
1 Solution

Accepted Solutions
NarelleChedzey
Esri Contributor

Hi Lesley, 

 

Unfortunately there is no SetClipGeometry method that allows you to exclude map layers from a clip geometry.  However there is a property on the CIMMap object that allows you to specify the layers.  The property is called LayersExcludedFromClipping.

 

 

 

 

Here's a small sample of how you would use it.   

 

      // find the first layer in the map
      var layer = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault();
      if (layer == null)
        return;

      // create a list of strings
      List<string> layerUris = new List<string>();
      // add the layer URI to the list
      layerUris.Add(layer.URI);

      QueuedTask.Run(() =>
      {
        // create a polygon from the current extent
        var poly = PolygonBuilder.CreatePolygon(MapView.Active.Extent);

        // set the clip geometry
        MapView.Active.Map.SetClipGeometry(poly, null);

        // get the map definition
        var mapDef = MapView.Active.Map.GetDefinition();
        // assign the layers to be excluded 
        mapDef.LayersExcludedFromClipping = layerUris.ToArray();
        // set the map definition
        MapView.Active.Map.SetDefinition(mapDef);
      });

 

Let me know if you have any questions.

We'll update the SetClipGeometry method to include the option to exclude layers in a future release. 

 

Thanks

Narelle

 

 

View solution in original post

2 Replies
NarelleChedzey
Esri Contributor

Hi Lesley, 

 

Unfortunately there is no SetClipGeometry method that allows you to exclude map layers from a clip geometry.  However there is a property on the CIMMap object that allows you to specify the layers.  The property is called LayersExcludedFromClipping.

 

 

 

 

Here's a small sample of how you would use it.   

 

      // find the first layer in the map
      var layer = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault();
      if (layer == null)
        return;

      // create a list of strings
      List<string> layerUris = new List<string>();
      // add the layer URI to the list
      layerUris.Add(layer.URI);

      QueuedTask.Run(() =>
      {
        // create a polygon from the current extent
        var poly = PolygonBuilder.CreatePolygon(MapView.Active.Extent);

        // set the clip geometry
        MapView.Active.Map.SetClipGeometry(poly, null);

        // get the map definition
        var mapDef = MapView.Active.Map.GetDefinition();
        // assign the layers to be excluded 
        mapDef.LayersExcludedFromClipping = layerUris.ToArray();
        // set the map definition
        MapView.Active.Map.SetDefinition(mapDef);
      });

 

Let me know if you have any questions.

We'll update the SetClipGeometry method to include the option to exclude layers in a future release. 

 

Thanks

Narelle

 

 

LesleyBross1
New Contributor III

Thank you! This worked well. I retrieved a polygon from a feature class to set my clip geometry. Wish I were more competent in LINQ queries when querying the layers to exclude from the clipping, but I got it working!

0 Kudos