关闭

重写FeatureStyleModifier实现更新一个图层中指定的几个图元的样式

1397人阅读 评论(3) 收藏 举报

重写FeatureStyleModifier


using System;
using MapInfo.Styles;

namespace GIS.MapInfoModify
{
/// <summary>
/// SelectedPointModifier 的摘要说明。
/// 重写FeatureStyleModifier,可以通过SelectedPointModifier,来修改单个的或是多个选中的点图元
/// </summary>
internal class SelectedPointModifier:MapInfo.Mapping. {
private BasePointStyle _pointStyle;
private System.Collections.Hashtable features;
/// <summary>
/// 重写FeatureStyleModifier,实现对图层中单个或是多个图元的样式的修改
/// </summary>
/// <param name="name">样式的名称</param>
/// <param name="alias">样式别名</param>
/// <param name="dSelection">要修改样式的集合</param>
/// <param name="layerAlias">图层别名</param>
// /// <param name="PointStyle">想使选中的点显示的样式</param>
public SelectedPointModifier(string name, string alias, MapInfo.Engine.Selection dSelection, string layerAlias): base(name, alias)
{
// this._pointStyle=PointStyle;
features = new System.Collections.Hashtable();
string[] exp = new string[]{"MI_Key"};
this.Expressions = exp;
foreach(MapInfo.Data.IResultSetFeatureCollection irfc in dSelection)
{
// Only save the selected features from the layer to apply the modifier too.
// The DefaultSelection could have features from several layers.

if(irfc.BaseTable.Alias == layerAlias)
{
foreach(MapInfo.Data.Feature f in irfc)
{
features.Add(f.Key.Value, f.Key.Value);
}
}
}
}
protected override bool Modify(MapInfo.Styles.FeatureStyleStack styles, object[] values)
{
MapInfo.Styles.CompositeStyle cs = styles.Current;
if (features.Contains((values[0] as MapInfo.Data.Key).Value))
{
// Set the style for region features because the modifier is being applied to a region layer.
// BitmapPointStyle vs=new BitmapPointStyle("PINB-64.BMP");
// (vs.PointSize=20;
//cs = new CompositeStyle(null, null, null, vs);
// cs.SymbolStyle=this._pointStyle;
cs.SymbolStyle.PointSize=20;
//(cs.AreaStyle.Interior as MapInfo.Styles.SimpleInterior).ForeColor = System.Drawing.Color.Orange;
//(cs.AreaStyle.Border as MapInfo.Styles.SimpleLineStyle).Color = System.Drawing.Color.RoyalBlue;
//(cs.AreaStyle.Border as MapInfo.Styles.SimpleLineStyle).Width = new MapInfo.Styles.LineWidth(3, MapInfo.Styles.LineWidthUnit.Pixel);

return true;
}
return false;
}
}
}
下面是调用

#region 高亮显示选中的图元通过改变其样式
private void ShowShi(string LayerName)
{
MapInfo.Mapping.FeatureLayer fl = this.mapControl1.Map.Layers[LayerName] as MapInfo.Mapping.FeatureLayer;
//The FeatureLayer can be any Region layer desired to change
//其中只是改变选中的图元的大小来表示闪烁
if(fl!=null)
{
string ModifierName=LayerName+"Modifier";
SelectedPointModifier scm = new SelectedPointModifier(ModifierName, ModifierName, MapInfo.Engine.Session.Current.Selections.DefaultSelection, fl.Alias);
int ModifiCount=fl.Modifiers.Count;
if(ModifiCount!=0)
{
fl.Modifiers.Remove(ModifierName);
this.ShanCi++;
}
else
{
fl.Modifiers.Append(scm);
this.ShanCi++;
}
if(this.ShanCi%6==0)//闪几次就不再闪
{
this.timerSelect.Enabled=false;
this._shanShuoLayerName=null;
this.ShanCi=0;
}

}
}
 

————————————————————————————————————————————————

左懿代码一

foreach(Feature ftr in fc)
{
MapInfo.Data.MIConnection connection = new MapInfo.Data.MIConnection();
connection.Open();

MapInfo.Data.MICommand command = connection.CreateCommand();
command.CommandText = "update " + ftr.Table.Alias + " set obj = @obj,MI_Style=@style where MI_Key = @MIKEY";
command.Parameters.Add("@obj", ftr.Geometry );
command.Parameters.Add("@MIKEY", ftr.Key);
command.Parameters.Add("@style",cs);
command.ExecuteNonQuery();

command.Dispose();
connection.Close();
connection.Dispose();

ftr.Update();
}

——————————————————————————————————————————————

左懿代码二

string tempLayerName = "tempStreet";
MapInfo.Data.Table newTable = CreateTempLayer(tempLayerName);

//MapInfo.Data.Table newTable = MapInfo.Engine.Session.Current.Catalog.OpenTable(tempLayerName);

MapInfo.Data.MIConnection connection = new MapInfo.Data.MIConnection();
connection.Open();

MapInfo.Data.MICommand command = connection.CreateCommand();

command.CommandText = "delete "+tempLayerName ;
command.Prepare();
command.ExecuteNonQuery();

command.CommandText = "Insert into "+tempLayerName + " Select * from street where MI_Key = @MIKEY";
command.Parameters.Add("@MIKEY", ftr.Key);
command.Prepare();
command.ExecuteNonQuery();

command.Dispose();
connection.Close();

(mapControl.Map.Layers[tempLayerName] as FeatureLayer).Modifiers.Clear();
MapInfo.Mapping.FeatureOverrideStyleModifier fsmtemp = new MapInfo.Mapping.FeatureOverrideStyleModifier(null,cs);
(mapControl.Map.Layers[tempLayerName] as FeatureLayer).Modifiers.Append(fsmtemp);

——————————————————————————————————————————————

C/S下替换图片

Feature feature=this.FindFeature(this.tableName,"siteId","4");

((BitmapPointStyle)feature.Style).Name="TRUC-64";
feature.Update();

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:316931次
    • 积分:4158
    • 等级:
    • 排名:第7427名
    • 原创:50篇
    • 转载:203篇
    • 译文:0篇
    • 评论:77条
    最新评论
    自己收藏的网站