public static void Load(string fileName) { styles = MapUtils.OpenMap(fileName); map = styles; styleLibFileName = fileName; // get symbolset file name string styleDir = Path.GetDirectoryName(fileName); if (File.Exists(map.symbolset.filename)) { symbolsetFileName = map.symbolset.filename; } else { throw new Exception("Cannot load Symbolset file." + map.symbolset.filename); } if (File.Exists(map.fontset.filename)) { fontsetFileName = map.fontset.filename; } else { throw new Exception("Cannot load Fontset file. " + map.fontset.filename); } ExpandFontStyles(); }
public AddWMSLayerFormViewModel(MapObjectHolder target) { this.Log().Debug("AddWMSLayerFormViewModel"); Load = ReactiveCommand.Create(() => { Log.Debug("Load"); if (Projections != null) { var epsg4326 = Projections.Find(f => f.Key == "EPSG:4326"); SelectedProjection = epsg4326.Value; // FIX: This doesn't work (and it should default to map projection anyway) } }); // TODO: Handle Loading in ViewModel this.WhenAnyValue(a => a.XmlDocument) .Select(s => s != null ? Version.GetVersion(s) : null) .ToPropertyEx(this, p => p.ServerVersion); this.WhenAnyValue(a => a.XmlDocument) .Select(s => s != null ? Format.GetFormatNodes(s) : null) .ToPropertyEx(this, p => p.Formats); this.WhenAnyValue(a => a.XmlDocument) .Select(s => s != null ? Projection.GetProjections(s, Epsgs) : null) .ToPropertyEx(this, p => p.Projections); Epsgs = Epsg.GetEpsg(); }
/// <summary> /// Constructs a new ThemeWizardForm object. /// </summary> /// <param name="target">The object that this Wizard operates on.</param> public ThemeWizardForm(MapObjectHolder target) { InitializeComponent(); this.target = target; ListViewItem item = new ListViewItem(); item.Text = "Individual Values"; IndividualValuesTheme theme = new IndividualValuesTheme(); theme.Visible = false; item.Tag = theme; listViewThemes.Items.Add(item); item = new ListViewItem(); item.Text = "Value Ranges"; RangeTheme theme2 = new RangeTheme(); theme2.Visible = false; item.Tag = theme2; listViewThemes.Items.Add(item); buttonBack.Enabled = false; buttonNext.Enabled = false; pageIndex = 1; }
/// <summary> /// Click event handler of the buttonEditStyle control /// </summary> /// <param name="sender">The source object of this event.</param> /// <param name="e">The event parameters.</param> private void buttonEditStyle_Click(object sender, EventArgs e) { if (listViewStyles.SelectedItems.Count == 0) { return; } try { styleObj style = (styleObj)listViewStyles.SelectedItems[0].Tag; MapObjectHolder styletarget = new MapObjectHolder(style, target); styletarget.PropertyChanged += new EventHandler(styletarget_PropertyChanged); //MapPropertyEditorForm stylePropertyEditor = new MapPropertyEditorForm(styletarget); //stylePropertyEditor.ShowDialog(this); if (this.EditProperties != null) { this.EditProperties(this, styletarget); } isStyleChanged = true; UpdatePreview(); } catch (Exception ex) { MessageBox.Show(ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
/// <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(); }
public ScriptConsoleForm(MapObjectHolder mapH) { InitializeComponent(); this.mapH = mapH; this.map = mapH; ListSupportedLanguages(); }
/// <summary> /// EditProperties event handler of the layerControl control /// </summary> /// <param name="sender">The source object of this event.</param> /// <param name="target">The target object to be edited.</param> void layerControl_EditProperties(object sender, MapObjectHolder target) { try { MapPropertyEditorForm mapPropertyEditor = new MapPropertyEditorForm(target); mapPropertyEditor.ShowDialog(this); } catch (Exception ex) { MessageBox.Show(ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
/// <summary> /// Constructs a new ChangeViewForm class. /// </summary> public StyleLibraryForm(MapObjectHolder target) { InitializeComponent(); isTextValidating = false; refresh = new RefreshDelegate(this.Refresh); isInit = true; isInitStyleLibText = true; // saving the reference to the base mapObj // In certain cases we require to reload the modified symbolset on the base mapfile too. this.target = target; this.map = target; }
/// <summary> /// Event handled to edit a sub-object. /// </summary> /// <param name="sender">The source object of this event.</param> /// <param name="target">The object to be edited.</param> void editor_EditProperties(object sender, MapObjectHolder target) { try { MapPropertyEditorForm mapPropertyEditor = new MapPropertyEditorForm(target); mapPropertyEditor.HelpRequested += new HelpEventHandler(mapPropertyEditor_HelpRequested); mapPropertyEditor.ShowDialog(this); } catch (Exception ex) { MessageBox.Show(ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
/// <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); } }
public override void InitializeBinding(MapObjectHolder target) { this.target = target; if (target.GetParent().GetParent().GetType() != typeof(layerObj)) { this.Enabled = false; return; } layerObj layer = target.GetParent().GetParent(); styleObj style = target; if (itemList == null) { itemList = new ComboBox(); itemList.Width = targetControl.Width; itemList.Height = targetControl.Height; itemList.Location = targetControl.Location; itemList.DropDownStyle = ComboBoxStyle.DropDownList; itemList.SelectedIndexChanged += new EventHandler(itemList_SelectedIndexChanged); targetControl.Parent.Controls.Add(itemList); itemList.BringToFront(); Bitmap bmp = Resources.DataConnection; bmp.MakeTransparent(Color.Magenta); pbox = new PictureBox(); pbox.Image = bmp; pbox.SizeMode = PictureBoxSizeMode.AutoSize; pbox.Location = new System.Drawing.Point(targetControl.Location.X + targetControl.Width + 2, targetControl.Location.Y + (targetControl.Height - pbox.Image.Height) / 2); targetControl.Parent.Controls.Add(pbox); pbox.BringToFront(); } BindingState = false; itemList.Items.Clear(); layer.open(); for (int i = 0; i < layer.numitems; i++) { itemList.Items.Add(layer.getItem(i)); } if (layer.getResults() == null) { layer.close(); // close only is no query results } if (layer.connectiontype == MS_CONNECTION_TYPE.MS_OGR) { itemList.Items.Add("OGR:LabelFont"); itemList.Items.Add("OGR:LabelSize"); itemList.Items.Add("OGR:LabelText"); itemList.Items.Add("OGR:LabelAngle"); itemList.Items.Add("OGR:LabelFColor"); itemList.Items.Add("OGR:LabelBColor"); itemList.Items.Add("OGR:LabelPlacement"); itemList.Items.Add("OGR:LabelAnchor"); itemList.Items.Add("OGR:LabelDx"); itemList.Items.Add("OGR:LabelDy"); itemList.Items.Add("OGR:LabelPerp"); itemList.Items.Add("OGR:LabelBold"); itemList.Items.Add("OGR:LabelItalic"); itemList.Items.Add("OGR:LabelUnderline"); itemList.Items.Add("OGR:LabelPriority"); itemList.Items.Add("OGR:LabelStrikeout"); itemList.Items.Add("OGR:LabelStretch"); itemList.Items.Add("OGR:LabelAdjHor"); itemList.Items.Add("OGR:LabelAdjVert"); itemList.Items.Add("OGR:LabelHColor"); itemList.Items.Add("OGR:LabelOColor"); } string binding = style.getBinding((int)styleBinding); if (binding != null) { itemList.SelectedItem = binding; BindingState = true; } else { if (itemList.Items.Count > 0) { itemList.SelectedIndex = 0; } } }
/// <summary> /// ItemSelect 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_ItemSelect(object sender, MapObjectHolder target) { selectedItem = target; UpdateSample(target); }
/// <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> /// Applying the text contents based on the current map configuration /// </summary> public static void ApplyTextContents(string text) { map = mapscript.msLoadMapFromString(text, null); styles = new MapObjectHolder(map, null); }
/// <summary> /// Constructs a new MapPropertyEditorForm object. /// </summary> /// <param name="target">The target object to be edited.</param> public MapPropertyEditorForm(MapObjectHolder target) : this(target, null) { }
/// <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); }
public virtual void InitializeBinding(MapObjectHolder target) { }
/// <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)ViewModel.XmlProxyUrlResolver.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)ViewModel.XmlProxyUrlResolver.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", ViewModel.XmlProxyUrlResolver.ProxyType); cred = (NetworkCredential)ViewModel.XmlProxyUrlResolver.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", ViewModel.ServerVersion); if (!colorPickerLayerColor.Value.IsEmpty) { colorObj color = new colorObj(colorPickerLayerColor.Value.R, colorPickerLayerColor.Value.G, colorPickerLayerColor.Value.B, 255); 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); }