C#+MO实现一个道路编辑软件(刚开始)
发布时间:2023-03-28 08:52:05
//**********************************************************
//******主窗口程序
//********************************************************
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 <= axMap1.Layers.Count - 1; i++)
{
axMap1.Layers.Remove(pubLayerVariable.MapLayerIndex);
break;
}
bool refTrue = true;
axMap1.Refresh();
axlegend1.LoadLegend(ref refTrue);
}
}
private void axlegend1_AfterSetLayerVisible(object sender,AxSampleLegendControl.__legend_AfterSetLayerVisibleEvent e)
{
axMap1.Refresh();
}
private void axlegend1_LayerDblClick(object sender, AxSampleLegendControl.__legend_LayerDblClickEvent e)
{
}
private void axlegend1_MouseDownEvent(object sender, AxSampleLegendControl.__legend_MouseDownEvent e)
{
if (e.index >= 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 < mrs.TableDesc.FieldCount; fld++)
{
Item = lvwAttr.Items.Add(mrs.TableDesc.get_FieldName(fld));
Item.SubItems.Add(mrs.Fields.Item(Item.Text).ValueAsString);
}
lvwAttr.Refresh();
break;
}
mrs.MoveNext();
}
}
public void CurRecordSet(MapObjects2.Recordset vNewValue)
{
mrs = vNewValue;
}
public void IniLvwAttr(MapObjects2.Recordset rst)
{
TreeNode n=null ;
ListViewItem Item;
string ID;
lvwAttr.Items.Clear();
if (tvFeat.Nodes.Count >= 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 < rst.TableDesc.FieldCount; fld++)
{
Item = lvwAttr.Items.Add(rst.TableDesc.get_FieldName(fld));
Item.SubItems.Add(rst.Fields.Item(Item.Text).ValueAsString);
}
lvwAttr.Refresh();
break;
}
}
}
}
}
//将选择的记录集加入到树型控件中进行显示
public void IniTvFeat(MapObjects2.Recordset moRs_in, string lyrName_in)
{
TreeNode n;
string ID;
if (moRs_in.EOF != true)
{
moRs_in.MoveFirst();
tvFeat.Nodes.Clear();
n = tvFeat.Nodes.Add(lyrName_in);
n=n.Parent;
while (moRs_in.EOF != true)
{
ID = moRs_in.Fields.Item("FeatureID").ValueAsString;
n= tvFeat.Nodes.Add(ID);
moRs_in.MoveNext();
}
}
}
///////zuihou////////////////////////////////////////////////////////////////////////////
}
}
//*************************************************************
//************加载图层函数
//*************************************************************
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace IRND_DPT
{
class OpenFile
{
//功能说明:
// 从公共对话框中提取文件名,然后调用不同的子模块处理不同的文件加入图层的问题(支持打开多个文件)
public void OpenShapeFiles(OpenFileDialog comopenfile,AxMapObjects2.AxMap map)
{
try
{
string strShape, strCov, strCAD, strVPF, strImage, strMilImage;
//将过滤器设置为可支持的文件
strShape = "ESRI ShapeFiles(*.shp)|*.shp";
strCov = "ESRI Coverages(*.adf,*.tat,*.pat,*.rat)|aat.adf;pat.adf;nat.adf;txt.adf;*.tat;*.pat;*.rat";
strCAD = "AutoCAD File (*.dwg,*.dxf)|*.dwg;*.dxf";
strImage ="All Image(*.bmp,*.dib,*.tif,*.jpg,*.jff,*.bil,*.bip,*.bsq,*.gis,*.lan,*.rlc,*.sid,*.sun,*.rs,*.ras,*.svf,*.img,*.gif)|*.bmp,*.dib,*.tif,*.jpg,*.jff,*.bil,*.bip,*.bsq,*.gis,*.lan,*.rlc,*.sid,*.sun,*.rs,*.ras,*.svf,*.img,*.gif";
comopenfile.CheckFileExists = true;
//设置过滤
comopenfile.Filter = strShape + "|" + strCov + "|" + strCAD + "|" + strImage ;
comopenfile.Title = "添加图层";
//允许选择多个文件,并允许长文件名
comopenfile.Multiselect = true;
if (comopenfile.ShowDialog() == DialogResult.OK)
{
foreach (string strFilename in comopenfile.FileNames)
{
string sPath = strFilename.Substring(0, strFilename.LastIndexOf("\\") + 1);
string sFile = strFilename.Substring(strFilename.LastIndexOf("\\") + 1, strFilename.Length - strFilename.LastIndexOf("\\") - 1);
string nametype = sFile.Substring(sFile.LastIndexOf(".") + 1, sFile.Length - sFile.LastIndexOf(".") - 1);
open_file(sPath, sFile, nametype, map);
}
}
}
catch
{
MessageBox.Show("图层添加有错!");
}
}
//功能说明:
// 测试文件类型,一便调用不同的子模块.处理不同图层加入的问题
private void open_file(string Path,string filename,string filetype,AxMapObjects2.AxMap mapobject)
{
string LayerName = filename.Substring(0, filename.LastIndexOf("."));
switch (filetype)
{
case "shp":
shpAdd(Path, filename, mapobject, LayerName, true);
break;
}
}
//功能说明:
//添加shape格式的文件
public void shpAdd(string databasepath, string filename,AxMapObjects2.AxMap mapobject, string LayerName, bool Hide)
{
MapObjects2.DataConnection dCon=new MapObjects2.DataConnection() ;
// MapObjects2.GeoDataset gSet=new MapObjects2.GeoDataset ();
MapObjects2.MapLayer newLayer = new MapObjects2.MapLayer();
long i=0;
try
{
dCon.Database = databasepath;
if (dCon.Connect())
{
MapObjects2.GeoDataset gSet = dCon.FindGeoDataset(filename);
if (gSet == null)
{
return ;
}
else
{
//查看当前是否有重复的图层名,以确保所有的图层名都是唯一的
if (FindMapLayerName(mapobject,LayerName)==true )
{
string tempstr = LayerName;
while (FindMapLayerName(mapobject, tempstr + "-" + i)==true )
{
i++;
}
LayerName = LayerName + "-" + i;
}
newLayer.GeoDataset = gSet;
if (Hide)
{
newLayer.Visible = true;
}
else
{
newLayer.Visible = false;
}
//使用默认颜色和样式设置图层
switch (newLayer.shapeType)
{
case MapObjects2.ShapeTypeConstants.moShapeTypePoint :
newLayer.Symbol.Color=11513775;
newLayer.Symbol.Size=5;
break;
case MapObjects2.ShapeTypeConstants .moShapeTypeLine :
newLayer.Symbol.Color = 11513775;
newLayer.Symbol.Size = 1;
break;
case MapObjects2.ShapeTypeConstants.moShapeTypePolygon :
newLayer.Symbol.SymbolType = 0;
newLayer.Symbol.Style = 8;
newLayer.Symbol.Color = 12566463;
newLayer.Symbol.Outline = true;
newLayer.Symbol.OutlineColor = (int)MapObjects2.ColorConstants.moBlack;
break;
}
mapobject.Layers.Add (newLayer);
newLayer.Name = LayerName;
newLayer.Tag=databasepath + filename ;
}
}
}
catch
{
// MessageBox("加载图层出错!");
}
}
//功能说明:
// 查找map中的图层AxMapObjects2.AxMap mapobject,string LayerName
public bool FindMapLayerName(AxMapObjects2.AxMap mapobject, string LayerName)
{
for (int i=0;i<mapobject.Layers.Count ;i++)
{
if (mapobject.Layers.Item(i).ToString() ==LayerName )
{
return true;
}
}
return false ;
}
}
}


