阅读:2232回复:2
[分享] MapXteme 2005 闪烁要素代码
<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> |
|
|
1楼#
发布于:2007-05-20 20:06
<img src="images/post/smile/dvbbs/em05.gif" />
|
|
2楼#
发布于:2008-02-14 15:25
你真是大好人呀。网站就是需要你这样无私奉献的人的支持呀。<img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em02.gif" />
|
|