/// <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; UpdateControls(); }
/// <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; UpdateControls(); }
/// <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); } }
/// <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); }
/// <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); }
/// <summary> /// Creating a sample (preview) based on a classObj, styleObj or labelObj. /// </summary> /// <param name="original">The wrapper holding the original object.</param> private void CreateSampleMap(MapObjectHolder original) { MapObjectHolder originalMap = null; MapObjectHolder originalLayer = null; MapObjectHolder originalClass = null; // create a sample map to render a preview of the given object if (original.GetType() == typeof(classObj)) { // tracking down the whole object tree originalLayer = original.GetParent(); if (originalLayer != null) originalMap = originalLayer.GetParent(); // creating a new compatible map object if (originalMap != null) { layerObj layer = InitializeDefaultLayer(originalMap, originalLayer); layer.insertClass(((classObj)original).clone(), -1); // bindings are not supported with sample maps classObj classobj = layer.getClass(0); for (int i = 0; i < classobj.numstyles; i++) StyleBindingController.RemoveAllBindings(classobj.getStyle(i)); for (int i = 0; i < classobj.numlabels; i++) LabelBindingController.RemoveAllBindings(classobj.getLabel(i)); classobj.setText("Sample text"); classobj.setExpression(""); // remove expression to have the class shown this.target = new MapObjectHolder(classobj, original.GetParent()); } } else if (original.GetType() == typeof(styleObj)) { // tracking down the whole object tree if (original.GetParent().GetType() == typeof(labelObj)) originalClass = original.GetParent().GetParent(); else originalClass = original.GetParent(); if (originalClass != null) originalLayer = originalClass.GetParent(); if (originalLayer != null) originalMap = originalLayer.GetParent(); // creating a new compatible map object if (originalMap != null) { layerObj layer = InitializeDefaultLayer(originalMap, originalLayer); classObj classobj = new classObj(layer); classobj.name = MapUtils.GetClassName(layer); styleObj style; if (original.GetParent().GetType() == typeof(labelObj)) { classobj.addLabel(new labelObj()); labelObj label = classobj.getLabel(classobj.numlabels - 1); MapUtils.SetDefaultLabel(label, layer.map); label.insertStyle(((styleObj)original).clone(), -1); style = label.getStyle(0); } else { classobj.insertStyle(((styleObj)original).clone(), -1); style = classobj.getStyle(0); } // bindings are not supported with sample maps StyleBindingController.RemoveAllBindings(style); classobj.setText("Sample text"); this.target = new MapObjectHolder(style, original.GetParent()); } } else if (original.GetType() == typeof(labelObj)) { // tracking down the whole object tree originalClass = original.GetParent(); if (originalClass != null) { if (originalClass.GetType() == typeof(classObj)) { originalLayer = originalClass.GetParent(); if (originalLayer != null) originalMap = originalLayer.GetParent(); } else if (originalClass.GetType() == typeof(scalebarObj)) { originalMap = originalClass.GetParent(); } } // creating a new compatible map object if (originalMap != null) { layerObj layer = InitializeDefaultLayer(originalMap, originalLayer); classObj classobj = new classObj(layer); classobj.name = MapUtils.GetClassName(layer); labelObj label = new labelObj(); if (originalClass.GetType() == typeof(classObj)) { // copy settings label.updateFromString(((labelObj)original).convertToString()); } classobj.addLabel(label); this.target = new MapObjectHolder(layer.getClass(0).getLabel(0), original.GetParent()); } } else throw new Exception("Invalid target type: " + original.GetType()); }
/// <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; } }
/// <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); } }
/// <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; } }
/// <summary> /// The ItemSelect event handler of the layer control. /// </summary> /// <param name="sender">The source object of this event.</param> /// <param name="target">The object which have been selected.</param> private void layerControl_ItemSelect(object sender, MapObjectHolder target) { ConfirmChanges(); layerPropertyEditor.Visible = false; mapPropertyEditor.Visible = false; selectedEditor = null; if (target == null) { } else if (target.GetType() == typeof(mapObj)) { mapPropertyEditor.Target = target; mapPropertyEditor.Visible = true; selectedEditor = mapPropertyEditor; } else if (target.GetType() == typeof(layerObj) || target.GetType() == typeof(classObj) || target.GetType() == typeof(styleObj) || target.GetType() == typeof(labelObj)) { layerPropertyEditor.Target = target; layerPropertyEditor.Visible = true; selectedEditor = layerPropertyEditor; } }