/// <summary> /// Let the editor to update the modified values to the underlying object. /// </summary> public void UpdateValues() { if (map == null) { return; } if (listView.SelectedItems.Count > 0) { styleObj style = target; mapObj map2; if (target.GetParent().GetType() == typeof(labelObj)) { map2 = target.GetParent().GetParent().GetParent().GetParent(); } else { map2 = target.GetParent().GetParent().GetParent(); } string symbolName = (string)listView.SelectedItems[0].Tag; if (symbolName == "(default)") { style.symbol = 0; style.symbolname = null; } else { style.setSymbolByName(map2, symbolName); } } }
/// <summary> /// Update the style object according to the current Editor state. /// </summary> /// <param name="style">The object to be updated.</param> private void Update(styleObj style) { // general tab style.size = double.Parse(textBoxSize.Text); style.width = double.Parse(textBoxWidth.Text); style.angle = double.Parse(textBoxAngle.Text); // display tab this.colorPickerColor.ApplyTo(style.color); this.colorPickerBackColor.ApplyTo(style.backgroundcolor); this.colorPickerOutlineColor.ApplyTo(style.outlinecolor); style.gap = double.Parse(textBoxGap.Text); string[] values = textBoxPattern.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (values.Length > 0) { double[] result = new double[values.Length]; for (int i = 0; i < values.Length; i++) result[i] = double.Parse(values[i], ni); style.pattern = result; } else style.patternlength = 0; if (comboBoxSymbol.SelectedIndex > 0) style.setSymbolByName(map, comboBoxSymbol.SelectedItem.ToString()); else { // no symbol selected style.symbol = 0; style.symbolname = null; } }
public static void ExpandFontStyles() { string symbolSetFileContents = File.ReadAllText(symbolsetFileName); string fontSetFileContents = File.ReadAllText(fontsetFileName); StringBuilder newSymbols = new StringBuilder(); StringBuilder newFonts = new StringBuilder(); for (int i = 0; i < map.numlayers; i++) { layerObj layer = map.getLayer(i); if (MapUtils.HasMetadata(layer, "character-count")) { string charcount = layer.getMetaData("character-count"); int num; if (layer.numclasses == 1 && charcount != null && int.TryParse(charcount, out num)) { classObj classobj = layer.getClass(0); if (!fontSetFileContents.Contains(classobj.name)) { throw new Exception("Invalid font reference in mmstyles.map: " + classobj.name + ". The fontset file should contain an entry for this font name."); } for (int c = 33; c < 33 + num; c++) { string symbolname = classobj.name + "-" + c.ToString(); if (!symbolSetFileContents.Contains(symbolname)) { symbolObj sym = new symbolObj(symbolname, null); sym.character = "&#" + c.ToString() + ";"; sym.antialias = mapscript.MS_TRUE; sym.type = (int)MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE; sym.font = classobj.name; sym.inmapfile = 0; map.symbolset.appendSymbol(sym); newSymbols.Append(String.Format("SYMBOL{0} NAME \"{1}\"{0} TYPE TRUETYPE{0} ANTIALIAS TRUE{0} CHARACTER \"{2}\"{0} FONT \"{3}\"{0}END{0}", Environment.NewLine, symbolname, sym.character, sym.font)); } if (c > 33) { // the first class is already inserted classObj class2 = classobj.clone(); class2.name = symbolname; styleObj style2 = class2.getStyle(0); style2.setSymbolByName(map, symbolname); layer.insertClass(class2, -1); } else { styleObj style2 = classobj.getStyle(0); style2.setSymbolByName(map, symbolname); } } if (!classobj.name.EndsWith("-33")) { classobj.name += "-33"; } } layer.removeMetaData("character-count"); } } if (newSymbols.Length > 0) { // writing the new symbols to the symbolset file int lastpos = symbolSetFileContents.LastIndexOf("END", StringComparison.InvariantCultureIgnoreCase); symbolSetFileContents = symbolSetFileContents.Substring(0, lastpos) + newSymbols.ToString() + "END"; File.WriteAllText(symbolsetFileName, symbolSetFileContents); } if (newFonts.Length > 0) { // writing the new fonts to the fontset file File.WriteAllText(fontsetFileName, fontSetFileContents + newFonts.ToString()); } }
private void UpdateStyleList() { string selectedName = style.symbolname; if (listView.SelectedItems.Count > 0) { selectedName = listView.SelectedItems[0].Text; } // populate the style listview listView.Items.Clear(); imageList.Images.Clear(); ListViewItem selected = null; if (comboBoxCategory.Text != "") { // Create "no symbol" entry styleObj nosymbolstyle = new styleObj(null); MapUtils.SetDefaultColor(layer.type, nosymbolstyle); ListViewItem nosymbolitem = AddListItem(nosymbolstyle, layer, "Default"); if (selectedName == null) { selected = nosymbolitem; } if (comboBoxCategory.Text == "Inline Symbols") { for (int i = 0; i < map.symbolset.numsymbols; i++) { symbolObj symbol = map.symbolset.getSymbol(i); if (symbol.inmapfile == mapscript.MS_TRUE && !StyleLibrary.HasSymbol(symbol.name)) { styleObj libstyle = new styleObj(null); //if (symbol.type == (int)MS_SYMBOL_TYPE.MS_SYMBOL_PATTERNMAP) // MapUtils.SetDefaultColor(MS_LAYER_TYPE.MS_LAYER_LINE, libstyle); //else MapUtils.SetDefaultColor(layer.type, libstyle); libstyle.setSymbolByName(map, symbol.name); libstyle.size = 8; MS_LAYER_TYPE type = layer.type; try { //STEPH: change layer passed to the list view to be consistent with the other symbol categories //so that it uses a point layer to display the style in the list layer.type = MS_LAYER_TYPE.MS_LAYER_POINT; ListViewItem item = AddListItem(libstyle, layer, symbol.name); if (selectedName == item.Text) { selected = item; } } finally { layer.type = type; } } } } else { // collect all fonts specified in the fontset file Hashtable fonts = new Hashtable(); string key = null; while ((key = map.fontset.fonts.nextKey(key)) != null) { fonts.Add(key, key); } mapObj styles = StyleLibrary.Styles; layerObj stylelayer = styles.getLayerByName(comboBoxCategory.Text); for (int i = 0; i < stylelayer.numclasses; i++) { classObj classobj = stylelayer.getClass(i); int symbolIndex = classobj.getStyle(0).symbol; if (symbolIndex >= 0) { string font = styles.symbolset.getSymbol(symbolIndex).font; if (font != null && !fonts.ContainsKey(font)) { continue; // this font cannot be found in fontset } } ListViewItem item = AddListItem(classobj.getStyle(0), stylelayer, classobj.name); if (selectedName == item.Text) { selected = item; } } } } if (selected != null) { selected.Selected = true; selected.EnsureVisible(); } }
private void UpdatePreview() { if (style != null && enablePreview) { styleObj pstyle = style.clone(); Update(pstyle); // apply current settings (opacity) to colors colorPickerColor.SetColor(pstyle.color); colorPickerBackColor.SetColor(pstyle.backgroundcolor); colorPickerOutlineColor.SetColor(pstyle.outlinecolor); // select the proper map containing symbols mapObj stylemap = map; if (listView.SelectedItems.Count > 0 && listView.SelectedItems[0].Text != "Default") { if (comboBoxCategory.Text != "Inline Symbols") { stylemap = StyleLibrary.Styles; } styleObj classStyle = (styleObj)listView.SelectedItems[0].Tag; pstyle.setSymbolByName(stylemap, classStyle.symbolname); } else { pstyle.symbol = 0; pstyle.symbolname = null; } classObj styleclass = new classObj(null); styleclass.insertStyle(pstyle, -1); using (classObj def_class = new classObj(null)) // for drawing legend images { using (imageObj image2 = def_class.createLegendIcon( stylemap, layer, pictureBoxSample.Width, pictureBoxSample.Height)) { MS_LAYER_TYPE type = layer.type; try { // modify the layer type in certain cases for drawing correct images if (comboBoxGeomTransform.Text.ToLower().Contains("labelpoly")) { layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON; } else if (comboBoxGeomTransform.Text.ToLower().Contains("labelpnt") || comboBoxGeomTransform.Text.ToLower().Contains("centroid")) { layer.type = MS_LAYER_TYPE.MS_LAYER_POINT; } styleclass.drawLegendIcon(stylemap, layer, pictureBoxSample.Width - 10, pictureBoxSample.Height - 10, image2, 4, 4); } finally { layer.type = type; } byte[] img = image2.getBytes(); using (MemoryStream ms = new MemoryStream(img)) { pictureBoxSample.Image = Image.FromStream(ms); } } } } }
private void UpdateStyleList() { string selectedName = style.symbolname; if (listView.SelectedItems.Count > 0) selectedName = listView.SelectedItems[0].Text; // populate the style listview listView.Items.Clear(); imageList.Images.Clear(); ListViewItem selected = null; if (comboBoxCategory.Text != "") { // Create "no symbol" entry styleObj nosymbolstyle = new styleObj(null); MapUtils.SetDefaultColor(layer.type, nosymbolstyle); ListViewItem nosymbolitem = AddListItem(nosymbolstyle, layer, "Default"); if (selectedName == null) selected = nosymbolitem; if (comboBoxCategory.Text == "Inline Symbols") { for (int i = 0; i < map.symbolset.numsymbols; i++) { symbolObj symbol = map.symbolset.getSymbol(i); if (symbol.inmapfile == mapscript.MS_TRUE && !StyleLibrary.HasSymbol(symbol.name)) { styleObj libstyle = new styleObj(null); //if (symbol.type == (int)MS_SYMBOL_TYPE.MS_SYMBOL_PATTERNMAP) // MapUtils.SetDefaultColor(MS_LAYER_TYPE.MS_LAYER_LINE, libstyle); //else MapUtils.SetDefaultColor(layer.type, libstyle); libstyle.setSymbolByName(map, symbol.name); libstyle.size = 8; MS_LAYER_TYPE type = layer.type; try { //STEPH: change layer passed to the list view to be consistent with the other symbol categories //so that it uses a point layer to display the style in the list layer.type = MS_LAYER_TYPE.MS_LAYER_POINT; ListViewItem item = AddListItem(libstyle, layer, symbol.name); if (selectedName == item.Text) selected = item; } finally { layer.type = type; } } } } else { // collect all fonts specified in the fontset file Hashtable fonts = new Hashtable(); string key = null; while ((key = map.fontset.fonts.nextKey(key)) != null) fonts.Add(key, key); mapObj styles = StyleLibrary.Styles; layerObj stylelayer = styles.getLayerByName(comboBoxCategory.Text); for (int i = 0; i < stylelayer.numclasses; i++) { classObj classobj = stylelayer.getClass(i); int symbolIndex = classobj.getStyle(0).symbol; if (symbolIndex >= 0) { string font = styles.symbolset.getSymbol(symbolIndex).font; if (font != null && !fonts.ContainsKey(font)) continue; // this font cannot be found in fontset } ListViewItem item = AddListItem(classobj.getStyle(0), stylelayer, classobj.name); if (selectedName == item.Text) selected = item; } } } if (selected != null) { selected.Selected = true; selected.EnsureVisible(); } }
private void listViewSymbol_SelectedIndexChanged(object sender, EventArgs e) { if (m_pDefaultMap == null) return; if (listViewSymbol.SelectedIndices.Count == 0) return; //make sure there is only one style in class while (m_pEditingClass.numstyles > 1) m_pEditingClass.removeStyle(0); //index 0 is the orienge symbol if(listViewSymbol.SelectedIndices[0] == 0) { pictureBoxPreview.Image = GetImageFromClass(m_pCurrentLayer.getClass(m_iClassIndex) , pictureBoxPreview.Width, pictureBoxPreview.Height); } else { if (m_pEditingClass != null) m_pEditingClass.Dispose(); m_pEditingClass = new classObj(null); styleObj pStyle = new styleObj(m_pEditingClass); pStyle.setSymbolByName(m_pDefaultMap, listViewSymbol.SelectedItems[0].Text); pStyle.color = new colorObj(0, 0, 0, 0); if (m_LayerType == MS_LAYER_TYPE.MS_LAYER_POINT) { pStyle.size = 10; pStyle.angle = 0; } else if (m_LayerType == MS_LAYER_TYPE.MS_LAYER_LINE) { pStyle.size = 8; pStyle.width = 1; } else if (m_LayerType == MS_LAYER_TYPE.MS_LAYER_POLYGON) { pStyle.size = 8; pStyle.outlinewidth = 1; pStyle.outlinecolor = new colorObj(0, 0, 0, 0); } if (m_pSymbolOptions != null) m_pSymbolOptions.Symbol = pStyle; DrawSymbol2Preview(); } }
/// <summary> /// Update the style object according to the current Editor state. /// </summary> /// <param name="style">The object to be updated.</param> private void Update(styleObj style) { // general tab style.size = double.Parse(textBoxSize.Text); style.width = double.Parse(textBoxWidth.Text); style.angle = double.Parse(textBoxAngle.Text); // display tab this.colorPickerColor.ApplyTo(style.color); this.colorPickerBackColor.ApplyTo(style.backgroundcolor); this.colorPickerOutlineColor.ApplyTo(style.outlinecolor); style.gap = double.Parse(textBoxGap.Text); string[] values = textBoxPattern.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (values.Length > 0) { double[] result = new double[values.Length]; for (int i = 0; i < values.Length; i++) result[i] = double.Parse(values[i], ni); style.pattern = result; } else style.patternlength = 0; if (comboBoxSymbol.SelectedIndex > 0) style.setSymbolByName(map, comboBoxSymbol.SelectedItem.ToString()); else { // no symbol selected style.symbol = 0; style.symbolname = null; } }