//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; } }
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()); } }
/// <summary> /// struction function /// </summary> /// <param name="layer"></param> /// <param name="index">there are more than 1 classes in layerobj, /// use index to specify which class to use</param> public SymbolSelectorDialog(layerObj layer, classObj inClass) : this(layer) { m_pCurrentClass = inClass; m_pEditingClass = m_pCurrentClass.clone(); }