猜你喜欢
- 废话不多说了,直接给大家贴代码了。具体代码如下所述:<?xml version="1.0" encoding=&q
- 1、引入依赖<dependency><groupId>org.springframework.boot</gr
- 官方办法 JAVA语言提供的一个关键字“FINAL”可以用来履行该任务。看看下面的源代码范例://FinalDemo.java public
- 1.Mybatis的Dao层实现1.1 传统开发方式1.1.1编写UserDao接口public interface UserDao { &
- 真实的多线程业务开发中,最常用到的逻辑就是数据的读写,ReentrantLock虽然具有完全互斥排他的效果(即同一时间只有一个线程正在执行l
- 下面是一个邮件接收的工具类,有点长!!!public class ReciveMail { private MimeMessage msg
- 本文研究的主要是优化MyBatis配置文件中的配置的相关内容,具体介绍如下。一、连接数据库的配置单独放在一个properties文件中之前,
- 进行数据源或者 FTP 服务器等资源配置时,我们可以将这些配置信息放到一个独立的外部属性文件中,并在 Spring 配置文件中通过形如 ${
- 最近接触到INI配置文件的读写,虽然很久以前微软就推荐使用注册表来代替INI配置文件,现在在Visual Stud
- 我们都知道,在我们开发时需要在模拟器上模拟GPS,可在Location的时候总是null,上网查了一下,发现如下解决: 网上大侠的解决方案:
- 学了Android有一段时间了,一直没有时间写博客,趁着周末有点空,就把自己做的一些东西写下来. 一方面锻炼一下自己的写文档的能力,另一方面
- 转拼音的依赖implementation 'com.github.SilenceDut:jpinyin:v1.0'FastI
- 最大单词长度乘积给你一个字符串数组 words ,找出并返回 length(words[i]) * length(words[j]
- Java中的引用类型有哪几种?Java中的引用类型分成 强引用 , 软引用 , 弱引用 , 虚引用 。1、强引用没有引用指向这个对象,垃圾回
- 本文实例为大家分享了java实现PDF转图片的具体代码,供大家参考,具体内容如下1.首先利用maven引入所需jar包<depende
- @PropertySource作用是:对自定义的properties文件加载使用:@PropertySource(value={"
- java的比较器有两类,分别是Comparable接口和Comparator接口。在为对象数组进行排序时,比较器的作用非常明显,首先来讲解C
- Environment的中文意思是环境,它表示整个spring应用运行时的环境信息,它包含两个关键因素profilespropertiesp
- TypeScript简介:TypeScript是一种由微软开发的自由和开源的编程语言。它是JavaScript的一个超集,而且本质上向这个语
- MANIFEST.MF打开Java的JAR文件我们经常可以看到文件中包含着一个META-INF目录, 这个目录下会有一些文件,其中必有一个M