Esempio n. 1
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);
            }
        }