Пример #1
0
        /// <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);
            }
        }