📄 form1.cs
字号:
this.axMap1.CtlRefresh();
}
catch (System.Runtime.InteropServices.COMException com)
{
MessageBox.Show(com.Message);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void valueMap_Click(object sender, System.EventArgs e)
{
try
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
this.m_pCitiesLyr.Visible = false;
ESRI.MapObjects2.Core.Recordset pRecs = this.m_pCountiesLyr.Records;
ESRI.MapObjects2.Core.Strings strings = new ESRI.MapObjects2.Core.StringsClass();
while (!pRecs.EOF)
{
strings.Add(pRecs.Fields.Item("STATE_NAME").ValueAsString);
pRecs.MoveNext();
}
ESRI.MapObjects2.Core.ValueMapRenderer pRend = new ESRI.MapObjects2.Core.ValueMapRendererClass();
pRend.Field = "STATE_NAME";
pRend.ValueCount = strings.Count;
for (int i=0; i<strings.Count - 1; i++)
{
//pRend.Value(Convert.ToInt16(i)) = strings.Item(i);
pRend.set_Value(Convert.ToInt16(i),strings.Item(i));
}
this.m_pCountiesLyr.Renderer = pRend;
this.axMap1.CtlRefresh();
}
catch (System.Runtime.InteropServices.COMException com)
{
MessageBox.Show(com.Message);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
InitializeMapData();
InitializeTrackingLayer();
this.timer1.Interval = 500;
if (CreateLineMapLayer())
SaveData();
this.axMap1.Layers.Add(layer);
layer.Symbol.Color = Convert.ToUInt32(ESRI.MapObjects2.Core.ColorConstants.moRed);
gds = layer.Records.Export(
this.dlgSave.FileName.Substring(0, this.dlgSave.FileName.Length - 4) + "1.shp", null);
ESRI.MapObjects2.Core.Rectangle rec = this.axMap1.FullExtent;
rec.Top = 2465040d;
rec.Bottom = 2175099d;
rec.Left = 1672595d;
rec.Right = 1865889d;
this.axMap1.Extent = rec;
this.axMap1.CtlRefresh();
}
/// <summary>
/// 初始化窗体
/// </summary>
private void InitializeMapData()
{
try
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
ESRI.MapObjects2.Core.DataConnection dataConn = new ESRI.MapObjects2.Core.DataConnectionClass();
string dataPath = ReturnDataPath("Northeast");
dataConn.Database = dataPath;
dataConn.Connect();
if (dataConn.Connected)
{
this.m_pCountiesLyr = new ESRI.MapObjects2.Core.MapLayerClass();
ESRI.MapObjects2.Core.GeoDataset gds = dataConn.FindGeoDataset("Counties");
if (gds != null)
{
this.m_pCountiesLyr.GeoDataset = gds;
this.m_pCountiesLyr.Symbol.Color = Convert.ToUInt32(ESRI.MapObjects2.Core.ColorConstants.moPaleYellow);
this.axMap1.Layers.Add(this.m_pCountiesLyr);
}
this.m_pCitiesLyr = new ESRI.MapObjects2.Core.MapLayerClass();
gds = dataConn.FindGeoDataset("Necenter");
if (gds != null)
{
this.m_pCitiesLyr.GeoDataset = gds;
this.m_pCitiesLyr.Symbol.Color = Convert.ToUInt32(ESRI.MapObjects2.Core.ColorConstants.moBlue);
this.axMap1.Layers.Add(this.m_pCitiesLyr);
}
}
if (this.axMap1.Layers.Count != 2)
{
MessageBox.Show("加载地图文件出错","错误");
}
}
catch (System.Exception e)
{
MessageBox.Show(e.Message);
}
finally {
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
}
}
private string ReturnDataPath(string dataPath)
{
/*string basePath = Application.ExecutablePath;
int index = basePath.LastIndexOf("Samples");
if (index > -1)
{
return basePath.Substring(0, index + 8) + "Data\\" + dataPath;
}
else
return null;*/
return this.m_dataPath + dataPath;
}
private void InitializeTrackingLayer()
{
stdole.StdFont fnt = new stdole.StdFontClass();
fnt.Name = "Wingdings";
fnt.Bold = false;
this.axMap1.TrackingLayer.SymbolCount = 2;
this.axMap1.TrackingLayer.get_Symbol(0).Color = (uint)ESRI.MapObjects2.Core.ColorConstants.moBlue;
this.axMap1.TrackingLayer.get_Symbol(0).Style = (short)ESRI.MapObjects2.Core.MarkerStyleConstants.moTrueTypeMarker;
this.axMap1.TrackingLayer.get_Symbol(0).Font = fnt;
this.axMap1.TrackingLayer.get_Symbol(0).Size = 16;
this.axMap1.TrackingLayer.get_Symbol(0).CharacterIndex = 88;
this.axMap1.TrackingLayer.get_Symbol(1).Color = (uint)ESRI.MapObjects2.Core.ColorConstants.moPurple;
this.axMap1.TrackingLayer.get_Symbol(1).Style = (short)ESRI.MapObjects2.Core.MarkerStyleConstants.moTrueTypeMarker;
this.axMap1.TrackingLayer.get_Symbol(1).Font = fnt;
this.axMap1.TrackingLayer.get_Symbol(1).Size = 16;
this.axMap1.TrackingLayer.get_Symbol(1).CharacterIndex = 88;
}
private void axMap1_MouseDownEvent(object sender, ESRI.MapObjects2.Core.MouseDownEventArgs e)
{
IEnumerator btnEnum = toolBar1.Buttons.GetEnumerator();
btnEnum.Reset();
System.Windows.Forms.ToolBarButton tbb = null;
while(btnEnum.MoveNext())
{
tbb = (System.Windows.Forms.ToolBarButton)btnEnum.Current;
if (tbb.Pushed ) break;
}
if (tbb != null)
{
if (tbb.ToolTipText.Equals("Zoom In")) DoZoom(e.shift);
else if (tbb.ToolTipText.Equals("Pan")) this.axMap1.Pan();
else if (tbb.ToolTipText.Equals("Add Event")) AddEvent(e.x, e.y);
else if (tbb.ToolTipText.Equals("Select Events")) SelectEvents();
}
}
/*private void Buffer(Object shape)
{
try
{
ESRI.MapObjects2.Core.GeoEvent res;
if (shape == null)
{
MessageBox.Show("shape is nothing");
}
ESRI.MapObjects2.Core.Polygon poly = shape as ESRI.MapObjects2.Core.PolygonClass;
if (poly != null)
{
res = this.axMap1.TrackingLayer.AddEvent(poly, 1);
}
ESRI.MapObjects2.Core.Line line = shape as ESRI.MapObjects2.Core.LineClass;
if (line != null)
res = this.axMap1.TrackingLayer.AddEvent(line, 0);
}
catch (System.Runtime.InteropServices.COMException comEx)
{
MessageBox.Show(comEx.Message);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}*/
private void stdDev_Click(object sender, System.EventArgs e)
{
try
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
this.m_pCitiesLyr.Visible = false;
ESRI.MapObjects2.Core.Recordset pRecs = this.m_pCountiesLyr.Records;
ESRI.MapObjects2.Core.ClassBreaksRenderer pCBRend = new ESRI.MapObjects2.Core.ClassBreaksRendererClass();
pCBRend.Field = "P_OTHER";
ESRI.MapObjects2.Core.Statistics pStats = pRecs.CalculateStatistics("P_OTHER");
double dBreak = pStats.Mean - (pStats.StdDev * 3);
for (int i=0; i<6; i++)
{
if (dBreak >= pStats.Min && dBreak < pStats.Max)
{
pCBRend.BreakCount ++;
//pCBRend.Break(pCBRend.BreakCount - Convert.ToInt16(1)) = dBreak;
short j = Convert.ToInt16(pCBRend.BreakCount - 1);
pCBRend.set_Break(j, dBreak);
}
dBreak += pStats.StdDev;
}
pCBRend.RampColors(Convert.ToUInt32(ESRI.MapObjects2.Core.ColorConstants.moLightYellow), Convert.ToUInt32(ESRI.MapObjects2.Core.ColorConstants.moRed));
this.m_pCountiesLyr.Renderer = pCBRend;
this.axMap1.CtlRefresh();
}
catch (System.Runtime.InteropServices.COMException com)
{
MessageBox.Show(com.Message);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void labMap_Click(object sender, System.EventArgs e)
{
}
private void dotDens_Click(object sender, System.EventArgs e)
{
try
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
this.m_pCitiesLyr.Visible = false;
ESRI.MapObjects2.Core.DotDensityRenderer pRend = new ESRI.MapObjects2.Core.DotDensityRendererClass();
this.m_pCountiesLyr.Renderer = pRend;
pRend.Field = "HBEDS_1000";
ESRI.MapObjects2.Core.Statistics pStats;
ESRI.MapObjects2.Core.Recordset pRecs = this.m_pCountiesLyr.Records;
pStats = pRecs.CalculateStatistics("HBEDS_1000");
pRend.DotValue = (pStats.Min + (pStats.Max - pStats.Min)/2)/20;
pRend.DotColor = Convert.ToUInt32(ESRI.MapObjects2.Core.ColorConstants.moRed);
this.axMap1.CtlRefresh();
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
}
catch (System.Runtime.InteropServices.COMException com)
{
MessageBox.Show(com.Message);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
IEnumerator btnEnum = this.toolBar1.Buttons.GetEnumerator();
btnEnum.Reset();
System.Windows.Forms.ToolBarButton tbb;
while (btnEnum.MoveNext())
{
tbb = (System.Windows.Forms.ToolBarButton)btnEnum.Current;
tbb.Pushed = false;
}
e.Button.Pushed = true;
}
private void DoZoom(short shift)
{
if (shift == 0.0)
this.axMap1.Extent = this.axMap1.TrackRectangle();
else
{
ESRI.MapObjects2.Core.Rectangle r = this.axMap1.Extent;
r.ScaleRectangle(1.5d);
this.axMap1.Extent = r;
}
}
private void SelectEvents()
{
ESRI.MapObjects2.Core.Rectangle r = this.axMap1.TrackRectangle();
long nEventCount = this.axMap1.TrackingLayer.EventCount;
ESRI.MapObjects2.Core.Point testPt = new ESRI.MapObjects2.Core.PointClass();
ESRI.MapObjects2.Core.GeoEvent evt;
for (int i=0;i<nEventCount;i++)
{
evt = this.axMap1.TrackingLayer.get_Event(i);
testPt.X = evt.X;
testPt.Y = evt.Y;
if (r.IsPointIn(testPt))
evt.SymbolIndex = 1;
else
evt.SymbolIndex = 0;
}
}
private void AddEvent(Single x, Single y)
{
ESRI.MapObjects2.Core.Point pt = this.axMap1.ToMapPoint(x, y);
this.axMap1.TrackingLayer.AddEvent(pt, 0);
}
/*private Object TrackShape()
{
if (this.radioButton2.Checked)
{
ESRI.MapObjects2.Core.Polygon poly = this.axMap1.TrackPolygon();
ESRI.MapObjects2.Core.GeoEvent evtPoly = this.axMap1.TrackingLayer.AddEvent(poly, 1);
return poly;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -