Select to view content in your preferred language

How I can Acces to the Renderer of layer of a LocalMapService

767
4
12-13-2012 09:20 AM
Labels (1)
JesúsVillajos1
Occasional Contributor
Hi,


How can I access the properties of a layer rendering of a LocalMapService?

I try get the next code to obtein the layers details

Layer l = Map.Layers[0]

if (l is ArcGISLocalDynamicMapServiceLayer)
{
     ArcGISLocalDynamicMapServiceLayer localDyn = l as ArcGISLocalDynamicMapServiceLayer;
     foreach (LayerDetails ld in localDyn.Service.MapLayers)
     {

      ...
     }
}


The LayerDetails has not Symbol property to obtein the renderer of the layer.
The LayerDetails has a Url with the local service. It can be read and get the Renderer but this
is not very dynamic. Is there any way to get the layer renderer?

Jesús Villajos Novillo

Software Engineer.


th
0 Kudos
4 Replies
MichaelBranscomb
Esri Frequent Contributor
Hi,

Unfortunately there's nothing currently in the API to retrieve the existing renderer for layers within a local map service. However, you should be able to construct the URL for a REST request to the ...\MapServer endpoint and download the JSON as a string which will contain the rendering information. The Renderer class has a FromJson method which enables you to reconstruct the renderer from the downloaded JSON.

We'll investigate a better way to support this in a future release.

Cheers

Mike
0 Kudos
GeorgeFaraj
Frequent Contributor
Hi,

Unfortunately there's nothing currently in the API to retrieve the existing renderer for layers within a local map service. However, you should be able to construct the URL for a REST request to the ...\MapServer endpoint and download the JSON as a string which will contain the rendering information. The Renderer class has a FromJson method which enables you to reconstruct the renderer from the downloaded JSON.



Can someone provide sample code that does this? I am also trying to retrieve the renderer/symbol from a LayerDetails.
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

There's actually a much simpler way to achieve this than going via JSON (although that's still a valid route, particularly if you're already using a 3rd party JSON parsing library or you're using .NET 4.5).

The solution then is to create a one or more FeatureLayers, one for each layer in the local map service, then directly call the Initialize method on the FeatureLayer which will download the service metadata and populate the properties, one of which is Renderer.

For example:

  public MainWindow()
        {
            InitializeComponent();

            _map.Layers.LayersInitialized += (s, e) =>
            {
                ArcGISLocalDynamicMapServiceLayer localDynamicServiceLayer = _map.Layers["USA"] as ArcGISLocalDynamicMapServiceLayer;

                IRenderer renderer;

                FeatureLayer featureLayer = new FeatureLayer()
                {
                    Url = localDynamicServiceLayer.Url + "/0"
                };

                featureLayer.Initialized += (fLayer, eventArgs) =>
                {
                    if (featureLayer.Renderer != null)
                    {
                        // Do Something with Renderer.
                        renderer = featureLayer.Renderer;
                    }
                };
                featureLayer.Initialize();
            };
        }



Cheers

Mike
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

There's actually a much simpler way to do this already in the API: The GetAllDetails Method returns a Dictionary of FeatureLayerInfo objects. The FeatureLayerInfo object is rich with numerous Properties that can be used to get metadata information about the ArcGISDynamicMapServiceLayer web service. To get the details for a specific sub-layer in an ArcGISDynamicMapServiceLayer consider using the ArcGISDynamicMapServiceLayer.GetDetails instead.

http://resources.arcgis.com/en/help/runtime-wpf/apiref/index.html?ESRI.ArcGIS.Client~ESRI.ArcGIS.Cli....

Cheers

Mike
0 Kudos