Exemple #1
0
        /// <summary>
        /// Sets layer visibility for layer
        /// </summary>
        /// <param name="ipLayer">the layer object</param>
        /// <param name="strLayerName">the layer name</param>
        /// <param name="strSecretName">the secret name</param>
        /// <returns>visibility</returns>
        private bool SetLayerVisible(ILayer ipLayer, string strLayerName, string strSecretName)
        {
            bool bFound;

            // if it is composite
            if (ipLayer is ICompositeLayer)
            {
                ICompositeLayer ipCompLayer = (ICompositeLayer)ipLayer;

                //for each of the layers in the composite layer
                for (int idx = 0; idx < ipCompLayer.Count; idx++)
                {
                    //  recurse
                    bFound = SetLayerVisible(ipCompLayer.get_Layer(idx), strLayerName, strSecretName);
                    //if something was found, set me to be visible and set return value
                    if (bFound)
                    {
                        ipLayer.Visible = true;
                        return(true);
                    }
                }
            }
            else if (ipLayer is IWMSLayer)
            {
                IWMSLayer ipWMSLayer = (IWMSLayer)ipLayer;
                if (ipWMSLayer.WMSLayerDescription.Name == strSecretName)
                {
                    ipLayer.Visible = true;
                    return(true);
                }
            }
            else if (ipLayer is IIMSSubLayer)
            {
                IIMSSubLayer ipSubLayer = (IIMSSubLayer)ipLayer;
                IACLayer     ipACLayer  = ipSubLayer.IMSLayer;
                // use the secret ID
                if (ipACLayer.ID == strSecretName)
                {
                    ipLayer.Visible = true;
                    return(true);
                }
            }
            else
            {
                if (ipLayer.Name == strSecretName)
                {
                    ipLayer.Visible = true;
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        public ILayer GetWmsMapServerLyr(string url, string serviceName)
        {
            IPropertySet pPropertyset = new PropertySetClass();

            pPropertyset.SetProperty("url", url);

            IWMSConnectionName pWmsConnectionName = new WMSConnectionNameClass();

            pWmsConnectionName.ConnectionProperties = pPropertyset;
            IWMSConnectionFactory wmsConnFac = new WMSConnectionFactoryClass();
            IName nn = wmsConnFac.Open(pPropertyset, 0, null) as IName;

            IWMSGroupLayer pWmsMapLayer = new WMSMapLayerClass();
            IDataLayer     pDataLayer   = pWmsMapLayer as IDataLayer;

            pDataLayer.Connect(pWmsConnectionName as IName);

            IWMSServiceDescription pWmsServiceDesc = pWmsMapLayer.WMSServiceDescription;

            for (int i = 0; i < pWmsServiceDesc.LayerDescriptionCount; i++)
            {
                IWMSLayerDescription pWmsLayerDesc = pWmsServiceDesc.get_LayerDescription(i);
                ILayer pNewLayer = null;
                if (pWmsLayerDesc.LayerDescriptionCount == 0)
                {
                    IWMSLayer pWmsLayer = pWmsMapLayer.CreateWMSLayer(pWmsLayerDesc);
                    pNewLayer = pWmsLayer as ILayer;
                }
                else
                {
                    IWMSGroupLayer pWmsGroupLayer = pWmsMapLayer.CreateWMSGroupLayers(pWmsLayerDesc);
                    for (int j = 0; j < pWmsGroupLayer.Count; j++)
                    {
                        ILayer layer = pWmsGroupLayer.get_Layer(j);
                        if (layer.Name.ToLower() == serviceName.ToLower())
                        {
                            pWmsMapLayer.InsertLayer(layer, 0);
                            layer.Visible = true;
                            break;
                        }
                    }
                }
            }
            ILayer pLayer = pWmsMapLayer as ILayer;

            pLayer.Name    = pWmsServiceDesc.WMSTitle;
            pLayer.Visible = true;
            return(pLayer);
        }
Exemple #3
0
        /// <summary>
        /// 添加 WMS 网络图层
        /// </summary>
        /// <param name="map">地图对象</param>
        /// <param name="address">网址</param>
        /// <param name="layerName">图层名称</param>
        /// <param name="layerPosition">图层添加位置</param>
        public void addWMSLayer(IMap map, string address, string layerName, int layerPosition)
        {
            IPropertySet propSet = new PropertySet();

            propSet.SetProperty("url", address);

            IWMSConnectionName wmsConName = new WMSConnectionName();

            wmsConName.ConnectionProperties = propSet;

            IWMSGroupLayer wmsMapLayer = new WMSMapLayer() as IWMSGroupLayer;
            IDataLayer     dataLayer   = wmsMapLayer as IDataLayer;

            dataLayer.Connect(wmsConName as IName);

            IWMSServiceDescription wmsServiceDescription = wmsMapLayer.WMSServiceDescription;
            ILayer theLayer = null;

            for (int i = 0; i < wmsServiceDescription.LayerDescriptionCount; i++)
            {
                IWMSLayerDescription wmsLayerDesc = wmsServiceDescription.get_LayerDescription(i);
                if (wmsLayerDesc.LayerDescriptionCount == 0)
                {
                    IWMSLayer wmsLayer = wmsMapLayer.CreateWMSLayer(wmsLayerDesc);
                    theLayer = wmsLayer as ILayer;
                }
                else
                {
                    IWMSGroupLayer wmsGroupLayer = wmsMapLayer.CreateWMSGroupLayers(wmsLayerDesc);
                    for (int j = 0; j < wmsGroupLayer.Count; j++)
                    {
                        ILayer layer = wmsGroupLayer.get_Layer(i);
                        layer.Visible = true;
                        wmsMapLayer.InsertLayer(layer, 0);
                    }
                    theLayer = wmsMapLayer as ILayer;
                }
            }
            theLayer.Name    = wmsServiceDescription.WMSTitle;
            theLayer.Visible = true;
            map.AddLayer(theLayer);
            map.MoveLayer(theLayer, layerPosition);
        }
        protected override void OnClick()
        {
            IMxDocument        mxDoc       = (IMxDocument)ArcMap.Application.Document;
            IWMSGroupLayer     wmsMapLayer = new WMSMapLayerClass();
            IWMSConnectionName connName    = new WMSConnectionNameClass();

            IPropertySet propSet = new PropertySetClass();

            propSet.SetProperty("URL", "https://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer");
            connName.ConnectionProperties = propSet;

            //Put the WMS service layers in a DataLayer
            IDataLayer dataLayer = (IDataLayer)wmsMapLayer;

            dataLayer.Connect((IName)connName);

            // Get access to WMS service and layer propeties
            IWMSServiceDescription serviceDesc = wmsMapLayer.WMSServiceDescription;
            IWMSLayerDescription   groupDesc   = serviceDesc.LayerDescription[0];

            //Clear existing WMS service group layer.
            wmsMapLayer.Clear();

            //Create an empty layer and populate it with the desired sub layer index.
            ILayer    newLayer;
            IWMSLayer newWMSLayer = wmsMapLayer.CreateWMSLayer(groupDesc.LayerDescription[1]);

            newLayer = (ILayer)newWMSLayer;
            wmsMapLayer.InsertLayer(newLayer, 0);

            //Add the layer to the map.
            mxDoc.FocusMap.AddLayer((ILayer)wmsMapLayer);
            IActiveView activeView = (IActiveView)mxDoc.FocusMap;

            activeView.Refresh();

            ArcMap.Application.CurrentTool = null;
        }