Exemplo n.º 1
0
        /// <summary>
        /// Adding the selected layer to map
        /// </summary>
        void AddLayerToMap()
        {
            // trying to open the layer
            layerObj layer = new layerObj(map);
            layer.connection = textBoxServer.Text.Trim();
            layer.connectiontype = MS_CONNECTION_TYPE.MS_WMS;
            layer.type = MS_LAYER_TYPE.MS_LAYER_RASTER;
            layer.status = mapscript.MS_ON;

            // set up authentication
            NetworkCredential cred = (NetworkCredential)resolver.GetCredentials();
            if (cred != null)
            {
                layer.metadata.set("wms_auth_username", cred.UserName);
                layer.metadata.set("wms_auth_password", cred.Password);
                layer.metadata.set("wms_auth_type", "any");
            }
            WebProxy proxy = (WebProxy)resolver.Proxy;
            if (proxy != null)
            {
                layer.metadata.set("wms_proxy_host", proxy.Address.Host);
                layer.metadata.set("wms_proxy_port", proxy.Address.Port.ToString());
                layer.metadata.set("wms_proxy_auth_type", "any");
                layer.metadata.set("wms_proxy_type", resolver.ProxyType);
                cred = (NetworkCredential)resolver.GetProxyCredentials();
                if (cred != null)
                {
                    layer.metadata.set("wms_proxy_username", cred.UserName);
                    layer.metadata.set("wms_proxy_password", cred.Password);
                }
            }

            // setting up the selected layer
            selected = new MapObjectHolder(layer, target);

            // set queryable flag
            if (wms_queryable == "1")
                layer.template = "query.html";

            // setting up the layer metadata section
            layer.metadata.set("wms_name", wms_name);
            layer.metadata.set("wms_format", comboBoxImageFormat.Text.Trim());

            layer.metadata.set("wms_server_version", wms_server_version);

            if (!colorPickerLayerColor.Value.IsEmpty)
            {
                colorObj color = new colorObj(colorPickerLayerColor.Value.R,
                    colorPickerLayerColor.Value.G, colorPickerLayerColor.Value.B, 0);
                layer.metadata.set("wms_bgcolor", "0x" + color.toHex().Substring(1));
            }

            if (!checkBoxTransparent.Checked)
                layer.metadata.set("wms_transparent", "FALSE");

            // wms_style
            if (comboBoxStyle.Text != "")
                layer.metadata.set("wms_style", comboBoxStyle.Text);

            // title
            if (wms_title != null)
                layer.name = MapUtils.GetUniqueLayerName(map, wms_title, 0);
            else
                layer.name = MapUtils.GetUniqueLayerName(map, "Layer", 0);

            // scale denom
            if (wms_maxscaledenom > 0)
                layer.maxscaledenom = wms_maxscaledenom;
            if (wms_minscaledenom > 0)
                layer.maxscaledenom = wms_minscaledenom;

            // get bbox parameters
            if (wms_bbox != null && map.numlayers == 1)
            {
                // this is the first layer, set the extent of the map
                map.setExtent(wms_bbox.minx, wms_bbox.miny, wms_bbox.maxx, wms_bbox.maxy);
            }

            // setting up the selected projection
            KeyValuePair<string, string> current = (KeyValuePair<string, string>)bs.Current;
            string wms_srs = current.Key;

            // mapping not EPSG systems to the EPSG variants
            if (string.Compare(wms_srs, "CRS:84", true) == 0)
                wms_srs = "EPSG:4326";
            else if (string.Compare(wms_srs, "CRS:83", true) == 0)
                wms_srs = "EPSG:4369";
            else if (string.Compare(wms_srs, "CRS:27", true) == 0)
                wms_srs = "EPSG:4267";

            if (wms_srs.StartsWith("EPSG", StringComparison.InvariantCultureIgnoreCase))
                layer.metadata.set("wms_srs", wms_srs);
            layer.setProjection(wms_srs);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adding the selected layer to map
        /// </summary>
        void AddLayerToMap()
        {
            // trying to open the layer
            layerObj layer = new layerObj(map);

            layer.connection     = textBoxServer.Text.Trim();
            layer.connectiontype = MS_CONNECTION_TYPE.MS_WMS;
            layer.type           = MS_LAYER_TYPE.MS_LAYER_RASTER;
            layer.status         = mapscript.MS_ON;

            // set up authentication
            NetworkCredential cred = (NetworkCredential)resolver.GetCredentials();

            if (cred != null)
            {
                layer.metadata.set("wms_auth_username", cred.UserName);
                layer.metadata.set("wms_auth_password", cred.Password);
                layer.metadata.set("wms_auth_type", "any");
            }
            WebProxy proxy = (WebProxy)resolver.Proxy;

            if (proxy != null)
            {
                layer.metadata.set("wms_proxy_host", proxy.Address.Host);
                layer.metadata.set("wms_proxy_port", proxy.Address.Port.ToString());
                layer.metadata.set("wms_proxy_auth_type", "any");
                layer.metadata.set("wms_proxy_type", resolver.ProxyType);
                cred = (NetworkCredential)resolver.GetProxyCredentials();
                if (cred != null)
                {
                    layer.metadata.set("wms_proxy_username", cred.UserName);
                    layer.metadata.set("wms_proxy_password", cred.Password);
                }
            }

            // setting up the selected layer
            selected = new MapObjectHolder(layer, target);

            // set queryable flag
            if (wms_queryable == "1")
            {
                layer.template = "query.html";
            }

            // setting up the layer metadata section
            layer.metadata.set("wms_name", wms_name);
            layer.metadata.set("wms_format", comboBoxImageFormat.Text.Trim());

            layer.metadata.set("wms_server_version", wms_server_version);

            if (!colorPickerLayerColor.Value.IsEmpty)
            {
                colorObj color = new colorObj(colorPickerLayerColor.Value.R,
                                              colorPickerLayerColor.Value.G, colorPickerLayerColor.Value.B, 0);
                layer.metadata.set("wms_bgcolor", "0x" + color.toHex().Substring(1));
            }

            if (!checkBoxTransparent.Checked)
            {
                layer.metadata.set("wms_transparent", "FALSE");
            }

            // wms_style
            if (comboBoxStyle.Text != "")
            {
                layer.metadata.set("wms_style", comboBoxStyle.Text);
            }

            // title
            if (wms_title != null)
            {
                layer.name = MapUtils.GetUniqueLayerName(map, wms_title, 0);
            }
            else
            {
                layer.name = MapUtils.GetUniqueLayerName(map, "Layer", 0);
            }

            // scale denom
            if (wms_maxscaledenom > 0)
            {
                layer.maxscaledenom = wms_maxscaledenom;
            }
            if (wms_minscaledenom > 0)
            {
                layer.maxscaledenom = wms_minscaledenom;
            }

            // get bbox parameters
            if (wms_bbox != null && map.numlayers == 1)
            {
                // this is the first layer, set the extent of the map
                map.setExtent(wms_bbox.minx, wms_bbox.miny, wms_bbox.maxx, wms_bbox.maxy);
            }

            // setting up the selected projection
            KeyValuePair <string, string> current = (KeyValuePair <string, string>)bs.Current;
            string wms_srs = current.Key;

            // mapping not EPSG systems to the EPSG variants
            if (string.Compare(wms_srs, "CRS:84", true) == 0)
            {
                wms_srs = "EPSG:4326";
            }
            else if (string.Compare(wms_srs, "CRS:83", true) == 0)
            {
                wms_srs = "EPSG:4369";
            }
            else if (string.Compare(wms_srs, "CRS:27", true) == 0)
            {
                wms_srs = "EPSG:4267";
            }

            if (wms_srs.StartsWith("EPSG", StringComparison.InvariantCultureIgnoreCase))
            {
                layer.metadata.set("wms_srs", wms_srs);
            }
            layer.setProjection(wms_srs);
        }