当前位置: 编程技术>.net/c#/asp.net
C#+MO实现一个道路编辑软件(刚开始)
来源: 互联网 发布时间:2014-10-13
本文导语: //********************************************************** //******主窗口程序 //******************************************************** using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using Sys...
//**********************************************************
//******主窗口程序
//********************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace IRND_DPT
{
public partial class frmMain : Form
{
IRND_DPT.layerVariable pubLayerVariable = new layerVariable ();
public frmMain()
{
InitializeComponent();
}
//添加图层
private void tlbAddLayer_Click(object sender, EventArgs e)
{
IRND_DPT.OpenFile AddFile = new OpenFile();
AddFile.OpenShapeFiles(CD1,axMap1 );
object refMap = (object)this.axMap1;
bool refTrue = true;
short refShort = 0;
axlegend1.setMapSource(ref refMap);
axlegend1.ShowAllLegend();
axlegend1.LoadLegend(ref refTrue);
axlegend1.set_Active(ref refShort, true);
axMap1.Refresh();
axlegend1.Refresh();
//AddFile(CD1, axMap1);
}
//删除图层
private void toolStripButton4_Click(object sender, EventArgs e)
{
if (pubLayerVariable.MapLayerIndex >= 0)
{
for (int i = 0; i = 0)
{
MapObjects2.MapLayer layer= (MapObjects2.MapLayer )axMap1.Layers.Item(e.index );
pubLayerVariable.MapLayerName = layer.Name;
pubLayerVariable.MapLayerIndex = e.index;
}
axMap1.TrackingLayer.Refresh(true, axMap1.Extent);
}
//放大
private void tlb_ZoomIn_Click(object sender, EventArgs e)
{
axMap1.MousePointer = MapObjects2.MousePointerConstants.moZoomIn;
}
//缩小
private void tlb_ZoomOut_Click(object sender, EventArgs e)
{
axMap1.MousePointer = MapObjects2.MousePointerConstants.moZoomOut;
}
//漫游
private void tlb_Pan_Click(object sender, EventArgs e)
{
axMap1.MousePointer = MapObjects2.MousePointerConstants.moPan;
}
//全图
private void tbl_Full_Click(object sender, EventArgs e)
{
axMap1.Extent = axMap1.FullExtent;
axMap1.MousePointer = MapObjects2.MousePointerConstants.moArrow;
}
//逐渐放大
private void tbl_SmallIn_Click(object sender, EventArgs e)
{
MapObjects2.Rectangle r = axMap1.Extent;
r.ScaleRectangle(0.9);
axMap1.Extent = r;
}
//逐渐缩小
private void tbl_SmallOut_Click(object sender, EventArgs e)
{
MapObjects2.Rectangle r = axMap1.Extent;
r.ScaleRectangle(1.1);
axMap1.Extent = r;
}
//选择查询
private void tbl_Identify_Click(object sender, EventArgs e)
{
axMap1.MousePointer = MapObjects2.MousePointerConstants.moIdentify;
}
//属性浏览
private void toolStripButton2_Click(object sender, EventArgs e)
{
if (pubLayerVariable.MapLayerIndex >= 0 & pubLayerVariable.MapLayerName != null)
{
MapObjects2.MapLayer lyr = (MapObjects2.MapLayer )axMap1.Layers.Item(pubLayerVariable.MapLayerName);
IRND_DPT.frmBrowseAttr frmBrowset = new frmBrowseAttr();
frmBrowset.IniListview(lyr);
frmBrowset.ShowDialog(this);
}
}
//地图响应事件
private void axMap1_MouseDownEvent(object sends, AxMapObjects2._DMapEvents_MouseDownEvent e)
{
MapObjects2.Rectangle rect;
MapObjects2.Point curp;
MapObjects2.MapLayer lyr;
MapObjects2.Recordset rest;
switch (axMap1.MousePointer)
{
//放大
case MapObjects2.MousePointerConstants.moZoomIn:
{
rect = axMap1.TrackRectangle();
if (rect.Width == 0 || rect.Height == 0)
{
rect = axMap1.Extent;
rect.ScaleRectangle(0.5);
}
axMap1.Extent = rect;
break;
}
//缩小
case MapObjects2.MousePointerConstants.moZoomOut:
{
MapObjects2.Rectangle Tempr;
Tempr = axMap1.Extent;
rect = axMap1.TrackRectangle();
double NewSR;
if (rect.Width != 0 || rect.Height != 0)
{
if (axMap1.Extent.Width / rect.Width > axMap1.Extent.Height / rect.Height)
{
NewSR = axMap1.Extent.Height / rect.Height;
}
else
{
NewSR = axMap1.Extent.Width / rect.Width;
}
Tempr.ScaleRectangle(NewSR);
}
else
{
Tempr.ScaleRectangle(2.0);
}
axMap1.Extent = Tempr;
break;
}
//漫游
case MapObjects2.MousePointerConstants.moPan:
{
axMap1.Pan();
break;
}
//选择查询
case MapObjects2.MousePointerConstants.moIdentify:
{
if (pubLayerVariable.MapLayerIndex >= 0 && pubLayerVariable.MapLayerName != "")
{
rect = axMap1.TrackRectangle();
lyr = (MapObjects2.MapLayer)axMap1.Layers.Item(pubLayerVariable.MapLayerIndex);
if (rect.Width == 0)
{
curp = axMap1.ToMapPoint(e.x, e.y);
rest = lyr.SearchByDistance(curp, (double)axMap1.ToMapDistance((float)Screen.PrimaryScreen.WorkingArea.X * 5), "");
}
else
{
rest = lyr.SearchShape(rect, MapObjects2.SearchMethodConstants.moAreaIntersect, "");
}
if (rest.EOF!=true)
{
axMap1.FlashShape(rest.Fields.Item("shape").Value, 2);
IRND_DPT.frmIdentify FunctionClass = new frmIdentify();
////FunctionClass.Close();
FunctionClass.CurRecordSet(rest);
FunctionClass.IniTvFeat(rest, lyr.Name);
FunctionClass.IniLvwAttr(rest);
FunctionClass.Show(this);
}
}
break;
}
}
}
////////
///////////////////////////////////////////////////////////////////////////////////////////////
}
}
//*************************************************
//********属性查询
//************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace IRND_DPT
{
public partial class frmIdentify : Form
{
MapObjects2.Recordset mrs;
public frmIdentify()
{
InitializeComponent();
}
private void frmIdentify_Load(object sender, System.EventArgs e)
{
lvwAttr.View = View.Details;
lvwAttr.Columns.Add("字段",50,HorizontalAlignment.Left );
lvwAttr.Columns.Add ("值",50,HorizontalAlignment.Center );
}
//
private void tvFeat_NodeMouseClick(object sender, System.Windows.Forms.TreeNodeMouseClickEventArgs e)
{
string ID;
ListViewItem Item;
//if (e.Node.Parent == null) { return; }
lvwAttr.Items.Clear();
ID = e.Node.Text;
mrs.MoveFirst();
while (mrs.EOF != true)
{
if (ID == mrs.Fields.Item("FeatureID").ValueAsString)
{
for (short fld = 1; fld = 2)
{
int i = 0;
foreach (TreeNode tn in tvFeat.Nodes)
{
i=i+1;
if (i == 2)
{
n = tn;
break;
}
}
if (n.Text != null)
{
rst.MoveFirst();
ID = rst.Fields.Item("FeatureID").ValueAsString;
while (rst.EOF != true)
{
if (ID == n.Text)
{
for (short fld = 1; fld
//******主窗口程序
//********************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace IRND_DPT
{
public partial class frmMain : Form
{
IRND_DPT.layerVariable pubLayerVariable = new layerVariable ();
public frmMain()
{
InitializeComponent();
}
//添加图层
private void tlbAddLayer_Click(object sender, EventArgs e)
{
IRND_DPT.OpenFile AddFile = new OpenFile();
AddFile.OpenShapeFiles(CD1,axMap1 );
object refMap = (object)this.axMap1;
bool refTrue = true;
short refShort = 0;
axlegend1.setMapSource(ref refMap);
axlegend1.ShowAllLegend();
axlegend1.LoadLegend(ref refTrue);
axlegend1.set_Active(ref refShort, true);
axMap1.Refresh();
axlegend1.Refresh();
//AddFile(CD1, axMap1);
}
//删除图层
private void toolStripButton4_Click(object sender, EventArgs e)
{
if (pubLayerVariable.MapLayerIndex >= 0)
{
for (int i = 0; i = 0)
{
MapObjects2.MapLayer layer= (MapObjects2.MapLayer )axMap1.Layers.Item(e.index );
pubLayerVariable.MapLayerName = layer.Name;
pubLayerVariable.MapLayerIndex = e.index;
}
axMap1.TrackingLayer.Refresh(true, axMap1.Extent);
}
//放大
private void tlb_ZoomIn_Click(object sender, EventArgs e)
{
axMap1.MousePointer = MapObjects2.MousePointerConstants.moZoomIn;
}
//缩小
private void tlb_ZoomOut_Click(object sender, EventArgs e)
{
axMap1.MousePointer = MapObjects2.MousePointerConstants.moZoomOut;
}
//漫游
private void tlb_Pan_Click(object sender, EventArgs e)
{
axMap1.MousePointer = MapObjects2.MousePointerConstants.moPan;
}
//全图
private void tbl_Full_Click(object sender, EventArgs e)
{
axMap1.Extent = axMap1.FullExtent;
axMap1.MousePointer = MapObjects2.MousePointerConstants.moArrow;
}
//逐渐放大
private void tbl_SmallIn_Click(object sender, EventArgs e)
{
MapObjects2.Rectangle r = axMap1.Extent;
r.ScaleRectangle(0.9);
axMap1.Extent = r;
}
//逐渐缩小
private void tbl_SmallOut_Click(object sender, EventArgs e)
{
MapObjects2.Rectangle r = axMap1.Extent;
r.ScaleRectangle(1.1);
axMap1.Extent = r;
}
//选择查询
private void tbl_Identify_Click(object sender, EventArgs e)
{
axMap1.MousePointer = MapObjects2.MousePointerConstants.moIdentify;
}
//属性浏览
private void toolStripButton2_Click(object sender, EventArgs e)
{
if (pubLayerVariable.MapLayerIndex >= 0 & pubLayerVariable.MapLayerName != null)
{
MapObjects2.MapLayer lyr = (MapObjects2.MapLayer )axMap1.Layers.Item(pubLayerVariable.MapLayerName);
IRND_DPT.frmBrowseAttr frmBrowset = new frmBrowseAttr();
frmBrowset.IniListview(lyr);
frmBrowset.ShowDialog(this);
}
}
//地图响应事件
private void axMap1_MouseDownEvent(object sends, AxMapObjects2._DMapEvents_MouseDownEvent e)
{
MapObjects2.Rectangle rect;
MapObjects2.Point curp;
MapObjects2.MapLayer lyr;
MapObjects2.Recordset rest;
switch (axMap1.MousePointer)
{
//放大
case MapObjects2.MousePointerConstants.moZoomIn:
{
rect = axMap1.TrackRectangle();
if (rect.Width == 0 || rect.Height == 0)
{
rect = axMap1.Extent;
rect.ScaleRectangle(0.5);
}
axMap1.Extent = rect;
break;
}
//缩小
case MapObjects2.MousePointerConstants.moZoomOut:
{
MapObjects2.Rectangle Tempr;
Tempr = axMap1.Extent;
rect = axMap1.TrackRectangle();
double NewSR;
if (rect.Width != 0 || rect.Height != 0)
{
if (axMap1.Extent.Width / rect.Width > axMap1.Extent.Height / rect.Height)
{
NewSR = axMap1.Extent.Height / rect.Height;
}
else
{
NewSR = axMap1.Extent.Width / rect.Width;
}
Tempr.ScaleRectangle(NewSR);
}
else
{
Tempr.ScaleRectangle(2.0);
}
axMap1.Extent = Tempr;
break;
}
//漫游
case MapObjects2.MousePointerConstants.moPan:
{
axMap1.Pan();
break;
}
//选择查询
case MapObjects2.MousePointerConstants.moIdentify:
{
if (pubLayerVariable.MapLayerIndex >= 0 && pubLayerVariable.MapLayerName != "")
{
rect = axMap1.TrackRectangle();
lyr = (MapObjects2.MapLayer)axMap1.Layers.Item(pubLayerVariable.MapLayerIndex);
if (rect.Width == 0)
{
curp = axMap1.ToMapPoint(e.x, e.y);
rest = lyr.SearchByDistance(curp, (double)axMap1.ToMapDistance((float)Screen.PrimaryScreen.WorkingArea.X * 5), "");
}
else
{
rest = lyr.SearchShape(rect, MapObjects2.SearchMethodConstants.moAreaIntersect, "");
}
if (rest.EOF!=true)
{
axMap1.FlashShape(rest.Fields.Item("shape").Value, 2);
IRND_DPT.frmIdentify FunctionClass = new frmIdentify();
////FunctionClass.Close();
FunctionClass.CurRecordSet(rest);
FunctionClass.IniTvFeat(rest, lyr.Name);
FunctionClass.IniLvwAttr(rest);
FunctionClass.Show(this);
}
}
break;
}
}
}
////////
///////////////////////////////////////////////////////////////////////////////////////////////
}
}
//*************************************************
//********属性查询
//************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace IRND_DPT
{
public partial class frmIdentify : Form
{
MapObjects2.Recordset mrs;
public frmIdentify()
{
InitializeComponent();
}
private void frmIdentify_Load(object sender, System.EventArgs e)
{
lvwAttr.View = View.Details;
lvwAttr.Columns.Add("字段",50,HorizontalAlignment.Left );
lvwAttr.Columns.Add ("值",50,HorizontalAlignment.Center );
}
//
private void tvFeat_NodeMouseClick(object sender, System.Windows.Forms.TreeNodeMouseClickEventArgs e)
{
string ID;
ListViewItem Item;
//if (e.Node.Parent == null) { return; }
lvwAttr.Items.Clear();
ID = e.Node.Text;
mrs.MoveFirst();
while (mrs.EOF != true)
{
if (ID == mrs.Fields.Item("FeatureID").ValueAsString)
{
for (short fld = 1; fld = 2)
{
int i = 0;
foreach (TreeNode tn in tvFeat.Nodes)
{
i=i+1;
if (i == 2)
{
n = tn;
break;
}
}
if (n.Text != null)
{
rst.MoveFirst();
ID = rst.Fields.Item("FeatureID").ValueAsString;
while (rst.EOF != true)
{
if (ID == n.Text)
{
for (short fld = 1; fld