Mapxはgstファイルをロードして、レイヤーをカスタマイズして、Mapxはカスタムスタイルの矩形を描いて、円形、楕円形
ブログを書くのは久しぶりで、Gisに関するブログを書くのも初めてです.今日はMapxの簡単な例を皆さんと共有します.
1、mapx 5.0インストールパッケージをインストールします.
2、VSツールボックスにMapxコントロールを追加する.
3、具体的な実現を見てみましょう.
1、mapx 5.0インストールパッケージをインストールします.
2、VSツールボックスにMapxコントロールを追加する.
3、具体的な実現を見てみましょう.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MapxDemo
{
///
/// : Mapx Demo
/// :
///
public partial class FormMapxDemo : Form
{
#region Parameters
Dictionary featureList = null;//
int feaNumber;//
const string feaPrefix = "fea";//
MapXLib.Layer m_visionLayer;//
#endregion
#region Constructor
public FormMapxDemo()
{
InitializeComponent();
}
#endregion
#region OnLoad
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
axMap.GeoSet = Application.StartupPath + "\\MapInfo\\ .gst";
axMap.CreateCustomTool(11, MapXLib.ToolTypeConstants.miToolTypeCircle, MapXLib.CursorConstants.miCrossCursor);
axMap.CreateCustomTool(12, MapXLib.ToolTypeConstants.miToolTypeMarquee, MapXLib.CursorConstants.miCrossCursor);
axMap.CreateCustomTool(13, MapXLib.ToolTypeConstants.miToolTypeMarquee, MapXLib.CursorConstants.miCrossCursor);
featureList = new Dictionary();
CreateLayer();
}
#endregion
#region Events
private void toolStripButtonRect_Click(object sender, EventArgs e)
{
axMap.CurrentTool = (MapXLib.ToolConstants)12; //
}
private void axMap_ToolUsed(object sender, AxMapXLib.CMapXEvents_ToolUsedEvent e)
{
if(m_visionLayer==null)
CreateLayer();
MapXLib.Feature feaObj;
MapXLib.Point pt1 = new MapXLib.Point();
pt1.Set(e.x1, e.y1);
MapXLib.Point pt2 = new MapXLib.Point();
pt2.Set(e.x2, e.y2);
if (e.toolNum == 11)
{
double radius = Math.Sqrt(Math.Pow((pt2.X - pt1.X), 2) + Math.Pow((pt2.Y - pt1.Y), 2));
#region
try
{
feaObj = axMap.FeatureFactory.CreateCircularRegion(MapXLib.CircleTypeConstants.miCircleTypeScreen, pt1, radius, MapXLib.MapUnitConstants.miUnitDegree, 100, axMap.DefaultStyle);
axMap.Layers._Item(m_visionLayer).AddFeature(feaObj, Type.Missing);
feaObj.Update(Type.Missing, Type.Missing);
feaObj.KeyValue = feaPrefix + feaNumber++.ToString();
featureList.Add(feaObj.KeyValue, feaObj);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
#endregion
}
if (e.toolNum == 12)
{
#region
MapXLib.Style redline = new MapXLib.StyleClass();
redline.LineColor = (uint)MapXLib.ColorConstants.miColorRed;
redline.LineWidthUnit = MapXLib.StyleUnitConstants.miStyleUnitPixel;
redline.LineWidth = 2;
redline.LineStyle = (MapXLib.PenStyleConstants)2; //
redline.RegionPattern = MapXLib.FillPatternConstants.miPatternNoFill;
MapXLib.Points pts = new MapXLib.Points();
pts.Add(pt1, 1);
pts.Add(pt2, 3);
pts.AddXY(e.x1, e.y2, 4);
pts.AddXY(e.x2, e.y1, 2);
try
{
feaObj = axMap.FeatureFactory.CreateRegion(pts, redline);
axMap.Layers._Item(m_visionLayer).AddFeature(feaObj, Type.Missing);
feaObj.KeyValue = feaPrefix + feaNumber++.ToString();
featureList.Add(feaObj.KeyValue, feaObj);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
#endregion
}
if (e.toolNum == 13)
{
#region
try
{
MapXLib.Rectangle rect = new MapXLib.Rectangle();
MapXLib.Style redline = new MapXLib.StyleClass();
redline.LineColor = (uint)MapXLib.ColorConstants.miColorRed;
redline.LineWidthUnit = MapXLib.StyleUnitConstants.miStyleUnitPixel;
redline.LineWidth = 2;
redline.LineStyle = (MapXLib.PenStyleConstants)2; //
redline.LineInterleaved = false;
rect.Set(e.x1, e.y1, e.x2, e.y2);
feaObj = axMap.FeatureFactory.CreateEllipticalRegion(rect, 2, 100, redline);
axMap.Layers._Item(m_visionLayer).AddFeature(feaObj, Type.Missing);
feaObj.KeyValue = feaPrefix + feaNumber++.ToString();
featureList.Add(feaObj.KeyValue, feaObj);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
#endregion
}
}
private void toolStripButtonRadius_Click(object sender, EventArgs e)
{
axMap.CurrentTool = (MapXLib.ToolConstants)11; //
}
private void toolStripButtonEllipse_Click(object sender, EventArgs e)
{
axMap.CurrentTool = (MapXLib.ToolConstants)13; //
}
private void toolStripButtonSave_Click(object sender, EventArgs e)
{
ClearLayer();
}
#endregion
#region Custom Method
///
///
///
private void CreateLayer()
{
MapXLib.LayerInfo redlayer = new MapXLib.LayerInfoClass();
redlayer.AddParameter("FileSpec", "");
redlayer.AddParameter("name", "red");
redlayer.AddParameter("TableStorageType", "MemTable");
redlayer.Type = MapXLib.LayerInfoTypeConstants.miLayerInfoTypeTemp;
MapXLib.Fields flds = new MapXLib.FieldsClass();
redlayer.AddParameter("fields", flds);
redlayer.Type = MapXLib.LayerInfoTypeConstants.miLayerInfoTypeTemp;
m_visionLayer = axMap.Layers.Add(redlayer, 0);
}
///
///
///
private void ClearLayer()
{
axMap.Layers.Remove(m_visionLayer);
m_visionLayer = null;
}
#endregion
}
}