/// <summary> /// Have the editor to update the theme on the layer object. /// </summary> public void UpdateValues() { if (newLayer != null) { // remove the auto style from this layer layer.styleitem = null; while (layer.numclasses > 0) { layer.removeClass(layer.numclasses - 1); } for (int i = 0; i < newLayer.numclasses; i++) { classObj classobj = newLayer.getClass(i).clone(); // bindings are not supported with sample maps for (int s = 0; s < classobj.numstyles; s++) { StyleBindingController.RemoveAllBindings(classobj.getStyle(s)); } for (int l = 0; l < classobj.numlabels; l++) { LabelBindingController.RemoveAllBindings(classobj.getLabel(l)); } layer.insertClass(classobj, -1); } if (target != null) { target.RaisePropertyChanged(this); } } }
public void testRemoveClassObj() { mapObj map = new mapObj(mapfile); layerObj layer = map.getLayer(1); classObj newClass = new classObj(null); layer.insertClass(newClass, 0); layer.removeClass(0); map = null; layer = null; gc(); assert(newClass.refcount == 1, "testRemoveClassObj"); }
public void testInsertClassObj() { mapObj map = new mapObj(mapfile); layerObj layer = map.getLayer(1); classObj newClass = new classObj(null); layer.insertClass(newClass, -1); assertNotNull(newClass.layer, "testInsertClassObj precondition"); map = null; layer = null; gc(); assertNotNull(newClass.layer, "testInsertClassObj"); assert(newClass.refcount == 2, "testInsertClassObj refcount"); }
public void testInsertClassObjDestroy() { mapObj map = new mapObj(mapfile); layerObj layer = map.getLayer(1); classObj newClass = new classObj(null); layer.insertClass(newClass, 0); classObj reference = layer.getClass(0); assert(newClass.refcount == 3, "testInsertClassObjDestroy precondition"); newClass.Dispose(); // force the destruction for Mono on Windows because of the constructor overload map = null; layer = null; newClass = null; gc(); assert(reference.refcount == 2, "testInsertClassObjDestroy"); }
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> /// Create the theme according to the individual values of the layer contents /// </summary> private MapObjectHolder CreateLayerTheme() { if (layer == null) return null; int index; for (index = 0; index < fieldName.Length; index++) { if (fieldName[index] == comboBoxColumns.Text) break; } if (index == fieldName.Length) return null; NumberFormatInfo ni = new NumberFormatInfo(); ni.NumberDecimalSeparator = "."; mapObj map = target.GetParent(); // create a new map object mapObj newMap = new mapObj(null); newMap.units = MS_UNITS.MS_PIXELS; map.selectOutputFormat(map.imagetype); // copy symbolset for (int s = 1; s < map.symbolset.numsymbols; s++) { symbolObj origsym = map.symbolset.getSymbol(s); newMap.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym)); } // copy the fontset string key = null; while ((key = map.fontset.fonts.nextKey(key)) != null) newMap.fontset.fonts.set(key, map.fontset.fonts.get(key, "")); newLayer = new layerObj(newMap); newLayer.type = layer.type; newLayer.status = mapscript.MS_ON; newLayer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE; // add the classObj and styles classObj classobj; if (checkBoxKeepStyles.Checked) { classobj = layer.getClass(0).clone(); classobj.setExpression(""); // remove expression to have the class shown // bindings are not supported with sample maps for (int s = 0; s < classobj.numstyles; s++) StyleBindingController.RemoveAllBindings(classobj.getStyle(s)); for (int l = 0; l < classobj.numlabels; l++) LabelBindingController.RemoveAllBindings(classobj.getLabel(l)); newLayer.insertClass(classobj, -1); } else { classobj = new classObj(newLayer); classobj.name = MapUtils.GetClassName(newLayer); styleObj style = new styleObj(classobj); style.size = 8; // set default size (#4339) if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT) { // initialize with the default marker if specified in the symbol file for point symbols symbolObj symbol; for (int s = 0; s < map.symbolset.numsymbols; s++) { symbol = map.symbolset.getSymbol(s); if (symbol.name == "default-marker") { style.symbol = s; style.symbolname = "default-marker"; break; } } } MapUtils.SetDefaultColor(layer.type, style); } // calculate breaks int classes = (int)numericUpDownClasses.Value; double[] breaks = null; if (comboBoxMode.SelectedIndex == 0) breaks = CalculateEqualInterval(classes, index); if (breaks == null) return null; for (int i = 0; i < classes; i++) { double percent = ((double)(i + 1)) / classes * 100; // creating the corresponding class object if (i > 0) { classobj = classobj.clone(); // bindings are not supported with sample maps for (int s = 0; s < classobj.numstyles; s++) StyleBindingController.RemoveAllBindings(classobj.getStyle(s)); for (int l = 0; l < classobj.numlabels; l++) LabelBindingController.RemoveAllBindings(classobj.getLabel(l)); newLayer.insertClass(classobj, -1); } classobj.name = breaks[i].ToString(ni) + " - " + breaks[i + 1].ToString(ni); classobj.setExpression("(([" + comboBoxColumns.SelectedItem + "] >= " + breaks[i].ToString(ni) + ") && ([" + comboBoxColumns.SelectedItem + "] <= " + breaks[i+1].ToString(ni) + "))"); for (int j = 0; j < classobj.numstyles; j++) { styleObj style = classobj.getStyle(j); style.color = colorRampPickerColor.GetMapColorAtValue(percent); style.outlinecolor = colorRampPickerOutlineColor.GetMapColorAtValue(percent); style.backgroundcolor = colorRampPickerBackgroundColor.GetMapColorAtValue(percent); if (checkBoxFirstOnly.Checked) break; } } return new MapObjectHolder(newLayer, new MapObjectHolder(newMap, null)); }
/// <summary> /// Create the theme according to the individual values of the layer contents /// </summary> private MapObjectHolder CreateLayerTheme() { if (layer == null) { return(null); } mapObj map = target.GetParent(); // create a new map object mapObj newMap = new mapObj(null); newMap.units = MS_UNITS.MS_PIXELS; map.selectOutputFormat(map.imagetype); // copy symbolset for (int s = 1; s < map.symbolset.numsymbols; s++) { symbolObj origsym = map.symbolset.getSymbol(s); newMap.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym)); } // copy the fontset string key = null; while ((key = map.fontset.fonts.nextKey(key)) != null) { newMap.fontset.fonts.set(key, map.fontset.fonts.get(key, "")); } newLayer = new layerObj(newMap); newLayer.type = layer.type; newLayer.status = mapscript.MS_ON; newLayer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE; // add the classObj and styles classObj classobj; if (checkBoxKeepStyles.Checked) { classobj = layer.getClass(0).clone(); classobj.setExpression(""); // remove expression to have the class shown // bindings are not supported with sample maps for (int s = 0; s < classobj.numstyles; s++) { StyleBindingController.RemoveAllBindings(classobj.getStyle(s)); } for (int l = 0; l < classobj.numlabels; l++) { LabelBindingController.RemoveAllBindings(classobj.getLabel(l)); } newLayer.insertClass(classobj, -1); } else { classobj = new classObj(newLayer); classobj.name = MapUtils.GetClassName(newLayer); styleObj style = new styleObj(classobj); style.size = 8; // set default size (#4339) if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT) { // initialize with the default marker if specified in the symbol file for point symbols symbolObj symbol; for (int s = 0; s < map.symbolset.numsymbols; s++) { symbol = map.symbolset.getSymbol(s); if (symbol.name == "default-marker") { style.symbol = s; style.symbolname = "default-marker"; break; } } } MapUtils.SetDefaultColor(layer.type, style); } SortedDictionary <string, string> items = new SortedDictionary <string, string>(); int i = 0; shapeObj shape; layer.open(); layer.whichShapes(layer.getExtent()); if (checkBoxClassItem.Checked) { layer.classitem = comboBoxColumns.SelectedItem.ToString(); } while ((shape = layer.nextShape()) != null) { string value = shape.getValue(comboBoxColumns.SelectedIndex); if (checkBoxZero.Checked && (value == "" || value == "")) { continue; } if (!items.ContainsValue(value)) { if (i == 100) { if (MessageBox.Show("The number of the individual values is greater than 100 would you like to continue?", "MapManager", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel) { break; } } items.Add(value, value); ++i; } } if (layer.getResults() == null) { layer.close(); // close only is no query results } i = 0; foreach (string value in items.Keys) { double percent = ((double)(i + 1)) / items.Count * 100; // creating the corresponding class object if (i > 0) { classobj = classobj.clone(); // bindings are not supported with sample maps for (int s = 0; s < classobj.numstyles; s++) { StyleBindingController.RemoveAllBindings(classobj.getStyle(s)); } for (int l = 0; l < classobj.numlabels; l++) { LabelBindingController.RemoveAllBindings(classobj.getLabel(l)); } newLayer.insertClass(classobj, -1); } classobj.name = value; if (checkBoxClassItem.Checked) { classobj.setExpression(value); } else { classobj.setExpression("('[" + comboBoxColumns.SelectedItem + "]' = '" + value + "')"); } for (int j = 0; j < classobj.numstyles; j++) { styleObj style = classobj.getStyle(j); style.color = colorRampPickerColor.GetMapColorAtValue(percent); style.outlinecolor = colorRampPickerOutlineColor.GetMapColorAtValue(percent); style.backgroundcolor = colorRampPickerBackgroundColor.GetMapColorAtValue(percent); if (checkBoxFirstOnly.Checked) { break; } } ++i; } return(new MapObjectHolder(newLayer, new MapObjectHolder(newMap, null))); }
/// <summary> /// Create the theme according to the individual values of the layer contents /// </summary> private MapObjectHolder CreateLayerTheme() { if (layer == null) return null; mapObj map = target.GetParent(); // create a new map object mapObj newMap = new mapObj(null); newMap.units = MS_UNITS.MS_PIXELS; map.selectOutputFormat(map.imagetype); // copy symbolset for (int s = 1; s < map.symbolset.numsymbols; s++) { symbolObj origsym = map.symbolset.getSymbol(s); newMap.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym)); } // copy the fontset string key = null; while ((key = map.fontset.fonts.nextKey(key)) != null) newMap.fontset.fonts.set(key, map.fontset.fonts.get(key, "")); newLayer = new layerObj(newMap); newLayer.type = layer.type; newLayer.status = mapscript.MS_ON; newLayer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE; // add the classObj and styles classObj classobj; if (checkBoxKeepStyles.Checked) { classobj = layer.getClass(0).clone(); classobj.setExpression(""); // remove expression to have the class shown // bindings are not supported with sample maps for (int s = 0; s < classobj.numstyles; s++) StyleBindingController.RemoveAllBindings(classobj.getStyle(s)); for (int l = 0; l < classobj.numlabels; l++) LabelBindingController.RemoveAllBindings(classobj.getLabel(l)); newLayer.insertClass(classobj, -1); } else { classobj = new classObj(newLayer); classobj.name = MapUtils.GetClassName(newLayer); styleObj style = new styleObj(classobj); style.size = 8; // set default size (#4339) if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT) { // initialize with the default marker if specified in the symbol file for point symbols symbolObj symbol; for (int s = 0; s < map.symbolset.numsymbols; s++) { symbol = map.symbolset.getSymbol(s); if (symbol.name == "default-marker") { style.symbol = s; style.symbolname = "default-marker"; break; } } } MapUtils.SetDefaultColor(layer.type, style); } SortedDictionary<string,string> items = new SortedDictionary<string,string>(); int i = 0; shapeObj shape; layer.open(); layer.whichShapes(layer.getExtent()); while ((shape = layer.nextShape()) != null) { string value = shape.getValue(comboBoxColumns.SelectedIndex); if (checkBoxZero.Checked && (value == "" || value == "")) continue; if (!items.ContainsValue(value)) { if (i == 100) { if (MessageBox.Show("The number of the individual values is greater than 100 would you like to continue?","MapManager", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel) { break; } } items.Add(value, value); ++i; } } if (layer.getResults() == null) layer.close(); // close only is no query results i = 0; foreach (string value in items.Keys) { double percent = ((double)(i + 1)) / items.Count * 100; // creating the corresponding class object if (i > 0) { classobj = classobj.clone(); // bindings are not supported with sample maps for (int s = 0; s < classobj.numstyles; s++) StyleBindingController.RemoveAllBindings(classobj.getStyle(s)); for (int l = 0; l < classobj.numlabels; l++) LabelBindingController.RemoveAllBindings(classobj.getLabel(l)); newLayer.insertClass(classobj, -1); } classobj.name = value; classobj.setExpression("('[" + comboBoxColumns.SelectedItem + "]' = '" + value + "')"); for (int j = 0; j < classobj.numstyles; j++) { styleObj style = classobj.getStyle(j); style.color = colorRampPickerColor.GetMapColorAtValue(percent); style.outlinecolor = colorRampPickerOutlineColor.GetMapColorAtValue(percent); style.backgroundcolor = colorRampPickerBackgroundColor.GetMapColorAtValue(percent); if (checkBoxFirstOnly.Checked) break; } ++i; } return new MapObjectHolder(newLayer, new MapObjectHolder(newMap, null)); }
/// <summary> /// Create the theme according to the individual values of the layer contents /// </summary> private MapObjectHolder CreateLayerTheme() { if (layer == null) { return(null); } int index; for (index = 0; index < fieldName.Length; index++) { if (fieldName[index] == comboBoxColumns.Text) { break; } } if (index == fieldName.Length) { return(null); } NumberFormatInfo ni = new NumberFormatInfo(); ni.NumberDecimalSeparator = "."; mapObj map = target.GetParent(); // create a new map object mapObj newMap = new mapObj(null); newMap.units = MS_UNITS.MS_PIXELS; map.selectOutputFormat(map.imagetype); // copy symbolset for (int s = 1; s < map.symbolset.numsymbols; s++) { symbolObj origsym = map.symbolset.getSymbol(s); newMap.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym)); } // copy the fontset string key = null; while ((key = map.fontset.fonts.nextKey(key)) != null) { newMap.fontset.fonts.set(key, map.fontset.fonts.get(key, "")); } newLayer = new layerObj(newMap); newLayer.type = layer.type; newLayer.status = mapscript.MS_ON; newLayer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE; // add the classObj and styles classObj classobj; if (checkBoxKeepStyles.Checked) { classobj = layer.getClass(0).clone(); classobj.setExpression(""); // remove expression to have the class shown // bindings are not supported with sample maps for (int s = 0; s < classobj.numstyles; s++) { StyleBindingController.RemoveAllBindings(classobj.getStyle(s)); } for (int l = 0; l < classobj.numlabels; l++) { LabelBindingController.RemoveAllBindings(classobj.getLabel(l)); } newLayer.insertClass(classobj, -1); } else { classobj = new classObj(newLayer); classobj.name = MapUtils.GetClassName(newLayer); styleObj style = new styleObj(classobj); style.size = 8; // set default size (#4339) if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT) { // initialize with the default marker if specified in the symbol file for point symbols symbolObj symbol; for (int s = 0; s < map.symbolset.numsymbols; s++) { symbol = map.symbolset.getSymbol(s); if (symbol.name == "default-marker") { style.symbol = s; style.symbolname = "default-marker"; break; } } } MapUtils.SetDefaultColor(layer.type, style); } // calculate breaks int classes = (int)numericUpDownClasses.Value; double[] breaks = null; if (comboBoxMode.SelectedIndex == 0) { breaks = CalculateEqualInterval(classes, index); } if (breaks == null) { return(null); } for (int i = 0; i < classes; i++) { double percent = ((double)(i + 1)) / classes * 100; // creating the corresponding class object if (i > 0) { classobj = classobj.clone(); // bindings are not supported with sample maps for (int s = 0; s < classobj.numstyles; s++) { StyleBindingController.RemoveAllBindings(classobj.getStyle(s)); } for (int l = 0; l < classobj.numlabels; l++) { LabelBindingController.RemoveAllBindings(classobj.getLabel(l)); } newLayer.insertClass(classobj, -1); } classobj.name = breaks[i].ToString(ni) + " - " + breaks[i + 1].ToString(ni); classobj.setExpression("(([" + comboBoxColumns.SelectedItem + "] >= " + breaks[i].ToString(ni) + ") && ([" + comboBoxColumns.SelectedItem + "] <= " + breaks[i + 1].ToString(ni) + "))"); for (int j = 0; j < classobj.numstyles; j++) { styleObj style = classobj.getStyle(j); style.color = colorRampPickerColor.GetMapColorAtValue(percent); style.outlinecolor = colorRampPickerOutlineColor.GetMapColorAtValue(percent); style.backgroundcolor = colorRampPickerBackgroundColor.GetMapColorAtValue(percent); if (checkBoxFirstOnly.Checked) { break; } } } return(new MapObjectHolder(newLayer, new MapObjectHolder(newMap, null))); }