ArcGISDynamicMapServiceLayer layer = new ArcGISDynamicMapServiceLayer(); layer.Url = myUrl; //this is just a string I acquire somewhere else layer.InitializationFailed += new EventHandler<EventArgs>(layer_InitializationFailed); //I added this in case our service was down layer.Initialize(); //I initialized here and... if (layer.IsInitialized) //when I test in this line it says false map1.Layers.Insert(1, layer); ...... void layer_InitializationFailed(object sender, EventArgs e) { MessageBox.Show("Your Layer was not initialized properly. The service may be down or there is a network problem."); }
Solved! Go to Solution.
ArcGISDynamicMapServiceLayer layer = new ArcGISDynamicMapServiceLayer() { Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer" }; layer.Initialized += (a, b) => { if (layer.IsInitialized && layer.InitializationFailure == null) map1.Layers.Insert(1, layer); }; layer.Initialize();
ArcGISDynamicMapServiceLayer layer = new ArcGISDynamicMapServiceLayer() { Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer" }; layer.Initialized += new EventHandler<EventArgs>(layer_Initialized); layer.Initialize(); } void layer_Initialized(object sender, EventArgs e) { var layer = sender as Layer; if (layer.IsInitialized && layer.InitializationFailure == null) map1.Layers.Insert(1, layer); }
ArcGISDynamicMapServiceLayer layer = new ArcGISDynamicMapServiceLayer() { Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer" }; layer.Initialized += (a, b) => { if (layer.IsInitialized && layer.InitializationFailure == null) map1.Layers.Insert(1, layer); }; layer.Initialize();
ArcGISDynamicMapServiceLayer layer = new ArcGISDynamicMapServiceLayer() { Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer" }; layer.Initialized += new EventHandler<EventArgs>(layer_Initialized); layer.Initialize(); } void layer_Initialized(object sender, EventArgs e) { var layer = sender as Layer; if (layer.IsInitialized && layer.InitializationFailure == null) map1.Layers.Insert(1, layer); }