注:此问题出现在MapXtreme 2004 6.2 中,经测试发现MapXtreme 2008 已修正此问题
下面的代码执行后并不能实现对“评价井”样式的修改:
// 打开 TAB 文件
Table t = MapInfo.Engine.Session.Current.Catalog.OpenTable(Application.StartupPath + @"/井.TAB");
FeatureLayer fl = new FeatureLayer(t);
mapControl1.Map.Layers.Add(fl);
// 创建单值主题
IndividualValueTheme ivt = new IndividualValueTheme(fl, "WELLTYPE", null);
for(int i = 0; i < ivt.Bins.Count; i ++)
{
if(ivt.Bins[i].Value.ToString() == "评价井")
{
// 对评价井进行修改样式
MapInfo.Styles.Font f = new MapInfo.Styles.Font("MapInfo Oil&Gas", 12);
short jingCode = 37;
FontPointStyle fps = new FontPointStyle(jingCode, f, 0, Color.Red, 12);
ivt.Bins[i].Style = new CompositeStyle(fps);
}
}
fl.Modifiers.Clear();
fl.Modifiers.Insert(0, ivt);
但这段代码在 MapXtreme 2008 下却可以正确的完成修改样式的功能。若想不升级 MapXtreme 而达到预期的效果,我们需要创建中间表,如下所示:
MapInfo.Data.SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchAll();
si.QueryDefinition.Columns = null;
IResultSetFeatureCollection rsfc = MapInfo.Engine.Session.Current.Catalog.Search("NOD10001", si);
// 创建一个“井.TAB” 的复本
TableInfo ti = TableInfoFactory.CreateFromFeatureCollection("tempNod10001", TableType.MemTable, rsfc);
Table tempTable = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
tempTable.InsertFeatures(rsfc);
tempLayer = new FeatureLayer(tempTable);
mapControl1.Map.Layers.Add(tempLayer);
// 对临时的复本图层应用主题
IndividualValueTheme ivt = new IndividualValueTheme(fl, "WELLTYPE", null);
for(int i = 0; i < ivt.Bins.Count; i ++)
{
if(ivt.Bins[i].Value.ToString() == "评价井")
{
// 对评价井进行修改样式
MapInfo.Styles.Font f = new MapInfo.Styles.Font("MapInfo Oil&Gas", 12);
short jingCode = 37;
FontPointStyle fps = new FontPointStyle(jingCode, f, 0, Color.Red, 12);
ivt.Bins[i].Style = new CompositeStyle(fps);
}
}
tempLayer.Modifiers.Clear();
tempLayer.Modifiers.Insert(0, ivt);