Select to view content in your preferred language

FeatureLayer OnDemand

2956
1
Jump to solution
03-30-2011 08:59 AM
BobbyRadakovich
Deactivated User
I have published a service that serves a large number of polygon features.  In my SL app, I add FeatureLayers to my map in code - four FeatureLayers all pointing to the same service URL but each of which has a separate Where clause.  I use the four FeatureLayers with different renderers to display subsets of the polygons in different colors (the criteria for determining the colors is only known at runtime so I have to do it this way).

The problem arises when one of the FeatureLayers contains a large number of polygons.  I am adding each layer as "OnDemand" with an OnDemandCacheSize of 50 - this should result in the FeatureLayer retrieving ONLY polygons within the current map extent PLUS 50 addition polygons outside the current extent.  Here's my code for adding the layers:

ESRI.ArcGIS.Client.FeatureLayer fLayer = new FeatureLayer();
fLayer.ID = "SitesThisPermitActive";
fLayer.Url = serviceUrl;
fLayer.Where = "pk_permit_id = " + currPermitId + " AND is_active = 1";
fLayer.Renderer = ThisPermitActiveRenderer;
fLayer.Mode = FeatureLayer.QueryMode.OnDemand;
fLayer.OnDemandCacheSize = 50;
fLayer.Visible = true;

OutFields outf = new OutFields();
outf.Add("permit_number");
outf.Add("site_number");
outf.Add("size");
outf.Add("size_units");
outf.Add("crop_list");
fLayer.OutFields = outf;

MyMap.Layers.Add(fLayer);


When the Where clause returns a large number (~3000) of polygons, I understand that the service will only return the first 1000 polygons found.  However it is my understanding that with an OnDemand service this 1000 limit will be applied AFTER the polygons are intersected with the map extent.

My code automatically turns off the layer when the zoom level gets out far enough that there might be > 1000 polygons within the map extent.  So at all closer zoom levels I should always be able to see all of the polygons.

When the layer first renders, only a few polygons show up in the map extent, although I know there should be around 200 within the extent.  If I pan the map very slightly (a few pixels), when the map redraws a larger number of polygons appear.  If I pan again, I get yet more polygons.  What this tells me is that the map extent is not being used to filter the polygons PRIOR to the 1000 limit being applied.

I have attached two screenshots - the first shows the map when I first turn on the layer with > 1000 polygons, the second after panning a few pixels.

What gives?
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Original User: jenniferdnery

I could not reproduce this. Please try the following code. I started this app with an extent that I know have very few features just to check that it only retrieves features at the given map extent. When I zoom out the map to an extent that will show all features, graphics count is over than its 1000 limit. If you change mode to SnapShot, you will find that the service limit is used.

In your app, can you try to get the count of graphics to see if the problem is with rendering or with retrieving from query? You can tweak this sample to help me reproduce the issue. Thanks.

XAML-code
    <Grid x:Name="LayoutRoot" Background="White">
  <esri:Map x:Name="MyMap" ExtentChanged="MyMap_ExtentChanged">
   <esri:Map.Extent>
    <esri:Envelope XMin="-98.9035767376658" YMin="28.5612723745683" XMax="-97.0240238509518" YMax="29.801860262267">
     <esri:Envelope.SpatialReference>
      <esri:SpatialReference WKID="4269"/>
     </esri:Envelope.SpatialReference>
    </esri:Envelope>
   </esri:Map.Extent>   
  </esri:Map>
  <Button Content="AddLayer" Click="Button_Click" VerticalAlignment="Top" HorizontalAlignment="Center"/>
 </Grid>


Code-behind
private void MyMap_ExtentChanged(object sender, ExtentEventArgs e)
{
 System.Diagnostics.Debug.WriteLine("Extent Changed: {0}", e.NewExtent);
}

private void FeatureLayer_UpdateCompleted(object sender, EventArgs e)
{
 FeatureLayer layer = sender as FeatureLayer;
 System.Diagnostics.Debug.WriteLine("Update Completed: {0}", layer.Graphics.Count);
}

private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
 MyMap.Layers.Clear();
 FeatureLayer layer = new FeatureLayer()
 {
  ID = "MyLayer",
  OnDemandCacheSize = 50,
  Mode = FeatureLayer.QueryMode.OnDemand,
  Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hurricanes/NOAA_Tracks_1851_2007/MapServer/0",
  Where = "1=1"
 };
 layer.UpdateCompleted += FeatureLayer_UpdateCompleted;
 MyMap.Layers.Add(layer);
}

View solution in original post

0 Kudos
1 Reply
by Anonymous User
Not applicable
Original User: jenniferdnery

I could not reproduce this. Please try the following code. I started this app with an extent that I know have very few features just to check that it only retrieves features at the given map extent. When I zoom out the map to an extent that will show all features, graphics count is over than its 1000 limit. If you change mode to SnapShot, you will find that the service limit is used.

In your app, can you try to get the count of graphics to see if the problem is with rendering or with retrieving from query? You can tweak this sample to help me reproduce the issue. Thanks.

XAML-code
    <Grid x:Name="LayoutRoot" Background="White">
  <esri:Map x:Name="MyMap" ExtentChanged="MyMap_ExtentChanged">
   <esri:Map.Extent>
    <esri:Envelope XMin="-98.9035767376658" YMin="28.5612723745683" XMax="-97.0240238509518" YMax="29.801860262267">
     <esri:Envelope.SpatialReference>
      <esri:SpatialReference WKID="4269"/>
     </esri:Envelope.SpatialReference>
    </esri:Envelope>
   </esri:Map.Extent>   
  </esri:Map>
  <Button Content="AddLayer" Click="Button_Click" VerticalAlignment="Top" HorizontalAlignment="Center"/>
 </Grid>


Code-behind
private void MyMap_ExtentChanged(object sender, ExtentEventArgs e)
{
 System.Diagnostics.Debug.WriteLine("Extent Changed: {0}", e.NewExtent);
}

private void FeatureLayer_UpdateCompleted(object sender, EventArgs e)
{
 FeatureLayer layer = sender as FeatureLayer;
 System.Diagnostics.Debug.WriteLine("Update Completed: {0}", layer.Graphics.Count);
}

private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
 MyMap.Layers.Clear();
 FeatureLayer layer = new FeatureLayer()
 {
  ID = "MyLayer",
  OnDemandCacheSize = 50,
  Mode = FeatureLayer.QueryMode.OnDemand,
  Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hurricanes/NOAA_Tracks_1851_2007/MapServer/0",
  Where = "1=1"
 };
 layer.UpdateCompleted += FeatureLayer_UpdateCompleted;
 MyMap.Layers.Add(layer);
}
0 Kudos