hover
路人甲
路人甲
  • 注册日期2005-12-13
  • 发帖数69
  • QQ
  • 铜币279枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2049回复:2

[分享] MapXteme 2005 闪烁要素代码

楼主#
更多 发布于:2007-05-17 17:37
<P>这些天有点郁闷。刚才无聊之下写了个闪烁要素的代码,很简单。给新手做个参考吧。</P>
<P>using System;<BR>using MapInfo.Mapping;<BR>using MapInfo.Data;<BR>using MapInfo.Geometry;</P>
<P>namespace AugurIT.SystemMap<BR>{<BR> /// <summary><BR> /// FlashFeature 的摘要说明。<BR> /// </summary><BR> public class FlashFeature<BR> {<BR>  private FlashFeature()<BR>  {<BR>  }<BR>  private static System.Windows.Forms.Timer m_Timer = null;  <BR>  private static IMapLayer m_TempLayer = null;<BR>  /// <summary><BR>  /// 开发闪烁<BR>  /// </summary><BR>  /// <param name="pMapControl"></param><BR>  /// <param name="pFeature"></param><BR>  public static void StartFlashFeature(MapInfo.Windows.Controls.MapControl pMapControl,Feature pFeature)<BR>  {   <BR>   // 设置闪烁的时间<BR>   m_Timer = new System.Windows.Forms.Timer();<BR>   m_Timer.Enabled = false;<BR>   m_Timer.Interval = 1000;   <BR>   m_Timer.Tick +=new EventHandler(TimerFlash_Tick);<BR>   // 在临时图层中创建用于闪烁的要素<BR>   CreateTempFlashFeature(pMapControl,pFeature);<BR>   m_Timer.Start();   <BR>  }<BR>  public static void StartFlashFeatures(MapInfo.Windows.Controls.MapControl pMapControl,IFeatureCollection pFeatureCollectoin)<BR>  {<BR>   // 设置闪烁的时间<BR>   m_Timer = new System.Windows.Forms.Timer();<BR>   m_Timer.Enabled = false;<BR>   m_Timer.Interval = 1000;<BR>   m_Timer.Tick +=new EventHandler(TimerFlash_Tick);<BR>   // 在临时图层中创建用于闪烁的要素<BR>   CreateTempFlashFeatures(pMapControl,pFeatureCollectoin);<BR>   m_Timer.Start();<BR>  }<BR>  /// <summary><BR>  /// 结束闪烁<BR>  /// </summary><BR>  public static void StopFlash()<BR>  {<BR>   m_Timer.Stop();<BR>   if (m_TempLayer == null) return;<BR>   // 清除临时图层上的所有要素<BR>   MapInfo.Data.Table pTempTable = MapInfo.Engine.Session.Current.Catalog.GetTable("TEMP");<BR>   (pTempTable as IFeatureCollection).Clear(); <BR>   m_TempLayer.Enabled = true;<BR>  }<BR>  /// <summary><BR>  /// 在临时图层中创建用于进行闪烁的要素<BR>  /// </summary><BR>  /// <param name="pMapControl"></param><BR>  /// <param name="pFeature"></param><BR>  private static void CreateTempFlashFeature(MapInfo.Windows.Controls.MapControl pMapControl,Feature pFeature)<BR>  {<BR>   MapInfo.Data.Table pTempTable = MapInfo.Engine.Session.Current.Catalog.GetTable("TEMP");<BR>   if (pTempTable == null)<BR>   {<BR>    MapInfo.Data.TableInfo ti = MapInfo.Data.TableInfoFactory.CreateTemp("TEMP");   <BR>    pTempTable = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);<BR>    pMapControl.Map.Layers.Insert(0, new MapInfo.Mapping.FeatureLayer(pTempTable));<BR>   }<BR>   else<BR>   {<BR>    //清除临时表中的所有Geometry对象<BR>    (pTempTable as IFeatureCollection).Clear();<BR>   }</P>
<P>   // 取得临时图层实例<BR>   m_TempLayer = pMapControl.Map.Layers["TEMP"];<BR>            <BR>   // 取得所要进行闪烁要素的空间对象<BR>   MapInfo.Geometry.FeatureGeometry pGeometry = pFeature.Geometry;<BR>   <BR>   // 设置当前视图的范围为当前要素的自身的范围<BR>   pMapControl.Map.SetView(pGeometry.Envelope);<BR>   <BR>   // 根据空间类型设置闪烁的符号样式<BR>   MapInfo.Styles.Style pStyle = CreateFlashStyle(pGeometry.Type);   <BR>   <BR>   // 根据闪烁的符号样式和空间信息创建所要进行闪烁的实体要素<BR>   Feature pTempFeature = new Feature(pGeometry, pStyle); <BR>   // 向临时图层中增加闪烁的实体要素<BR>   pTempTable.InsertFeature(pTempFeature);<BR>  }</P>
<P>  private static void CreateTempFlashFeatures(MapInfo.Windows.Controls.MapControl pMapControl,IFeatureCollection pFeatureCollection)<BR>  {<BR>   MapInfo.Data.Table pTempTable = MapInfo.Engine.Session.Current.Catalog.GetTable("TEMP");<BR>   if (pTempTable == null)<BR>   {<BR>    MapInfo.Data.TableInfo ti = MapInfo.Data.TableInfoFactory.CreateTemp("TEMP");   <BR>    pTempTable = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);<BR>    pMapControl.Map.Layers.Insert(0, new MapInfo.Mapping.FeatureLayer(pTempTable));<BR>   }<BR>   else<BR>   {<BR>    //清除临时表中的所有Geometry对象<BR>    (pTempTable as IFeatureCollection).Clear();<BR>   }</P>
<P>   // 取得临时图层实例<BR>   m_TempLayer = pMapControl.Map.Layers["TEMP"];   </P>
<P>   // 设置当前视图的范围为当前要素的自身的范围<BR>   pMapControl.Map.SetView(pFeatureCollection.Envelope);</P>
<P>   foreach (Feature pFeature in pFeatureCollection)<BR>   {<BR>    // 取得所要进行闪烁要素的空间对象<BR>    MapInfo.Geometry.FeatureGeometry pGeometry = pFeature.Geometry;<BR>    <BR>    // 根据空间类型设置闪烁的符号样式<BR>    MapInfo.Styles.Style pStyle = CreateFlashStyle(pGeometry.Type);    <BR>   <BR>    // 根据闪烁的符号样式和空间信息创建所要进行闪烁的实体要素<BR>    Feature pTempFeature = new Feature(pGeometry, pStyle); <BR>    // 向临时图层中增加闪烁的实体要素<BR>    pTempTable.InsertFeature(pTempFeature);<BR>   }<BR>  }</P>
<P>  private static MapInfo.Styles.Style CreateFlashStyle(GeometryType pGeometryType)<BR>  {<BR>   // 根据空间类型设置闪烁的符号样式<BR>   MapInfo.Styles.Style pStyle = null;<BR>   switch (pGeometryType)<BR>   {<BR>    case GeometryType.Curve:<BR>     pStyle = new MapInfo.Styles.SimpleLineStyle(new MapInfo.Styles.LineWidth(2, MapInfo.Styles.LineWidthUnit.Pixel), 2, System.Drawing.Color.Red, false);<BR>     break;<BR>    case GeometryType.Ellipse:<BR>     break;<BR>    case GeometryType.Envelope:<BR>     break;<BR>    case GeometryType.FeatureGeometryCollection:<BR>     break;<BR>    case GeometryType.LegacyArc:<BR>     break;<BR>    case GeometryType.LegacyText:<BR>     break;<BR>    case GeometryType.LineString:<BR>     break;<BR>    case GeometryType.MultiCurve:<BR>     break;<BR>    case GeometryType.MultiPoint:<BR>     break;<BR>    case GeometryType.MultiPolygon:<BR>     break;<BR>    case GeometryType.Point:<BR>     pStyle = new MapInfo.Styles.SimpleVectorPointStyle(1,System.Drawing.Color.Red,2);<BR>     break;<BR>    case GeometryType.Polygon:<BR>     break;  <BR>    case GeometryType.Rectangle:<BR>     break;<BR>    case GeometryType.Ring:<BR>     break;<BR>    case GeometryType.RoundedRectangle:<BR>     break;<BR>    default:<BR>     break;<BR>   }<BR>   return pStyle;<BR>  }<BR>  /// <summary><BR>  /// 进行闪烁<BR>  /// </summary><BR>  /// <param name="sender"></param><BR>  /// <param name="e"></param><BR>  private static void TimerFlash_Tick(object sender, System.EventArgs e)<BR>  {<BR>   if (m_TempLayer == null) return;<BR>   m_TempLayer.Enabled = !m_TempLayer.Enabled;<BR>  }<BR> }<BR>}<BR></P>
<P>补充一下:CreateFlashStyle方法没有写完,了解一下MapInfo.Styles空间就知道了。<BR>本人是通过文本文件进行配置。</P>
喜欢0 评分0
承接、合作各种GIS项目开发 :ArcGIS平(基于AO、AE、ArcIMS、ArcServer开发) :MapInfo平台(基于MapXtreme 2004/2005、MapXtreme For Java开发) E-Mail:cmcrj0929@163.com QQ:31814576 有国土、市政、交通、电力等行业的成功应用项目经验。
whmwxhanshan123
路人甲
路人甲
  • 注册日期2006-06-17
  • 发帖数3108
  • QQ
  • 铜币6445枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2007-05-20 20:06
<img src="images/post/smile/dvbbs/em05.gif" />
举报 回复(0) 喜欢(0)     评分
coolsundy
路人甲
路人甲
  • 注册日期2006-05-17
  • 发帖数2
  • QQ
  • 铜币107枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2008-02-14 15:25
你真是大好人呀。网站就是需要你这样无私奉献的人的支持呀。<img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em02.gif" />
举报 回复(0) 喜欢(0)     评分
游客

返回顶部