Пример #1
0
        /// <summary>
        /// Refresh the layer list by submitting a GetCapabilities request.
        /// </summary>
        public void LoadLayers()
        {
            while (true)
            {
                try
                {
                    this.Cursor           = Cursors.WaitCursor;
                    ViewModel.XmlDocument = Capability.GetCapabilities(ViewModel.ServerUrl.Trim());
                    break;
                }
                catch (WebException wex)
                {
                    if (wex.Status == WebExceptionStatus.ProtocolError)
                    {
                        // Get HttpWebResponse to check the HTTP status code.
                        HttpWebResponse httpResponse = (HttpWebResponse)wex.Response;
                        if (httpResponse.StatusCode == HttpStatusCode.Unauthorized ||
                            httpResponse.StatusCode == HttpStatusCode.ProxyAuthenticationRequired)
                        {
                            CredentialsForm form = new CredentialsForm("Authentication required for " + ViewModel.ServerUrl,
                                                                       ViewModel.XmlProxyUrlResolver);
                            if (form.ShowDialog(this) == DialogResult.OK)
                            {
                                continue;
                            }
                            return;
                        }
                    }
                    MessageBox.Show("Unable to load WMS capabilities of the layer, " + wex.Message,
                                    "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to load WMS capabilities of the layer, " + ex.Message,
                                    "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }

            // load supported image types
            var formatNodes = ViewModel.Formats;

            comboBoxImageFormat.Items.Clear();
            foreach (XmlNode node in formatNodes)
            {
                int index = comboBoxImageFormat.Items.Add(node.InnerText.Trim());
                if (comboBoxImageFormat.Items[index].ToString() == map.outputformat.mimetype ||
                    (comboBoxImageFormat.SelectedIndex < 0 &&
                     map.outputformat.mimetype.StartsWith(comboBoxImageFormat.Items[index].ToString())) ||
                    comboBoxImageFormat.Items[index].ToString().ToLower().StartsWith("image/png"))
                {
                    comboBoxImageFormat.SelectedIndex = index;
                }
            }

            bs                      = new BindingSource();
            bs.DataSource           = ViewModel.Projections;
            comboBoxProj.DataSource = bs;

            UpdateProjBinding();

            if (ViewModel.SelectedProjection != null)
            {
                comboBoxProj.SelectedValue = ViewModel.SelectedProjection;
            }

            if (comboBoxImageFormat.SelectedIndex < 0 && comboBoxImageFormat.Items.Count > 0)
            {
                comboBoxImageFormat.SelectedIndex = 0;
            }

            // ensure default imageindices are invalid
            if (treeViewLayers.ImageList != null)
            {
                treeViewLayers.ImageIndex         = treeViewLayers.ImageList.Images.Count;
                treeViewLayers.SelectedImageIndex = treeViewLayers.ImageList.Images.Count;
            }

            // set up the treeView
            treeViewLayers.BeginUpdate();
            treeViewLayers.Nodes.Clear();
            listViewLayers.Items.Clear();
            var layerNodes = Capability.GetLayerNodes(ViewModel.XmlDocument);

            foreach (XmlNode node in layerNodes)
            {
                AddLayerNode(treeViewLayers.Nodes, node);
            }
            treeViewLayers.EndUpdate();
            treeViewLayers.ExpandAll();

            if (treeViewLayers.Nodes.Count > 0)
            {
                treeViewLayers.Nodes[0].EnsureVisible();
            }
        }