cl991036
管理员
管理员
  • 注册日期2003-07-25
  • 发帖数5913
  • QQ14265545
  • 铜币29654枚
  • 威望213点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • GIS帝国铁杆
阅读:2107回复:0

Mapx加载gst文件,自定义图层,Mapx画自定义样式矩形,圆形,椭圆形

楼主#
更多 发布于:2013-01-09 17:22
 <p>1、安装mapx 5.0安装包。</p><p>2、在VS工具箱中添加Mapx控件。</p><p>3、下面来看一下具体实现:</p><p>using System;</p><p>using System.Collections.Generic;</p><p>using System.ComponentModel;</p><p>using System.Data;</p><p>using System.Drawing;</p><p>using System.Linq;</p><p>using System.Text;</p><p>using System.Windows.Forms;</p><p>namespace MapxDemo</p><p>{</p><p>/// <summary></p><p>/// Mapx画形状的Demo</p><p>/// </summary></p><p>public partial class FormMapxDemo : Form</p><p>{</p><p>#region Parameters</p><p>Dictionary<string, MapXLib.Feature> featureList = null;//图元集合</p><p>int feaNumber;//图元编号</p><p>const string feaPrefix = "fea";//图元标识前缀</p><p>MapXLib.Layer m_visionLayer;//图层</p><p>#endregion</p><p>#region Constructor</p><p>public FormMapxDemo()</p><p>{</p><p>InitializeComponent();</p><p>}</p><p>#endregion</p><p>#region OnLoad</p><p>protected override void OnLoad(EventArgs e)</p><p>{</p><p>base.OnLoad(e);</p><p>axMap.GeoSet = Application.StartupPath + "\\MapInfo\\广州.gst";</p><p>axMap.CreateCustomTool(11, MapXLib.ToolTypeConstants.miToolTypeCircle, MapXLib.CursorConstants.miCrossCursor);</p><p>axMap.CreateCustomTool(12, MapXLib.ToolTypeConstants.miToolTypeMarquee, MapXLib.CursorConstants.miCrossCursor);</p><p>axMap.CreateCustomTool(13, MapXLib.ToolTypeConstants.miToolTypeMarquee, MapXLib.CursorConstants.miCrossCursor);</p><p>featureList = new Dictionary<string, MapXLib.Feature>();</p><p>CreateLayer();</p><p>}</p><p>#endregion</p><p>#region Events</p><p>private void toolStripButtonRect_Click(object sender, EventArgs e)</p><p>{</p><p>axMap.CurrentTool = (MapXLib.ToolConstants)12; //画矩形</p><p>}</p><p>private void axMap_ToolUsed(object sender, AxMapXLib.CMapXEvents_ToolUsedEvent e)</p><p>{</p><p>if(m_visionLayer==null)</p><p>CreateLayer();</p><p>MapXLib.Feature feaObj;</p><p>MapXLib.Point pt1 = new MapXLib.Point();</p><p>pt1.Set(e.x1, e.y1);</p><p>MapXLib.Point pt2 = new MapXLib.Point();</p><p>pt2.Set(e.x2, e.y2);</p><p>if (e.toolNum == 11)</p><p>{</p><p>double radius = Math.Sqrt(Math.Pow((pt2.X - pt1.X), 2) + Math.Pow((pt2.Y - pt1.Y), 2));</p><p>#region 画圆</p><p>try</p><p>{</p><p>feaObj
 =
axMap.FeatureFactory.CreateCircularRegion(MapXLib.CircleTypeConstants.miCircleTypeScreen,
 pt1, radius, MapXLib.MapUnitConstants.miUnitDegree, 100,
axMap.DefaultStyle);</p><p>axMap.Layers._Item(m_visionLayer).AddFeature(feaObj, Type.Missing);</p><p>feaObj.Update(Type.Missing, Type.Missing);</p><p>feaObj.KeyValue = feaPrefix + feaNumber++.ToString();</p><p>featureList.Add(feaObj.KeyValue, feaObj);</p><p>}</p><p>catch (Exception ex)</p><p>{</p><p>MessageBox.Show(ex.Message);</p><p>}</p><p>#endregion</p><p>}</p><p>if (e.toolNum == 12)</p><p>{</p><p>#region 画矩形</p><p>MapXLib.Style redline = new MapXLib.StyleClass();</p><p>redline.LineColor = (uint)MapXLib.ColorConstants.miColorRed;</p><p>redline.LineWidthUnit = MapXLib.StyleUnitConstants.miStyleUnitPixel;</p><p>redline.LineWidth = 2;</p><p>redline.LineStyle = (MapXLib.PenStyleConstants)2; //画笔样式</p><p>redline.RegionPattern = MapXLib.FillPatternConstants.miPatternNoFill;</p><p>MapXLib.Points pts = new MapXLib.Points();</p><p>pts.Add(pt1, 1);</p><p>pts.Add(pt2, 3);</p><p>pts.AddXY(e.x1, e.y2, 4);</p><p>pts.AddXY(e.x2, e.y1, 2);</p><p>try</p><p>{</p><p>feaObj = axMap.FeatureFactory.CreateRegion(pts, redline);</p><p>axMap.Layers._Item(m_visionLayer).AddFeature(feaObj, Type.Missing);</p><p>feaObj.KeyValue = feaPrefix + feaNumber++.ToString();</p><p>featureList.Add(feaObj.KeyValue, feaObj);</p><p>}</p><p>catch (Exception ex)</p><p>{</p><p>MessageBox.Show(ex.Message);</p><p>}</p><p>#endregion</p><p>}</p><p>if (e.toolNum == 13)</p><p>{</p><p>#region 画椭圆</p><p>try</p><p>{</p><p>MapXLib.Rectangle rect = new MapXLib.Rectangle();</p><p>MapXLib.Style redline = new MapXLib.StyleClass();</p><p>redline.LineColor = (uint)MapXLib.ColorConstants.miColorRed;</p><p>redline.LineWidthUnit = MapXLib.StyleUnitConstants.miStyleUnitPixel;</p><p>redline.LineWidth = 2;</p><p>redline.LineStyle = (MapXLib.PenStyleConstants)2; //画笔样式</p><p>redline.LineInterleaved = false;</p><p>rect.Set(e.x1, e.y1, e.x2, e.y2);</p><p>feaObj = axMap.FeatureFactory.CreateEllipticalRegion(rect, 2, 100, redline);</p><p>axMap.Layers._Item(m_visionLayer).AddFeature(feaObj, Type.Missing);</p><p>feaObj.KeyValue = feaPrefix + feaNumber++.ToString();</p><p>featureList.Add(feaObj.KeyValue, feaObj);</p><p>}</p><p>catch (Exception ex)</p><p>{</p><p>MessageBox.Show(ex.Message);</p><p>}</p><p>#endregion</p><p>}</p><p>private void toolStripButtonRadius_Click(object sender, EventArgs e)</p><p>{</p><p>axMap.CurrentTool = (MapXLib.ToolConstants)11; //画圆形</p><p>}</p><p>private void toolStripButtonEllipse_Click(object sender, EventArgs e)</p><p>{</p><p>axMap.CurrentTool = (MapXLib.ToolConstants)13; //画椭圆</p><p>}</p><p>private void toolStripButtonSave_Click(object sender, EventArgs e)</p><p>{</p><p>ClearLayer();</p><p>}</p><p>#endregion</p><p>#region Custom Method</p><p>/// <summary></p><p>/// 创建一个图层</p><p>/// </summary></p><p>private void CreateLayer()</p><p>{</p><p>MapXLib.LayerInfo redlayer = new MapXLib.LayerInfoClass();</p><p>redlayer.AddParameter("FileSpec", "");</p><p>redlayer.AddParameter("name", "red");</p><p>redlayer.AddParameter("TableStorageType", "MemTable");</p><p>redlayer.Type = MapXLib.LayerInfoTypeConstants.miLayerInfoTypeTemp;</p><p>MapXLib.Fields flds = new MapXLib.FieldsClass();</p><p>redlayer.AddParameter("fields", flds);</p><p>redlayer.Type = MapXLib.LayerInfoTypeConstants.miLayerInfoTypeTemp;</p><p>m_visionLayer = axMap.Layers.Add(redlayer, 0);</p><p>}</p><p>/// <summary></p><p>/// 清空图层</p><p>/// </summary></p><p>private void ClearLayer()</p><p>{</p><p>axMap.Layers.Remove(m_visionLayer);</p><p>m_visionLayer = null;</p><p>}</p><p>#endregion</p><p>}</p><p><span class="img"><a style="cursor: default;" class="vi"><img src="http://img1.cutt.com/img/121231000755889477912423/0"/><span></span></a></span></p>



<p>
<span><br/></span><a class="article-url" href="http://cutt.com/click?articleId=1660419524;url=http%3A%2F%2Fblog.csdn.net%2Fhugengyong%2Farticle%2Fdetails%2F8453963" title="http://blog.csdn.net/hugengyong/article/details/8453963" rel="nofollow"></a>
</p>
喜欢0 评分0
没钱又丑,农村户口。头可断,发型一定不能乱。 邮箱:gisempire@qq.com
游客

返回顶部