Select to view content in your preferred language

How to obtain feature ID

4869
27
11-16-2010 10:18 AM
DonFreeman
Emerging Contributor
Is there a sample around that shows how to obtain the feature ID (place it into a variable) when the user clicks on a point feature?
Silverlight 4

Thanks
0 Kudos
27 Replies
DonFreeman
Emerging Contributor
Thanks Jenn -
My layer displays OK as a MapDynamicServiceLayer but doesn't display as a featureService layer. Apparently the featureService layer requires the data to be taken from a geodatabase?

I guess I am puzzled because I can Identify and see the data I want, or I can load a featuredataform as if I was going to edit (but I cannot edit) and also see the data I need, why can't I just parse that data into a variable? Seems like this would be a fairly basic thing to do without requireing the jump into geodatabases.
🙂
0 Kudos
JenniferNery
Esri Regular Contributor
If you are using FeatureDataForm, then you must be using FeatureLayer, because FeatureDataForm need to set its FeatureLayer property in order to display attributes.
0 Kudos
DonFreeman
Emerging Contributor
If you are using FeatureDataForm, then you must be using FeatureLayer, because FeatureDataForm need to set its FeatureLayer property in order to display attributes.


Actually I'm not using FeatureDataForm. I was just blindly copying the ESRI sample and combining the featureDataForm with a DynamicMapServiceLayer. btw - It does work to bring up the data but doesn't allow editing.
0 Kudos
JenniferNery
Esri Regular Contributor
I think you will still get compile error because the FeatureLayer property would expect only FeatureLayer type. It is however, possible to create a FeatureLayer from a map service (maybe this is what you were doing). It is true that FeatureDataForm will show read-only fields if the FeatureLayer comes from a map service. You will not be allowed to edit, but you will be allowed to retrieve the feature ID, if this is part of your feature Attributes.
0 Kudos
DonFreeman
Emerging Contributor
I think you will still get compile error because the FeatureLayer property would expect only FeatureLayer type. It is however, possible to create a FeatureLayer from a map service (maybe this is what you were doing). It is true that FeatureDataForm will show read-only fields if the FeatureLayer comes from a map service. You will not be allowed to edit, but you will be allowed to retrieve the feature ID, if this is part of your feature Attributes.


Well . . . You were right. I went back to my previous attempt and it was in fact a FeatureLayer that I was playing with. Here is the code
<esri:FeatureLayer ID="PointLayer"
    Url="http://198.182.104.173/ArcGIS/rest/services/Intersection_Test/MapServer/0"
                MouseLeftButtonUp="FeatureLayer_MouseLeftButtonUp"
                DisableClientCaching="True" 
                Mode="OnDemand"
                SelectionColor="#FFFFFF00"
                OutFields="*" />


Interestingly, when I copy this exact code into my current project I get 2 errors that say "Mode" and "SelectionColor" are not properties of Feature Layer. The only difference is the current project is in Silverlight 4.

Also, the codebehind
private void FeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs args)
tells me I may be missing a reference because GraphicMouseButtonEventArgs cannot be found. I have all the same references (I think) but I did convert from VB to C#. So, before I can go further I need to get these fixed.
0 Kudos
JenniferNery
Esri Regular Contributor
For Silverlight 4, you need API v2.0 and up. Yeah, check that the project references are correct and that they point to the proper file location. Once you have verified that your project has the proper version and files, maybe you just need to add imports statement:
Imports ESRI.ArcGIS.Client
0 Kudos
DonFreeman
Emerging Contributor
For Silverlight 4, you need API v2.0 and up. Yeah, check that the project references are correct and that they point to the proper file location. Once you have verified that your project has the proper version and files, maybe you just need to add imports statement:
Imports ESRI.ArcGIS.Client


Well, I think I got the right file.
ArcGISSilverlightWPF20.exe filesize 7193 kb

I reinstalled it anyway with no change in the result. Is there a post install of some kind needed to integrate it with VWD?
0 Kudos
JenniferNery
Esri Regular Contributor
This is all you need for installing the API. http://help.arcgis.com/en/webapi/silverlight/help/Installation.htm
0 Kudos
DonFreeman
Emerging Contributor
This is all you need for installing the API. http://help.arcgis.com/en/webapi/silverlight/help/Installation.htm


Thanks. That confirms that I had the right file. But somehow my references were pointing to ver 1.1. So I deleted them and rereferenced the correct ones. I now have a FeatureLayer with a MouseLeftButtonUp="FeatureLayer_MouseLeftButtonUp" event. Can you show me how to capture the attribute in this event?
0 Kudos
AliMirzabeigi
Emerging Contributor
You can do this by listening to the FeatureLayer_MouseLeftButtonUp event handler. Use the following code snippet to get the attribute collection of the Graphic object that has been clicked by the user:
IDictionary<string, object> attributes = e.Graphic.Attributes;
0 Kudos