//for example:use layer.clone() public SymbolSelectorDialog(layerObj layer) { InitializeComponent(); if (layer != null) { m_pCurrentLayer = layer; m_pCurrentClass = layer.getClass(0); m_pEditingClass = m_pCurrentClass.clone(); m_LayerType = layer.type; } }
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); } } } } }
/// <summary> /// Refresh the control according to the underlying object. /// </summary> public void RefreshView() { if (map != null) { symbolObj symbol; string selectedSymbol = style.symbolname; int selected = style.symbol; MS_LAYER_TYPE layerType = layer.type; ListViewItem selectedItem = null; int itemIndex = 0; for (int i = 0; i < map.symbolset.numsymbols; i++) { symbol = map.symbolset.getSymbol(i); if (symbol.name == null) { symbol.name = "Symbol" + i; } if ((MS_SYMBOL_TYPE)symbol.type == MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE) { // looking up the referred font file and skip if not exists string fontFile = map.fontset.fonts.get(symbol.font, null); if (fontFile == null) { continue; } if (!File.Exists(fontFile)) { continue; } } else if ((MS_SYMBOL_TYPE)symbol.type == MS_SYMBOL_TYPE.MS_SYMBOL_PIXMAP) { // looking up the referred image file and skip if not exists if (symbol.imagepath == null) { continue; } if (!File.Exists(map.mappath + symbol.imagepath)) { continue; } } // pre-filter mapinfo auto styles if (symbol.name.StartsWith("mapinfo-brush") && layerType != MS_LAYER_TYPE.MS_LAYER_POLYGON) { continue; } if (symbol.name.StartsWith("mapinfo-pen") && layerType != MS_LAYER_TYPE.MS_LAYER_LINE) { continue; } if (i == 0) { style.symbol = 0; style.symbolname = null; if (selected == i && listView.Items.Count == itemIndex) { selectedItem = SetSymbolItem("(default)", itemIndex); } else { SetSymbolItem("(default)", itemIndex); } } else { style.symbol = i; style.symbolname = symbol.name; if ((selected == i || string.Compare(selectedSymbol, symbol.name) == 0) && listView.Items.Count == itemIndex) { selectedItem = SetSymbolItem(symbol.name, itemIndex); } else { SetSymbolItem(symbol.name, itemIndex); } } ++itemIndex; } listView.LargeImageList = imageList; listViewPreview.LargeImageList = imageList; if (selectedItem != null) { selectedItem.Selected = true; selectedItem.EnsureVisible(); } this.listView.Refresh(); UpdatePreview(); } SetDirty(false); }
/// <summary> /// Get default color color. /// </summary> /// <returns>The default color</returns> public static void SetDefaultColor(MS_LAYER_TYPE type, styleObj style) { // set default color (#4337) to black for line color and white for brush color if (type == MS_LAYER_TYPE.MS_LAYER_POLYGON) { style.color = new colorObj(255, 255, 255, 0); style.outlinecolor = new colorObj(0, 0, 0, 0); style.symbol = 0; style.symbolname = null; } else { style.color = new colorObj(0, 0, 0, 0); } }