Exemple #1
0
        /// <summary>
        /// Constructs a new AddWMSLayerForm class.
        /// </summary>
        public AddWMSLayerForm(MapObjectHolder target)
        {
            InitializeComponent();
            if (target.GetType() != typeof(mapObj))
            {
                throw new ApplicationException("Invalid object type.");
            }
            this.map    = target;
            this.target = target;

            var keyDown = Observable.FromEventPattern <KeyEventArgs>(this, "KeyDown");

            keyDown.Subscribe(evt =>
            {
                if (evt.EventArgs.KeyCode == Keys.Escape)
                {
                    Close();
                }
            });

            this.Bind(ViewModel, vm => vm.ServerUrl, v => v.textBoxServer.Text);
            this.BindCommand(ViewModel, a => a.Load, b => b.buttonLoadLayers); // TODO: Handle Loading in ViewModel

            ViewModel = new AddWMSLayerFormViewModel(target);

            UpdateControls();
        }
Exemple #2
0
        /// <summary>
        /// EditProperties Event handler for the layerControlStyles object.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">Event parameters.</param>
        private void layerControlStyles_EditProperties(object sender, MapObjectHolder target)
        {
            try
            {
                MapPropertyEditorForm mapPropertyEditor;
                if (target.GetType() == typeof(classObj))
                {
                    classObj classobj = target;

                    if (classobj.numstyles <= 0)
                    {
                        // adding an empty style to this class
                        styleObj style = new styleObj(classobj);
                    }

                    mapPropertyEditor = new MapPropertyEditorForm(
                        new MapObjectHolder(classobj.getStyle(0), target), new StyleLibraryPropertyEditor());
                }
                else if (target.GetType() == typeof(styleObj))
                {
                    mapPropertyEditor = new MapPropertyEditorForm(target, new StyleLibraryPropertyEditor());
                }
                else
                {
                    return;
                }
                propertyChanged         = false;
                target.PropertyChanged += new EventHandler(target_PropertyChanged);
                mapPropertyEditor.ShowDialog(this);
                if (propertyChanged)
                {
                    layerControlStyles.RefreshView();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemple #3
0
        /// <summary>
        /// Update the Sample image according to the selected element
        /// </summary>
        /// <param name="target">Selected element</param>
        private void UpdateSample(MapObjectHolder target)
        {
            layerObj layer    = null;
            mapObj   map      = null;
            classObj classobj = null;

            if (target.GetType() == typeof(layerObj))
            {
                layer    = target;
                map      = layer.map;
                classobj = layer.getClass(0);
            }
            else if (target.GetType() == typeof(classObj))
            {
                classobj = target;
                if (classobj != null)
                {
                    layer = classobj.layer;
                }
                if (layer != null)
                {
                    map = layer.map;
                }
            }
            if (map == null || layer == null || classobj == null)
            {
                pictureBoxSample.Image = null;
                return;
            }

            styleObj style = classobj.getStyle(0);
            double   size  = style.size;

            // collect all fonts specified in the fontset file
            Hashtable fonts = new Hashtable();
            string    key   = null;

            while ((key = this.map.fontset.fonts.nextKey(key)) != null)
            {
                fonts.Add(key, key);
            }
            textBoxInfo.Text = "";
            if (style.symbol >= 0)
            {
                string font = ((mapObj)StyleLibrary.Styles).symbolset.getSymbol(style.symbol).font;
                if (font != null && !fonts.ContainsKey(font))
                {
                    textBoxInfo.Text = "WARNING: The fontset of the map doesn't contain " + font + " font. This symbol will not be selectable on the map.";
                }
            }

            if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
            {
                // apply magnification for point styles
                style.size = size * trackBarMagnify.Value / 4;
            }

            try
            {
                using (classObj def_class = new classObj(null)) // for drawing legend image
                {
                    using (imageObj image2 = def_class.createLegendIcon(map, layer,
                                                                        pictureBoxSample.Width, pictureBoxSample.Height))
                    {
                        classobj.drawLegendIcon(map, layer,
                                                pictureBoxSample.Width, pictureBoxSample.Height, image2, 5, 5);
                        byte[] img = image2.getBytes();
                        using (MemoryStream ms = new MemoryStream(img))
                        {
                            pictureBoxSample.Image = Image.FromStream(ms);
                        }
                    }
                }
            }
            finally
            {
                style.size = size;
            }
        }
Exemple #4
0
        /// <summary>
        /// Constructs a new MapPropertyEditorForm object.
        /// </summary>
        /// <param name="target">The target object to be edited.</param>
        /// <param name="editor">The editor to be used.</param>
        public MapPropertyEditorForm(MapObjectHolder target, IPropertyEditor editor)
        {
            InitializeComponent();
            this.SuspendLayout();
            if (target.GetType() == typeof(mapObj))
            {
                if (editor == null)
                {
                    editor = new MapPropertyEditor();
                    ((MapPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Map Properties";
                mapObj map = (mapObj)target;
                if (map.name != "")
                {
                    this.Text += " (" + map.name + ")";
                }
                this.editor = editor;
            }
            else if (target.GetType() == typeof(layerObj))
            {
                if (editor == null)
                {
                    editor = new LayerPropertyEditor();
                    ((LayerPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Layer Properties";
                layerObj layer = (layerObj)target;
                if (layer.name != "")
                {
                    this.Text += " (" + layer.name + ")";
                }
                this.editor = editor;
            }
            else if (target.GetType() == typeof(classObj))
            {
                if (editor == null)
                {
                    editor = new ClassPropertyEditor();
                    ((ClassPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text = "Class Properties";
                classObj classObject = (classObj)target;

                StringBuilder scaledomain = new StringBuilder("");
                if (classObject.minscaledenom >= 0)
                {
                    if (classObject.maxscaledenom >= 0)
                    {
                        scaledomain.Append(" 1:" + classObject.minscaledenom.ToString("#,#", CultureInfo.InvariantCulture));
                    }
                    else
                    {
                        scaledomain.Append(" from 1:" + classObject.minscaledenom.ToString("#,#", CultureInfo.InvariantCulture));
                    }
                }
                if (classObject.maxscaledenom >= 0)
                {
                    scaledomain.Append(" to 1:" + classObject.maxscaledenom.ToString("#,#", CultureInfo.InvariantCulture));
                }

                if (classObject.name != "")
                {
                    this.Text += " (" + classObject.name + scaledomain + ")";
                }
                this.editor = editor;
            }
            else if (target.GetType() == typeof(styleObj))
            {
                if (editor == null)
                {
                    editor = new StylePropertyEditor();
                    ((StylePropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text   = "Style Properties";
                this.editor = editor;
            }

            else if (target.GetType() == typeof(labelObj))
            {
                if (editor == null)
                {
                    editor = new LabelPropertyEditor();
                    ((LabelPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text   = "Label Properties";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(scalebarObj))
            {
                if (editor == null)
                {
                    editor = new ScalebarPropertyEditor();
                    ((ScalebarPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text   = "Scalebar Properties";
                this.editor = editor;
            }
            else if (target.GetType() == typeof(queryMapObj))
            {
                if (editor == null)
                {
                    editor = new QueryMapPropertyEditor();
                    ((QueryMapPropertyEditor)editor).HelpRequested +=
                        new HelpEventHandler(mapPropertyEditor_HelpRequested);
                }

                this.Text   = "Query Map Properties";
                this.editor = editor;
            }
            else
            {
                throw new Exception("No editor have been implemented for this item");
            }

            if (this.editor != null)
            {
                Control c = (Control)this.editor;
                c.Location = new System.Drawing.Point(3, 4);
                c.TabIndex = 0;

                editor.Target = target;
                this.Controls.Add(c);
                target.PropertyChanging += new EventHandler(target_PropertyChanging);
                editor.EditProperties   += new EditPropertiesEventHandler(editor_EditProperties);

                buttonOK.Top     = c.Bottom + 8;
                buttonCancel.Top = c.Bottom + 8;
                buttonApply.Top  = c.Bottom + 8;
            }

            UpdateButtonState();

            this.ResumeLayout(false);
        }