

<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> /**//// <summary>
/// 数据提供接口,定义了获取数据的基本方法
/// </summary>
public interface IDataProvider
{
/**//// <summary>
/// 获取所有数据主方法
/// </summary>
/// <returns>获取到的实体列表</returns>
List<AbstractEntity> GetData ();
}


<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> /**//// <summary>
/// 地图横向坐标X(经度)
/// </summary>
public double X
{
get
{
return this._x;
}
set
{
this._x = value;
}
}
/**//// <summary>
/// 地图纵向坐标Y(纬度)
/// </summary>
public double Y
{
get
{
return this._y;
}
set
{
this._y = value;
}
}
然后就是定义一大堆抽象方法了:


<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> /**//// <summary>
/// 获取该子类实例化在地图上的显示样式
/// </summary>
/// <returns></returns>
public abstract CompositeStyle GetMapStyle ();
/**//// <summary>
/// 获取该子类实例在地图上显示的图元形状
/// </summary>
/// <param name="coordSys"></param>
/// <returns></returns>
public abstract FeatureGeometry GetFeature ( CoordSys coordSys );
/**//// <summary>
/// 构造该子类在地图表中的自定义字段
/// </summary>
/// <remarks>
/// 不应包含X、Y、Key字段
/// 字段名“MI_Geometry”和“MI_Style”和“MI_Key”为保留字段名
/// </remarks>
/// <returns>自定义列列表</returns>
public abstract List<Column> CreateCustomColumn ();
/**//// <summary>
/// 填充Command对象中Parameters的值。只需填充除父类外的自定义属性
/// </summary>
/// <remarks>该方法只允许被父类调用</remarks>
/// <param name="command">MICommand对象引用</param>
protected abstract void FillCommand ( ref MICommand command );
/**//// <summary>
/// 构造该子类在地图上显示的标注图层
/// </summary>
/// <returns>如不需显示标注图层,返回NULL</returns>
public abstract IMapLayer CreateLabelLayer ();
/**//// <summary>
/// 获取该子类在地图数据表表名
/// </summary>
/// <returns></returns>
public abstract string GetTableName ();
/**//// <summary>
/// 获取子类在地图上图层的名称
/// </summary>
/// <returns>数据在图层上的名称</returns>
public abstract string GetLayerName ();
/**//// <summary>
/// 获取该实体的唯一标识
/// </summary>
/// <returns></returns>
public abstract string GetKey ();
/**//// <summary>
/// 构造该图形被点击后在地图上弹出的附加控件
/// </summary>
/// <param name="key">被点击图形的唯一标识,该标识由Entity中GetKey获取</param>
/// <returns></returns>
public abstract System.Windows.Forms.Control SelectionTips(string key);


<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> public override MapInfo.Styles.CompositeStyle GetMapStyle ()
{
Color cc = Color.FromArgb(200, GetValueColor(this.Value));
SimpleInterior siStyle = new SimpleInterior(2, cc);
SimpleLineStyle lineStyle = new SimpleLineStyle ( new LineWidth () );
AreaStyle aStyle = new AreaStyle ( lineStyle, siStyle );
CompositeStyle style = new CompositeStyle ( aStyle );
return style;
}
public override sealed List<MapInfo.Data.Column> CreateCustomColumn ()
{
MapInfo.Data.Column c = new MapInfo.Data.Column ( "value", MapInfo.Data.MIDbType.Double );
List<MapInfo.Data.Column> list = new List<MapInfo.Data.Column> ();
list.Add ( c );
return list;
}
protected override sealed void FillCommand ( ref MapInfo.Data.MICommand command )
{
command.Parameters["value"].Value = this._value;
}
public override MapInfo.Geometry.FeatureGeometry GetFeature ( MapInfo.Geometry.CoordSys coordSys )
{
//构造一个边长100米的矩形
MapInfo.Geometry.Rectangle dr = new MapInfo.Geometry.Rectangle ( coordSys, new DPoint ( this.X, this.Y ), 100d, 100d, DistanceUnit.Meter, DistanceType.Spherical );
FeatureGeometry fg = new MapInfo.Geometry.Rectangle ( coordSys, dr );
return fg;
}


<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> /**//// <summary>
/// 把数据填充到地图表中
/// </summary>
/// <param name="table">地图数据表实例,必须实现GetFeature和GetMapStyle方法</param>
/// <param name="coordSys">地图坐标系统</param>
/// <param name="entityList">数据</param>
public static void InsertTable ( Table table,CoordSys coordSys, List<AbstractEntity> entityList )
{
//创建连接对象
MIConnection connection = new MIConnection ();
connection.Open ();
//Comm对象
MICommand cmd;
try
{
foreach ( AbstractEntity entity in entityList )
{
cmd = connection.CreateCommand ();
//使用各个实体构造Comm对象
entity.PrepareCommand ( table.Alias, ref cmd, entity.GetFeature ( coordSys ), entity.GetMapStyle () );
cmd.Prepare ();
int nchanged = cmd.ExecuteNonQuery ();
cmd.Dispose ();
}
}
catch ( Exception ex )
{
throw new Exception ( "InsertTable Error " + ex.Message, ex );
}
finally
{
if ( connection.State == System.Data.ConnectionState.Open )
{
connection.Close ();
}
}
}