AnsweredAssumed Answered

How to get the layer url when Adding a layer

Question asked by CWang-esristaff Employee on Aug 16, 2018
Latest reply on Aug 19, 2018 by CWang-esristaff

Recently, I used the SDK to make a small plug-in. I need to get the URL of the layer when adding the layer. In fact, only when the type of the layer is ServiceLayer can I get the URL. But if I want to add a local data, similar to "C:\temp\test.shp", but in the Layer property can not get the URL (or Path, DataSource and other properties), so, is the SDK designed like this or still can use other method to get the URL.

 

Attach some code (Sure, is URL property, not URI property )

 

 LayersAddedEvent.Subscribe(AddLayer, false);

 

private void AddLayer(LayerEventsArgs args)
{

 

   List<Layer> layerList = args.Layers as List<Layer>;
   if (layerList != null && layerList.Count != 0)

 

   Layer layer = layerList[0] as Layer;
   string url = GetLayerUrl(layer);

}

 

private string GetLayerUrl(Layer layer)
{
// Determine whether the layer has URL property, if has, get URL value.
return layer?.GetType()?.GetProperty("URL")?.GetValue(layer) as string;
}

Outcomes