Select to view content in your preferred language

OnDemand FeatureLayer

2049
3
08-17-2010 10:39 AM
MansourArshon
Emerging Contributor
Hi,

I want to have a list box on the right side of my Map to list the Name attribute of the features displayed on screen. So every time map extent changes, the list gets updated with the names of displayed features.
I have the feature layer added in OnDemand mode. Since the feature layer (in OnDemand mode) only returns the features in the map extent I was wondering if there is a method to retrieve the Name attribute of the returned features.
Instead of performing a spatial query each time the map extent changes, I simply retrieve the attribute from the features that is displayed.

Any hint would be greatly appreciated,
Mansour
0 Kudos
3 Replies
JamesMolohon
Emerging Contributor
You could add a handler to your layers UpdateCompleted event, and enumerate the layers Graphics collection to build a list. I've done something similar like this.

Dim layer As FeatureLayer = TryCast(sender, FeatureLayer)
For Each g As Graphic In layer.Graphics
       Dim mg As New MyGraphic With {.Label = g.Attributes("Label")}
       newList.Add(mg)
Next


James
0 Kudos
MansourArshon
Emerging Contributor
James,

It isn't doing what it expected to do; I am using the following FeatureLayer:
http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/Map...


If I add this featurelayer in snap shot mode, the count value is 500 (which is the correct total number of features) but if I add it in OnDemand mode, the count value is variable number much bigger than 500 and showing even bigger number every time the map extent changes, even when I am zooming in.
 
Dim layer As FeatureLayer = MyMap.Layers.Item(1)
mytxt.Text = layer.Graphics.Count
0 Kudos
MansourArshon
Emerging Contributor
I didn't realized that spatial query is performed in client side. I was trying to avoid the traffic when I wanted to avoid the spatial query approach. In fact, now I learned that performing spatial query is easier and quicker.
0 Kudos