Select to view content in your preferred language

FullExtent is Nothing

2109
5
Jump to solution
01-10-2012 07:31 AM
JeffRogholt
Emerging Contributor
In the ExecuteCompleted event of a QueryTask, we add the features to a graphics layer.

The features are points.  They include geometry.

After adding/inserting the graphic into the layer, the graphicsLayer.FullExtent should have a value but is Nothing.  Prior to upgrading to the 2.3 API this was working, now it is not.  Do we need to change how we do this or is this a bug?

Here's the code from the ExecuteCompleted event:
Dim featureSet As FeatureSet = args.FeatureSet Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)  For Each feature As Graphic In featureSet.Features     graphicsLayer.Graphics.Insert(0, feature) Next  Dim env As New ESRI.ArcGIS.Client.Geometry.Envelope env.XMax = graphicsLayer.FullExtent.XMax env.XMin = graphicsLayer.FullExtent.XMin env.YMax = graphicsLayer.FullExtent.YMax env.YMin = graphicsLayer.FullExtent.YMin  MyMap.ZoomTo(env)



We get an exception on env.XMax = graphicsLayer.FullExtent.XMax because graphicsLayer.FullExtent is Nothing.

Any advice is appreciated.  Thanks.
0 Kudos
1 Solution

Accepted Solutions
dotMorten_esri
Esri Notable Contributor
You could calculate the extent yourself based on the query results (sorry for the C# code - my VB is rusty :-))
Envelope env = null;
foreach(var feature in featureSet.Features)
{
    if(env == null) env = feature.Geometry.Extent;
    else env= env.Union(feature.Geometry.Extent)
}
if(env != null)
    Map.ZoomTo(env);

View solution in original post

0 Kudos
5 Replies
dotMorten_esri
Esri Notable Contributor
Due to a change in how the layer is getting rendered, the FullExtent property will not be set until the layer has rendered.
0 Kudos
JenniferNery
Esri Regular Contributor
I could not reproduce with the following SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SpatialQuery.

On ExecuteCompleted event handler, I added the following code:
MyMap.ZoomTo(graphicsLayer.FullExtent);
0 Kudos
JeffRogholt
Emerging Contributor
Is there documentation on the other 2.3 changes related to rendering?  I looked at the "what's new in 2.3" page but didn't see it, but maybe I just didn't know what I was looking for.

We still want to zoom to the points returned from the query.  Do you have a suggestion how we can do that without the use of the FullExtent property?  I looked for a RenderComplete event or something similar but couldn't find one.  Any ideas?
0 Kudos
dotMorten_esri
Esri Notable Contributor
You could calculate the extent yourself based on the query results (sorry for the C# code - my VB is rusty :-))
Envelope env = null;
foreach(var feature in featureSet.Features)
{
    if(env == null) env = feature.Geometry.Extent;
    else env= env.Union(feature.Geometry.Extent)
}
if(env != null)
    Map.ZoomTo(env);
0 Kudos
JenniferNery
Esri Regular Contributor
Jeff, can you share your code? I would like to reproduce the bug so we could fix it in future versions.

I'm not able to repro with the following code.
    <Grid x:Name="LayoutRoot" Background="White">
  <esri:Map x:Name="myMap" WrapAround="True">
   <esri:ArcGISTiledMapServiceLayer 
                    ID="baseMap"                                       
                    Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />      
  </esri:Map>  
 </Grid>


  public MainPage()
  {
   InitializeComponent();

   QueryTask queryTask = new QueryTask("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer/0");
   Query query = new Query() { Where = "1=1", ReturnGeometry = true, OutSpatialReference = myMap.SpatialReference };
   queryTask.ExecuteCompleted += (s, e) =>
    {
     var l = new GraphicsLayer();
     foreach (var r in e.FeatureSet.Features)
      l.Graphics.Add(r);     
     System.Diagnostics.Debug.WriteLine(l.FullExtent);
    };
   queryTask.ExecuteAsync(query);
  }
0 Kudos