Last active
December 21, 2015 11:59
-
-
Save KohsukeHada/6302939 to your computer and use it in GitHub Desktop.
GraphicTracker を使用してRPG風シンボルの移動
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Text; | |
using System.Windows.Forms; | |
using ESRI.ArcGIS.Carto; | |
using ESRI.ArcGIS.Geometry; | |
using ESRI.ArcGIS.Display; | |
using ESRI.ArcGIS.EngineCore; | |
namespace MappingApplication_CS | |
{ | |
public partial class Form1 : Form | |
{ | |
double g_X; | |
double g_Y; | |
IGraphicTracker g_pGraphicTracker; | |
IGraphicTrackerSymbol g_pGraphicTrackerSymbol1; | |
IGraphicTrackerSymbol g_pGraphicTrackerSymbol2; | |
int g_ID; | |
bool g_Flag; | |
public Form1() | |
{ | |
InitializeComponent(); | |
//GraphicTrackerの初期化 | |
g_pGraphicTracker = new GraphicTrackerClass(); | |
g_pGraphicTracker.Initialize(axMapControl1.Map as IBasicMap); | |
string path = @".\saga.png"; | |
string path2 = @".\saga2.png"; | |
g_pGraphicTrackerSymbol1 = g_pGraphicTracker.CreateSymbolFromPath(path, path); | |
g_pGraphicTrackerSymbol2 = g_pGraphicTracker.CreateSymbolFromPath(path2, path2); | |
IPoint pPoint = new PointClass(); | |
pPoint.PutCoords(0, 0); | |
g_X = 1278000; | |
g_Y = 341000; | |
g_ID = g_pGraphicTracker.Add(pPoint as IGeometry, g_pGraphicTrackerSymbol1); | |
g_pGraphicTracker.SetOrientationMode(g_ID, esriGTOrientation.esriGTOrientationFixed); | |
//Timerイベント | |
Timer timer = new Timer(); | |
timer.Interval = 1000; | |
timer.Tick += new EventHandler(timer1_Tick); | |
timer.Start(); | |
} | |
//現在のマウスカーソル位置の座標をステータスバーに表示する | |
private void axMapControl1_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e) | |
{ | |
string x = System.Convert.ToString(e.mapX); | |
string y = System.Convert.ToString(e.mapY); | |
toolStripStatusLabel1.Text = "X: " + x + " " + "Y: " + y; | |
} | |
//タイマー イベント ハンドラ | |
private void timer1_Tick(object sender, EventArgs e) | |
{ | |
if (g_Flag == true) | |
{ | |
g_pGraphicTracker.SetSymbol(0, g_pGraphicTrackerSymbol1); | |
g_Flag = !g_Flag; | |
} | |
else | |
{ | |
g_pGraphicTracker.SetSymbol(0, g_pGraphicTrackerSymbol2); | |
g_Flag = !g_Flag; | |
} | |
g_pGraphicTracker.MoveTo(g_ID, g_X, g_Y, 0.0); | |
} | |
private void axMapControl1_OnKeyDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnKeyDownEvent e) | |
{ | |
switch (e.keyCode) | |
{ | |
//8キー | |
case (int)104: | |
g_Y += 50; | |
break; | |
//2キー | |
case (int)98: | |
g_Y -= 50; | |
break; | |
//4キー | |
case (int)100: | |
g_X -= 50; | |
break; | |
//6キー | |
case (int)102: | |
g_X += 50; | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment