Ejemplo n.º 1
0
        internal void addWebMappingServiceToMap(Uri WMS_URI)
        {
            try
            {
                // create a new WMS layer for the ArcMap session
                IWMSGroupLayer     wmsMapLayer = new WMSMapLayer() as IWMSGroupLayer;
                IWMSConnectionName connName    = new WMSConnectionName();

                // set the property of the WMS layer to the Google Maps Engine
                // WMS GetCapabilities URL
                IPropertySet propSet = new PropertySet();
                propSet.SetProperty("URL", WMS_URI.ToString());

                connName.ConnectionProperties = propSet;

                // create a new data layer for the WMS layer to use
                IDataLayer dataLayer = wmsMapLayer as IDataLayer;
                dataLayer.Connect((IName)connName);

                // create a new ArcMap layer and add the WMS.  Set the name.
                IWMSServiceDescription serviceDesc = wmsMapLayer.WMSServiceDescription;
                ILayer layer = wmsMapLayer as ILayer;
                layer.Name = serviceDesc.WMSTitle;

                // add the WMS layer to the ArcMap session
                m_map.AddLayer(layer);
            }
            catch (System.Exception ex)
            {
                // an error occured and was not able to add the WMS layer to the map
                log.Error(ex);
                System.Windows.Forms.MessageBox.Show("Unable to add a WMS layer to the map.");
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public static void AddWMSTopMap(string title, string wmsURL, IGroupLayer parentGrpLayer)
        {
            // WMS GetCapabilities URL
            IPropertySet propSet = new PropertySet();

            propSet.SetProperty("URL", wmsURL);

            IWMSGroupLayer     wmsMapLayer = new WMSMapLayer() as IWMSGroupLayer;
            IWMSConnectionName connName    = new WMSConnectionName();

            // set the property of the WMS layer to the Google Maps Engine
            connName.ConnectionProperties = propSet;

            // create a new data layer for the WMS layer to use
            IDataLayer dataLayer = wmsMapLayer as IDataLayer;

            dataLayer.Connect((IName)connName);

            // create a new ArcMap layer and add the WMS.  Set the name.
            IWMSServiceDescription serviceDesc = wmsMapLayer.WMSServiceDescription;
            ILayer layer = wmsMapLayer as ILayer;

            layer.Name    = title;
            layer.Visible = true;
            //layer.Name = serviceDesc.WMSTitle;

            // add the WMS layer to the ArcMap session
            ((IMapLayers)ArcMap.Document.FocusMap).InsertLayerInGroup(parentGrpLayer, layer, true, 0);
            //((IMapLayers)ArcMap.Document.FocusMap).InsertLayer(layer, true, 0);

            if (wmsMapLayer is ICompositeLayer)
            {
                ChangeGroupLayerVisibility((ICompositeLayer)wmsMapLayer, true);
            }

            ArcMap.Document.UpdateContents();
            ArcMap.Document.ActiveView.Refresh();
            ArcMap.Document.CurrentContentsView.Refresh(null);
        }
        internal void addWebMappingServiceToMap(Uri WMS_URI)
        {
            try
            {
                // create a new WMS layer for the ArcMap session
                IWMSGroupLayer wmsMapLayer = new WMSMapLayer() as IWMSGroupLayer;
                IWMSConnectionName connName = new WMSConnectionName();

                // set the property of the WMS layer to the Google Maps Engine
                // WMS GetCapabilities URL
                IPropertySet propSet = new PropertySet();
                propSet.SetProperty("URL", WMS_URI.ToString());

                connName.ConnectionProperties = propSet;

                // create a new data layer for the WMS layer to use
                IDataLayer dataLayer = wmsMapLayer as IDataLayer;
                dataLayer.Connect((IName)connName);

                // create a new ArcMap layer and add the WMS.  Set the name.
                IWMSServiceDescription serviceDesc = wmsMapLayer.WMSServiceDescription;
                ILayer layer = wmsMapLayer as ILayer;
                layer.Name = serviceDesc.WMSTitle;

                // add the WMS layer to the ArcMap session
                m_map.AddLayer(layer);
            }
            catch (System.Exception ex)
            {
                // an error occured and was not able to add the WMS layer to the map
                log.Error(ex);
                System.Windows.Forms.MessageBox.Show("Unable to add a WMS layer to the map.");
            }
        }