/// <summary> /// Add new dynamic base layer at the end of the layer list /// </summary> /// <param name="layerUrl">URL of the rest mapservice</param> /// <param name="visible">Visible or not</param> /// <param name="layerName">Layername allocated</param> public void AddNewDynamicLayer(string layerUrl, bool visible, string layerName, ArcGISServiceType serviceType) { AddNewDynamicLayer(layerUrl, visible, layerName, -1, serviceType); }
/// <summary> /// Add new dynamic base layer at a specific position /// </summary> /// <param name="layerUrl">URL of the rest mapservice</param> /// <param name="visible">Visible or not</param> /// <param name="layerName">Layername allocated</param> /// <param name="index">Position in the map</param> public void AddNewDynamicLayer(string layerUrl, bool visible, string layerName, int index,ArcGISServiceType serviceType) { if (serviceType == ArcGISServiceType.Dynamic) { ArcGISDynamicMapServiceLayer mapLayer = new ArcGISDynamicMapServiceLayer() { Url = layerUrl, DisableClientCaching = true, ID = layerName, Visible = visible }; mapLayer.Initialized += InitializedDynamicLayer; mapLayer.InitializationFailed += layer_InitializationFailed; if (index < 0) mapControl.Layers.Add(mapLayer); else mapControl.Layers.Insert(index, mapLayer); } else if (serviceType == ArcGISServiceType.Image) { ArcGISTiledMapServiceLayer mapLayer = new ArcGISTiledMapServiceLayer() { Url = layerUrl, ID = layerName, Visible = visible }; mapLayer.Initialized += InitializedDynamicLayer; mapLayer.InitializationFailed += layer_InitializationFailed; if (index < 0) mapControl.Layers.Add(mapLayer); else mapControl.Layers.Insert(index, mapLayer); } }
public void Add(string sLink, string sID) { ArcGISServiceType myType = ArcGISServiceType.Unknown; if (sLink.ToUpper().IndexOf("SERVICE=WMS") > 0) { myType = ArcGISServiceType.WMS; } else if (sLink.ToUpper().IndexOf("IMAGESERVER") > 0) { myType = ArcGISServiceType.ImageServer; } else if (sLink.ToUpper().IndexOf("ARCGIS/REST") > 0) { if (sLink.ToUpper().IndexOf("MAPSERVER") > 0) { myType = ArcGISServiceType.ArcGIS; } } _status = "Adding new service..."; ESRI.ArcGIS.Client.Layer layer = null; switch (myType) { case ArcGISServiceType.ArcGIS: layer = new ArcGISDynamicMapServiceLayer(); ArcGISDynamicMapServiceLayer temp = layer as ArcGISDynamicMapServiceLayer; temp.InitializationFailed += new EventHandler <EventArgs>(layer_InitializationFailed); temp.Initialized += new EventHandler <EventArgs>(temp_Initialized); temp.Url = sLink; temp.ID = sID; break; case ArcGISServiceType.ImageServer: layer = new ArcGISImageServiceLayer(); ArcGISImageServiceLayer imageServer = layer as ArcGISImageServiceLayer; imageServer.Url = sLink; imageServer.ID = sID; imageServer.Initialized += new EventHandler <EventArgs>(temp_Initialized); imageServer.InitializationFailed += new EventHandler <EventArgs>(imageServer_InitializationFailed); break; case ArcGISServiceType.WMS: layer = new ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer(); ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer wmsLayer = layer as ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer; wmsLayer.InitializationFailed += new EventHandler <EventArgs>(wmsLayer_InitializationFailed); wmsLayer.Initialized += new EventHandler <EventArgs>(temp_Initialized); string [] layers = new string[1]; layers[0] = "1"; wmsLayer.Layers = layers; wmsLayer.Url = CleanWMSSErvices(sLink); wmsLayer.ID = sID; break; case ArcGISServiceType.IMS: layer = new ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer(); ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer imsLayer = layer as ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer; imsLayer.InitializationFailed += new EventHandler <EventArgs>(imsLayer_InitializationFailed); imsLayer.Initialized += new EventHandler <EventArgs>(temp_Initialized); imsLayer.ID = sID; imsLayer.ServiceHost = sLink; imsLayer.ServiceHost = sLink; break; } if (layer != null) { _mapServicesID.Add(layer.ID); _map.Layers.Add(layer); } }