예제 #1
0
        public static WMTSLayerClass GetWmtsLayer(string Url, string LayerName, string LayerId)
        {
            var propSet = new PropertySetClass();

            propSet.SetProperty("URL", Url);
            var wmtsConnFactory = new WMTSConnectionFactoryClass();
            var wmtsConnection  = wmtsConnFactory.Open(propSet, 0, null);

            var wmtsServiceDescription = (IWMTSServiceDescription)wmtsConnection;

            for (int i = 0; i < wmtsServiceDescription.LayerDescriptionCount; i++)
            {
                var layerDescription = wmtsServiceDescription.LayerDescription[i];
                if (layerDescription.Identifier == LayerId)
                {
                    var          wmtsLayer = new WMTSLayerClass();
                    IPropertySet propSet_1 = new PropertySetClass();
                    propSet_1.SetProperty("URL", Url);
                    propSet_1.SetProperty("LayerName", layerDescription.Identifier);

                    var connectionName = new WMTSConnectionNameClass();
                    connectionName.ConnectionProperties = propSet_1;
                    wmtsLayer.Connect((IName)connectionName);
                    wmtsLayer.Name = LayerName;
                    return(wmtsLayer);
                }
            }
            return(null);
        }
예제 #2
0
 public override void OnClick()
 {
     try
     {
         var          wmtsLayer = new WMTSLayerClass();
         var          propSet   = new PropertySetClass();
         const string url       = "http://t0.tianditu.com/vec_c/wmts?request=GetCapabilities&service=wmts";
         propSet.SetProperty("URL", url);
         var wmtsConnFactory = new WMTSConnectionFactoryClass();
         var wmtsConnection  = wmtsConnFactory.Open(propSet, 0, null);
         wmtsLayer.Connect(wmtsConnection.FullName);
         var mxdoc = (IMxDocument)_application.Document;
         var map   = mxdoc.FocusMap;
         wmtsLayer.Name = "Tianditu - World";
         ((IMapLayers)map).InsertLayer(wmtsLayer, true, 0);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
예제 #3
0
        private void AddLayerWMTS(CswRecord cswrecord)
        {
            //string url = @"http://gisdemo.agro.nl/wmts/PDOK_wmts_met_bbox_groot.xml";
            //string url = "http://acceptatie." + cswrecord.MapServerURL.Substring(7, cswrecord.MapServerURL.Length - 7);
            string url = cswrecord.MapServerURL;
            int lastIndex = cswrecord.MapServerURL.LastIndexOf('/') + 1;
            int length = cswrecord.MapServerURL.IndexOf('?') - lastIndex;
            string layerTitle = cswrecord.MapServerURL.Substring(lastIndex, length);

            try
            {
                IPropertySet propertySet = new PropertySetClass();
                propertySet.SetProperty("URL", url);

                IMxDocument mxDoc = (IMxDocument)m_application.Document;
                IMap map = (IMap)mxDoc.FocusMap;
                IActiveView activeView = (IActiveView)map;

                IWMTSConnectionFactory wmtsconnFact = new WMTSConnectionFactoryClass();
                IWMTSConnection wmtsconn = wmtsconnFact.Open(propertySet, 0, null);
                IWMTSServiceDescription wmtsServiceDesc = (IWMTSServiceDescription)wmtsconn;
                
                //Get WMTSConnectionName
                IWMTSConnectionName wmtsConnectionName = (IWMTSConnectionName)wmtsconn.FullName;

                for (int i = 0; i < wmtsServiceDesc.LayerDescriptionCount; i++)
                {
                    IWMTSLayerDescription ld = wmtsServiceDesc.get_LayerDescription(i);

                    IPropertySet layerPropertiesSet = wmtsConnectionName.ConnectionProperties;
                    //Set the layer name and assign this to the WMTSConnectionName
                    layerPropertiesSet.SetProperty("LAYERNAME", ld.Identifier);
                    wmtsConnectionName.ConnectionProperties = layerPropertiesSet;

                    if (ld.Title == layerTitle)//cswrecord.Title)
                    {
                        bool connected = false;
                        try
                        {
                            IWMTSLayer wmtslayer = new WMTSLayerClass();
                            
                            //Pass in the Name with layerIdentifier.
                            connected = wmtslayer.Connect((IName)wmtsConnectionName);

                            map.AddLayer((ILayer)wmtslayer);
                        }
                        catch (Exception ex)
                        {
                            ShowErrorMessageBox(StringResources.ConnectToMapServiceFailed + "\r\n" + "url:" + url + "\r\n" + ex.Message);
                            connected = false;
                        }
                    }
                }

                return;
            }
            catch (Exception ex)
            {
                //TODO: wmts string resource aanmaken?
                ShowErrorMessageBox(StringResources.AddWmsLayerFailed + "\r\n" + ex.Message);
            }
        }