Hi,something like this?int GetLayerID(string layerName) { var client = new WebClient(); client.DownloadStringCompleted += (sender, args) => { string json = args.Result; foreach (var layer in JObject.Parse(json)["layers"].Children()) { if (string.Equals((string)layer["name"], layerName, StringComparison.OrdinalIgnoreCase)) return (int)layer["id"]; } throw new InvalidOperationException(string.Format("A layer with the name '{0}' was not found in the MXD.", layerName)); }; string uri = "your map server url" + "?f=json"; client.DownloadStringAsync(new Uri(uri)); }
<esri:ArcGISDynamicMapServiceLayer x:Uid="dynMapSvcId" ID="BigMap" Url="" /> My understanding is that you know the url of your map service, so it should be: <esri:ArcGISDynamicMapServiceLayer x:Uid="dynMapSvcId" ID="BigMap" Url="http://<server>/ArcGIS/rest/services/<mapService>" /> then you can add an Initialized event handler: <esri:ArcGISDynamicMapServiceLayer x:Uid="dynMapSvcId" ID="BigMap" Url="http://<server>/ArcGIS/rest/services/<mapService>" Initialized="BigMap_Initialized" /> and in the event handler you can use the LayerInfo array to define which layerID you want to work with and make your query.Note that instead of using a graphicslayer and a query, you could use a feature layer which is basically doing that without any code from you. You just have to initialize the Url of the feature layer which is also something like http://<server>/ArcGIS/rest/services/<mapService>/LayerID
<esri:ArcGISDynamicMapServiceLayer x:Uid="dynMapSvcId" ID="BigMap" Url="" />
<esri:ArcGISDynamicMapServiceLayer x:Uid="dynMapSvcId" ID="BigMap" Url="http://<server>/ArcGIS/rest/services/<mapService>" />
<esri:ArcGISDynamicMapServiceLayer x:Uid="dynMapSvcId" ID="BigMap" Url="http://<server>/ArcGIS/rest/services/<mapService>" Initialized="BigMap_Initialized" />
I don't understand why Map.layers is null if you do have an ArcGISDynamicMapService inside it. You should at least have this layer in Map.Layers?That being said, this will not help you because at this moment the layer is not yet initialized so the sublayers are not yet known.You could put your code in the 'Initialized' event of the layer. At this moment, the LayerInfo array will be initialized.
I do have ArcGISDynamicMapService in my map, but at this point, I have not run the query to get the map layers yet. My code is run after the wpf map page is loaded (it is inside the xyz_loaded method). Map.Layers will be null. Hope I'm clear now.
One option is you to include an ArcGISDynamicMapService in your map. Then, the 'Layers' property of this ArcGISDynamicMapService is giving you an array with the layer IDs, names, ...If you don't want to include such a layer in your map, you can request yourself the mapserver endpoint and deserialize the result. Example of mapserver url : http://services.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Median_Age/MapServer?f=pjson
Oh you don't mean x:Name?If you mean name defined in the service, you can probably keep them in a dictionary (if you know that names will be unique), with URL as the value. You can add to the dictionary as each layer is initialized.For the main layer, you can use MapName.http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer~MapName.htmlFor the sub layers, you can use LayerInfo.Name and append the sub layer ID to the main layer's URL.http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.LayerInfo~Name.htmlFor FeatureLayer, it's similar.http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo_members.htmlThese information are available after the layer has initialized.
Is there a reason why you don't want to set the ID of the layer? You can get the layer based on ID or index.Map.Layers[LayerID] or Map.Layers[index]
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.