<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Get the right map extent in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-the-right-map-extent/m-p/1210044#M8702</link>
    <description>&lt;P&gt;I believe query layers have a data connection that contains an extent property that u can set via the CIM. In the case of a query layer, it may be null by default as the software probably wants to avoid doing a full table scan to calculate it ....thus, I assume the layer extent gets defaulted to something v large - probably the map's default extent or similar....&lt;/P&gt;&lt;P&gt;As a workaround, perhaps u could create the layer with visibility off then set the extent u desire, turning visibility on at the same time. "Zoom to Layer", I believe, will also honor any extent u set.&lt;/P&gt;&lt;P&gt;Here's a snippet that does something along those lines that u can play with:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;//elsewhere - compute extent envelope as needed...
 var extent = EnvelopeBuilderEx.CreateEnvelope(x_min, y_min, x_max, y_max);

 var feat_layer = LayerFactory.Instance.CreateLayer(....) as FeatureLayer;
 QueuedTask.Run(() =&amp;gt; {
   //Get the CIM Definition
   var def = feat_layer.GetDefinition() as CIMFeatureLayer;
   def.Visibility = true; //make the layer visible
   var sql_conn = def.FeatureTable.DataConnection as CIMSqlQueryDataConnection;
   if (sql_conn != null) {
     //Set the extent - honored by "Zoom to Layer", etc.
     sql_conn.Extent = extent;
   }
   feat_layer.SetDefinition(def);//commit the changes
 });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Zoom to Layer should use the extent, also:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="zoom_to_layer.jpg" style="width: 447px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50539iD5C8ACD85B3A3BCC/image-size/large?v=v2&amp;amp;px=999" role="button" title="zoom_to_layer.jpg" alt="zoom_to_layer.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Additionally, "&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/recalculate-feature-class-extent.htm" target="_self"&gt;&lt;SPAN&gt;Recalculate Feature Class Extent&lt;/SPAN&gt;&lt;/A&gt;" gp tool &lt;SPAN&gt;provides an option to&amp;nbsp; store the calc'd extent as part of an unregistered table (aka query layer) at the db level.&amp;nbsp;&amp;nbsp;The next time you add a query layer, it should read the extent off the table's metadata without recalc or need to set the extent programmatically.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gp_recalc_extent.jpg" style="width: 284px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50540i57ED3DCD7E9CAF38/image-size/large?v=v2&amp;amp;px=999" role="button" title="gp_recalc_extent.jpg" alt="gp_recalc_extent.jpg" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Sep 2022 18:57:34 GMT</pubDate>
    <dc:creator>CharlesMacleod</dc:creator>
    <dc:date>2022-09-06T18:57:34Z</dc:date>
    <item>
      <title>Get the right map extent</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-the-right-map-extent/m-p/1209805#M8697</link>
      <description>&lt;P&gt;Hey, I am building an Addin to AGP that gets data from an Oracle database and displaying on a map. The user can from a combobox select the layer thay want to see.&lt;/P&gt;&lt;P&gt;When I am creating a new projekt i pro and select a layer from the combobox, the map are zooming out to this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Daniel4_0-1662463345180.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50485iEC1FBD6313FC8E26/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Daniel4_0-1662463345180.png" alt="Daniel4_0-1662463345180.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;QueryDescription queryDescription = oracleDatabase.GetQueryDescription(SQLquery, this.tableName);
queryDescription.SetObjectIDFields("OBJECTID");
queryDescription.SetShapeType(geomType);
SpatialReference spatialReference = MapView.Active.Map.SpatialReference;

Table table = oracleDatabase.OpenTable(queryDescription);
                   

                    
FeatureClass featureClass = oracleDatabase.OpenTable(queryDescription) as FeatureClass;
if (featureClass.GetCount() != 0)
{
FeatureLayer featureLayer = LayerFactory.Instance.CreateFeatureLayer(featureClass, map, layerName: tableName);
} else
{
// Display a message
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I make it zoom correctly?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 11:29:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-the-right-map-extent/m-p/1209805#M8697</guid>
      <dc:creator>Daniel4</dc:creator>
      <dc:date>2022-09-06T11:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: Get the right map extent</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-the-right-map-extent/m-p/1210044#M8702</link>
      <description>&lt;P&gt;I believe query layers have a data connection that contains an extent property that u can set via the CIM. In the case of a query layer, it may be null by default as the software probably wants to avoid doing a full table scan to calculate it ....thus, I assume the layer extent gets defaulted to something v large - probably the map's default extent or similar....&lt;/P&gt;&lt;P&gt;As a workaround, perhaps u could create the layer with visibility off then set the extent u desire, turning visibility on at the same time. "Zoom to Layer", I believe, will also honor any extent u set.&lt;/P&gt;&lt;P&gt;Here's a snippet that does something along those lines that u can play with:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;//elsewhere - compute extent envelope as needed...
 var extent = EnvelopeBuilderEx.CreateEnvelope(x_min, y_min, x_max, y_max);

 var feat_layer = LayerFactory.Instance.CreateLayer(....) as FeatureLayer;
 QueuedTask.Run(() =&amp;gt; {
   //Get the CIM Definition
   var def = feat_layer.GetDefinition() as CIMFeatureLayer;
   def.Visibility = true; //make the layer visible
   var sql_conn = def.FeatureTable.DataConnection as CIMSqlQueryDataConnection;
   if (sql_conn != null) {
     //Set the extent - honored by "Zoom to Layer", etc.
     sql_conn.Extent = extent;
   }
   feat_layer.SetDefinition(def);//commit the changes
 });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Zoom to Layer should use the extent, also:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="zoom_to_layer.jpg" style="width: 447px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50539iD5C8ACD85B3A3BCC/image-size/large?v=v2&amp;amp;px=999" role="button" title="zoom_to_layer.jpg" alt="zoom_to_layer.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Additionally, "&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/recalculate-feature-class-extent.htm" target="_self"&gt;&lt;SPAN&gt;Recalculate Feature Class Extent&lt;/SPAN&gt;&lt;/A&gt;" gp tool &lt;SPAN&gt;provides an option to&amp;nbsp; store the calc'd extent as part of an unregistered table (aka query layer) at the db level.&amp;nbsp;&amp;nbsp;The next time you add a query layer, it should read the extent off the table's metadata without recalc or need to set the extent programmatically.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gp_recalc_extent.jpg" style="width: 284px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50540i57ED3DCD7E9CAF38/image-size/large?v=v2&amp;amp;px=999" role="button" title="gp_recalc_extent.jpg" alt="gp_recalc_extent.jpg" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 18:57:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/get-the-right-map-extent/m-p/1210044#M8702</guid>
      <dc:creator>CharlesMacleod</dc:creator>
      <dc:date>2022-09-06T18:57:34Z</dc:date>
    </item>
  </channel>
</rss>

