コード例 #1
0
        public static WmsTileSource Create(WmsInfo info)
        {
            var schema = new TileSchema
            {
                Format = "image/png",
                Srs    = info.CRS,
                Height = 256,
                Width  = 256,
            };

            var onlineResource = info.WmsCapabilities.Capability.Request.GetCapabilities.DCPType[0].Http.Get.OnlineResource.Href;

            return(new WmsTileSource(new WebTileProvider(new WmsRequest(new Uri(onlineResource),
                                                                        schema,
                                                                        new List <string> {
                info.Layer.Name
            },
                                                                        info.Style == null? null : new List <string> {
                info.Style
            },
                                                                        info.CustomParameters, info.WmsCapabilities.Version.VersionString),
                                                         fetchTile: d => RequestHelper.FetchImage(d, info.Credentials)
                                                         ),
                                     schema));
        }
コード例 #2
0
        public WMSServerParameters(WmsInfo data)
        {
            InitializeComponent();

            WmsInfo = data;
            if (WmsInfo == null)
            {
                return;
            }

            _wmsCapabilities = WmsInfo.WmsCapabilities;
            tbServerUrl.Text = WmsInfo.ServerUrl;
            if (WmsInfo.Credentials != null)
            {
                tbLogin.Text    = WmsInfo.Credentials.UserName;
                tbPassword.Text = WmsInfo.Credentials.Password;
            }

            ShowServerDetails(_wmsCapabilities);
            InitLayers(_wmsCapabilities);

            // Select layer
            tvLayers.SelectedNode = FindNodeByLayer(tvLayers.Nodes, WmsInfo.Layer);
            if (tvLayers.SelectedNode != null)
            {
                tvLayers.SelectedNode.EnsureVisible();
            }
            tvLayers.Select();
            tvLayers.Focus();

            // Select CRS
            lbCRS.SelectedItem = WmsInfo.CRS;

            // Select Style
            for (int i = 0; i < lbStyles.Items.Count; i++)
            {
                var style = (StyleWrapper)lbStyles.Items[i];
                if (style.Style.Name == WmsInfo.Style)
                {
                    lbStyles.SelectedIndex = i;
                    break;
                }
            }

            // Show custom parameters
            if (WmsInfo.CustomParameters != null)
            {
                tbCustomParameters.Text = string.Join(Environment.NewLine,
                                                      WmsInfo.CustomParameters.Select(d => string.Format("{0}={1}", d.Key, d.Value)));
            }
        }
コード例 #3
0
        private void btnGetCapabilities_Click(object sender, EventArgs e)
        {
            var serverUrl = tbServerUrl.Text;

            if (String.IsNullOrWhiteSpace(serverUrl))
            {
                return;
            }

            if (serverUrl.IndexOf("Request=GetCapabilities", StringComparison.OrdinalIgnoreCase) < 0)
            {
                serverUrl = serverUrl + "&Request=GetCapabilities";
            }
            if (serverUrl.IndexOf("SERVICE=WMS", StringComparison.OrdinalIgnoreCase) < 0)
            {
                serverUrl = serverUrl + "&SERVICE=WMS";
            }

            WmsCapabilities capabilities;

            try
            {
                var myRequest = WebRequest.Create(serverUrl);
                myRequest.Credentials = GetUserCredentials();
                using (var myResponse = myRequest.GetResponse())
                    using (var stream = myResponse.GetResponseStream())
                        capabilities = new WmsCapabilities(stream);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to read capabilities: " + ex.Message);
                return;
            }

            WmsInfo          = null;
            _wmsCapabilities = capabilities;

            ShowServerDetails(capabilities);
            InitLayers(capabilities);
        }
コード例 #4
0
        public WmsServiceProvider(string name) :
            base(name, null, new MemoryCache <byte[]>())
        {
            Configure = delegate
            {
                using (var wmsDialog = new WMSServerParameters(_data))
                {
                    if (wmsDialog.ShowDialog() != DialogResult.OK)
                    {
                        return(false);
                    }

                    _data = wmsDialog.WmsInfo;
                    if (_data != null)
                    {
                        TileSource = WmsTileSource.Create(_data);
                        TileCache  = new MemoryCache <byte[]>();
                        return(true);
                    }
                    return(false);
                }
            };
        }
コード例 #5
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (_wmsCapabilities == null)
            {
                MessageBox.Show("Select server to view.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (tvLayers.SelectedNode == null)
            {
                MessageBox.Show("Select layer to view.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (lbCRS.SelectedItem == null)
            {
                MessageBox.Show("Select CRS to view.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ProjectionInfo projectionInfo;

            try
            {
                var crs = (string)lbCRS.SelectedItem;
                if (string.Equals(crs, "CRS:84", StringComparison.OrdinalIgnoreCase))
                {
                    crs = "EPSG:4326";
                }
                var epsgCode = Convert.ToInt32(crs.Replace("EPSG:", ""));
                switch (epsgCode)
                {
                case 3857:
                    projectionInfo = KnownCoordinateSystems.Projected.World.WebMercator;
                    break;

                case 4326:
                    projectionInfo = KnownCoordinateSystems.Geographic.World.WGS1984;
                    break;

                default:
                    projectionInfo = ProjectionInfo.FromEpsgCode(epsgCode);
                    break;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Unsupported CRS. Select another CRS.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Parse custom parameters
            var cs = string.IsNullOrWhiteSpace(tbCustomParameters.Text)
                ? new Dictionary <string, string>()
                : tbCustomParameters.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                     .Select(d => d.Split('=')).ToDictionary(d => d[0], d => d[1]);

            WmsInfo = new WmsInfo(tbServerUrl.Text,
                                  _wmsCapabilities,
                                  (Layer)tvLayers.SelectedNode.Tag, cs, (string)lbCRS.SelectedItem, projectionInfo,
                                  lbStyles.SelectedItem == null? null :
                                  ((StyleWrapper)lbStyles.SelectedItem).Style.Name, GetUserCredentials());
            DialogResult = DialogResult.OK;
        }