Select to view content in your preferred language

adding map service url

556
2
11-18-2013 07:18 PM
rakeshmenga
Emerging Contributor
hi,

i am trying to add mapservice through programtically (NOT XAML) through code behind in a simple
webmap application. here i am able to read the service Background.Child but not able to bind it to mapcontrol

code i have used is

((ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer)((new List<ESRI.ArcGIS.Client.Layer>(((ESRI.ArcGIS.Client.Map)(BackgroundBorder.Child)).Layers))[0])).Url = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";

Error;

"Index was out of range. Must be non-negative and less than the size of the collection"

kindly let me know any solution for this.

thanks in advance.

rakesh
0 Kudos
2 Replies
JohanCarlsson
Regular Contributor
Try this

ArcGISTiledMapServiceLayer tiles = new ArcGISTiledMapServiceLayer() 
{ 
    Url = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/0"
};
MapApplication.Current.Map.Layers.Add(tiles);
MapApplication.SetLayerName(tiles, "World Street Map");


EDIT:
The layer you are trying  to add is as feature layer, so you might want to try FeatureLayer instead of ArcGISTiledMapServiceLayer.
0 Kudos
DenisT
by
Deactivated User
((ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer)((new List<ESRI.ArcGIS.Client.Layer>(((ESRI.ArcGIS.Client.Map)(BackgroundBorder.Child)).Layers))[0])).Url = "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";

Add an x:Name attribute to Map in xaml, then use that name to access the map in the code-behind file.
There is a samples page for SL API.
0 Kudos