Select to view content in your preferred language

Accessing FeatureLayers from within code (ie FeatureLayer not defined in XAML)

865
2
07-15-2010 08:53 AM
MichaelBlom
Deactivated User
Hello,

how would i write code to access and itterate the FeatureLayers of a service with only having the ArcGISDynamicMapServiceLayer defined in the XAML ie. without declaring the FeatureLayer in the XAML?


Below is how i am getting access to my LayerInfo's:

private void HawaiiPointsInitialised(object sender, EventArgs e)
        {
            var dynamicService = sender as ArcGISDynamicMapServiceLayer;
                foreach (LayerInfo fl in dynamicService.Layers)
                {
                }
        }

Thanks,
Mike
0 Kudos
2 Replies
MichaelBlom
Deactivated User
So, i think you need to define the feature layer within the XAML...

I tried to declare a feature layer in xaml then set the url in the code behind but you can't do that.

And i tried to create the FeatureLayer from scratch in the code behind, but no luck either.


Mike
0 Kudos
DominiqueBroux
Esri Frequent Contributor
It's possible to create feature layers by code.

Something like:
 
privatevoid HawaiiPointsInitialised(object sender, EventArgs e)
{
var dynamicService = sender asArcGISDynamicMapServiceLayer;
foreach (LayerInfo fl in dynamicService.Layers)
{
if (fl.DefaultVisibility == false)
continue;
if(fl.SubLayerIds != null && fl.SubLayerIds.Length > 0) // group layer
continue;
FeatureLayer featureLayer = newFeatureLayer();
featureLayer.Url = dynamicService.Url + "/" + fl.ID.ToString();
featureLayer.ID = fl.Name;
myMap.Layers.Add(featureLayer);
}
}
0 Kudos