/// <summary> /// Click event handler of the buttonOK control. /// </summary> /// <param name="sender">The source object of this event.</param> /// <param name="e">The event parameters.</param> private void buttonOK_Click(object sender, EventArgs e) { // construct layer definition StringBuilder s = new StringBuilder(layerdef); s.Replace("%name%", MapUtils.GetUniqueLayerName(map, "grid", 0)); s.Replace("%labelformat%", textBoxLabelFormat.Text); s.Replace("%labelcolorR%", colorPickerLabelColor.Value.R.ToString()); s.Replace("%labelcolorG%", colorPickerLabelColor.Value.G.ToString()); s.Replace("%labelcolorB%", colorPickerLabelColor.Value.B.ToString()); s.Replace("%colorR%", colorPickerLineColor.Value.R.ToString()); s.Replace("%colorG%", colorPickerLineColor.Value.G.ToString()); s.Replace("%colorB%", colorPickerLineColor.Value.B.ToString()); if (textBoxLabelSize.Text.Trim() != "") { s.Replace("%labelsize%", textBoxLabelSize.Text.ToString()); } else { s.Replace("%labelsize%", "8"); } if (textBoxLineWidth.Text.Trim() != "") { s.Replace("%linewidth%", textBoxLineWidth.Text.ToString()); } else { s.Replace("%linewidth%", "2"); } // optional parameters if (textBoxMinArcs.Text.Trim() != "") { s.Replace("%minarcs%", "MINARCS " + textBoxMinArcs.Text.ToString()); } else { s.Replace("%minarcs%", ""); } if (textBoxMaxArcs.Text.Trim() != "") { s.Replace("%maxarcs%", "MAXARCS " + textBoxMaxArcs.Text.ToString()); } else { s.Replace("%maxarcs%", ""); } if (textBoxMinInterval.Text.Trim() != "") { s.Replace("%mininterval%", "MININTERVAL " + textBoxMinInterval.Text.ToString()); } else { s.Replace("%mininterval%", ""); } if (textBoxMaxInterval.Text.Trim() != "") { s.Replace("%maxinterval%", "MAXINTERVAL " + textBoxMaxInterval.Text.ToString()); } else { s.Replace("%maxinterval%", ""); } if (textBoxMinSubdivide.Text.Trim() != "") { s.Replace("%minsubdivide%", "MINSUBDIVIDE " + textBoxMinSubdivide.Text.ToString()); } else { s.Replace("%minsubdivide%", ""); } if (textBoxMaxSubdivide.Text.Trim() != "") { s.Replace("%maxsubdivide%", "MAXSUBDIVIDE " + textBoxMaxSubdivide.Text.ToString()); } else { s.Replace("%maxsubdivide%", ""); } if (textBoxProjection.Tag != null) { s.Replace("%projection%", textBoxProjection.Tag.ToString()); } else { s.Replace("%projection%", "init=epsg:4326"); } // create layer layerObj layer = new layerObj(map); try { layer.updateFromString(s.ToString()); DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error); map.removeLayer(layer.index); } }
/// <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); }