I have a map with one layer, roads. How do I detect which road the user clicks on in the mapclick event ?
I'll try to answer this, but it might depend on what kind of layer you have. In my example, I'm using an InMemoryFeatureLayer so this might be specific to this. First I find the layer using map.FindFeatureLayer, which I then cast as an InMemoryFeatureLayer.
Then my code looks something like this:
if ((featureLayer as InMemoryFeatureLayer).InternalFeatures.Count > 0)
{
featureLayer.Open();
Collection<Feature> selectedfeatures = featureLayer.QueryTools.GetFeaturesNearestTo(pointShape, GeographyUnit.Meter, 1, ReturningColumnsType.AllColumns);
featureLayer.Close();
if (selectedfeatures.Count > 0)
{
Then selectedFeatures is just a collection which I can use as needed. I will usually do a check on the distance between where the user clicked and the shape so if my only shapes are in Portland, but they click in NYC, they won't get a shape in Portland.
Hope this helps!
I should have included another line of code in my previous post. The pointShape that I refer to was taken from e.WorldLocation in the mapClick event.
Kimberly
Kenneth,
Attachment is a sample to demonstrate how to select a feature by clicking on the map and delete it. Hope it helps.
Thanks,
ThinkGeo Support
608-DeleteFeatureDemo.zip (11.4 KB)