一:组件添加到工具栏
要在应用程序中应用OTGisX控件,首先要把所下载的OTGisX组件添加到.Net工程中。并将其添加到工具箱托盘
中。添加方式为:在工具箱上单击右键,选择“选择项”,会出现“选择工具箱项”对话框,在“COM组件”属性页,选择浏览,找到OTGisX.ocx添加到工具箱项。这时工具箱中会出现AxOTGisForm控件。在设计应
用程序界面时,可以将其拖入应用程序界面,系统会在代码中自动创建一个AxOTGisForm对象。
以管理员身份注册组件,就可以用了
二:如图
三:组件介绍
组件上有map对象,map对象上有layer对象,layer上有图元对象
四:实例
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;
using OTGisX; namespace OTGisX_test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} #region 事件:运行自加载,准备显示
private void Form1_Load(object sender, EventArgs e)
{
Otg.DoOnShow();
cbx_Type.SelectedIndex = ;
}
#endregion #region 事件:选中一个元素触发,选中井元素,将井号赋给文本框
private void axOTGisForm1_OnSelectedOneElement(object sender, AxOTGisX.IOTGisFormEvents_OnSelectedOneElementEvent e)
{
txt_Jname.Text = "";
OTMap _OTMap = this.Otg.GetActiveMap();
OTElement _OTElement = _OTMap.GetSelectedElement();
OTWell _OTWell;
if (_OTElement != null && _OTElement.ElementClassCodeID == ElementType.etWell)
{
_OTWell = (OTWell)_OTElement;
txt_Jname.Text = _OTWell.TextStr.Trim();
}
}
#endregion #region 修改
private void button1_Click(object sender, EventArgs e)
{ OTMap _OTMap = this.Otg.GetActiveMap();
OTElement _OTElement = _OTMap.GetSelectedElement(); if (_OTElement != null && _OTElement.ElementClassCodeID == ElementType.etWell)
{
OTWell aOtwell = (OTWell)_OTElement;
if (txt_Jname.Text.Trim().Length > )
{
aOtwell.TextStr = txt_Jname.Text.Trim();
OTLayer _OTLayer = aOtwell.GetParentLayer();
aOtwell.UpDatePosInfo();
_OTMap.UpdateAllPosition();
Otg.Refresh();
}
else
{
MessageBox.Show("请输入更改的井号名!");
}
}
}
#endregion #region 保存更改
private void button2_Click(object sender, EventArgs e)
{
Otg.SaveCurrentFile();
} #endregion #region 关闭
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Otg.ClearUI();
this.Dispose();
this.Close();
}
#endregion #region 添加图件
private void btn_add_tj_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txt_tj_mc.Text.Trim()))
{ MessageBox.Show("图件名称不能为空");
txt_tj_mc.Focus();
return;
}
if (string.IsNullOrEmpty(txt_blc.Text.Trim()))
{
MessageBox.Show("比例尺不能为空");
txt_blc.Focus();
return;
}
if (string.IsNullOrEmpty(txt_zs_x.Text.Trim()))
{ MessageBox.Show("左上X不能为空");
txt_zs_x.Focus();
return;
}
if (string.IsNullOrEmpty(txt_zs_y.Text.Trim()))
{ MessageBox.Show("左上Y不能为空");
txt_zs_y.Focus();
return;
}
if (string.IsNullOrEmpty(txt_yx_x.Text.Trim()))
{ MessageBox.Show("右下X不能为空");
txt_yx_x.Focus();
return;
}
if (string.IsNullOrEmpty(txt_yx_y.Text.Trim()))
{ MessageBox.Show("右下Y不能为空");
txt_yx_y.Focus();
return;
} OTMap aOtmap = Otg.CreateNewMap();
aOtmap.MapName = txt_tj_mc.Text;
aOtmap.MapZoomRateX = double.Parse(txt_blc.Text);
aOtmap.MapZoomRateY = double.Parse(txt_blc.Text);
aOtmap.SetMapRect(double.Parse(txt_zs_x.Text), double.Parse(txt_zs_y.Text), double.Parse(txt_yx_x.Text), double.Parse(txt_yx_y.Text));//设置图件范围
aOtmap.SetProjection("XA_80", TOTProjectionType.TMR, TOTCoordinateType.Projection, , , , , , , , , , , , , , , );
switch (cbx_Type.SelectedIndex)
{
case :
aOtmap.CoordinateType = TOTCoordinateType.User;
break;
case :
aOtmap.CoordinateType = TOTCoordinateType.LonLat;
break;
case :
aOtmap.CoordinateType = TOTCoordinateType.Projection;
break;
case :
aOtmap.CoordinateType = TOTCoordinateType.Geodesic;
break; }
aOtmap.UpdateAllPosition(); }
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
#endregion #region 读取图件信息
private void btn_read_tj_Click(object sender, EventArgs e)
{
OTMap aOtmap = Otg.GetActiveMap();
double zx = , zy = , yx = , yy = ;
aOtmap.GetMapRect(out zx, out zy, out yx, out yy);
string temp = "图件名称:" + aOtmap.MapName + Environment.NewLine;
temp += "x轴比例尺是:" + aOtmap.MapZoomRateX + ",y轴比例尺是:" + aOtmap.MapZoomRateY + Environment.NewLine;
temp += "图件的宽,高分别是:" + aOtmap.MapWidth.ToString() + "," + aOtmap.MapHight.ToString() + Environment.NewLine;
temp += "图件坐标左边距,上边距分别是: " + aOtmap.MapLeft.ToString() + "," + aOtmap.MapHight.ToString() + Environment.NewLine;
temp += "左上,右下坐标分别是:" + zx.ToString() + "," + zy.ToString() + "," + yx.ToString() + "," + yy.ToString() + Environment.NewLine;
temp += "基准面列表是:" + aOtmap.GetProjectionParams();
MessageBox.Show(temp);
}
#endregion #region 添加图层
private void btn_add_tc_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txt_tc_mc.Text.Trim()))
{ MessageBox.Show("图层名称不能为空");
txt_tc_mc.Focus();
return;
} OTMap aOtmap = Otg.GetActiveMap();
MessageBox.Show("所属图件是:" + aOtmap.MapName);
OTLayer aOtlayer = aOtmap.CreateNewLayer(txt_tc_mc.Text);
aOtmap.UpdateAllPosition();
Otg.Refresh();
Otg.RefreshMapList();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
#endregion #region 添加井位图
private void btn_add_ty_Click(object sender, EventArgs e)
{
try
{
OTMap aOtmap = Otg.GetActiveMap();
int index = aOtmap.ActiveLayerIndex;//活动图层的索引
OTLayer aOtlayer = aOtmap.GetLayer(index);
MessageBox.Show("所属图层是:" + aOtlayer.LayerName);
OTWell aOtwell = aOtlayer.CreateNewWellElement(, , );
aOtwell.TextStr = txt_ty_mc.Text;
aOtwell.TopSymID = ;
aOtwell.TopSymSize = ;
aOtwell.BottomSymID = ;
aOtwell.BottomSymSize = ;
aOtwell.TopPosX = double.Parse(txt_jkx.Text);
aOtwell.TopPosY = double.Parse(txt_jky.Text);
aOtwell.BottomPosX = double.Parse(txt_jdx.Text);
aOtwell.BottomPosY = double.Parse(txt_jdy.Text);
aOtwell.UpDatePosInfo();
aOtmap.UpdateAllPosition(); }
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
#endregion
}
}
刷新一口井的信息,控件和属性上的值
#region 编辑一口井的图像信息
public void Edit_Well(object sender, EventArgs e)
{
try
{
//10.17新增
CamlBuilder cb = new CamlBuilder();
cb.AddWhere(OperationSymbol.Contains, "jwty_point", ConstInfo.W_sort, ConstInfo.文本);
DataSet ds = OperatePort.SearchDataList(ConstInfo.ListName_Jwty, cb.GetCamlString(), null);
if (!Common.JudgeDs(ds))
{ OTMap aOtmap = axOtg.GetActiveMap();
OTElement _OTElement = aOtmap.GetSelectedElement();
if (_OTElement != null && _OTElement.ElementClassCodeID == ElementType.etWell)
{
OTWell aOtwell = (OTWell)_OTElement;
aOtwell.TextStr = ConstInfo.J_Number;
aOtwell.TopSymID = int.Parse(ds.Tables[].Rows[]["jkfhlx_id"].ToString());//井口符号类型ID;
aOtwell.TopSymSize = double.Parse(ds.Tables[].Rows[]["jkfhlxdx"].ToString());//井口符号大小;
aOtwell.BottomSymID = int.Parse(ds.Tables[].Rows[]["jdfhlx_id"].ToString());//井底符号类型ID;
aOtwell.BottomSymSize = double.Parse(ds.Tables[].Rows[]["jdfhdx"].ToString());//井底符号大小
aOtwell.TopPosX = ConstInfo.J_jkx - ;
aOtwell.TopPosY = ConstInfo.J_jky;
aOtwell.BottomPosX = ConstInfo.J_jdx - ;
aOtwell.BottomPosY = ConstInfo.J_jdy;
aOtwell.TextHeight = ;
aOtwell.UpDatePosInfo();//更新井的信息
aOtmap.UpdateAllPosition();//跟新井的图像位置
//axOtg.RefreshMapList();
//axOtg.RefreshToolbarPosition();
this.axOtg.Refresh();//刷新井的名字
aOtwell.ShowProperty();//刷新属性
} }
else
{
sh.Message("不存在该井的类别!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString()); }
}
#endregion
删除某一层
private void btn_Download_Click(object sender, EventArgs e)
{
SaveFileDialog sw = new SaveFileDialog();
sw.Filter = "*.OTP|*.*";
sw.FilterIndex = ;
sw.Title = this.Text;
sw.RestoreDirectory = true;
if (sw.ShowDialog() == DialogResult.OK)
{
string path = sw.FileName.ToString() + ".OTP";
for (int j = ; j < axOTGisForm1.Count(); j++)
{
OTMap fMap = axOTGisForm1.GetMap(j);
for (int i = ; i < fMap.Count(); i++)
{
OTLayer aOtlayer = fMap.GetLayer(i);
string layerN = aOtlayer.LayerName.ToString().Trim();
if (j == && layerN.Length >= && layerN.Substring(, ) == "")
{
fMap.RemoveLayer(i);
}
if (cmb_imageType.Text.Trim() == "黑白图" && layerN.Length >= && layerN.Substring(, ) == "")//去彩色线
{
fMap.RemoveLayer(i);
}
if (cmb_imageType.Text.Trim() == "彩色图" && layerN.Length >= && layerN.Substring(, ) == "")//去黑白线
{
fMap.RemoveLayer(i);
}
}
fMap.UpdateAllPosition();
}
int temp =axOTGisForm1.SaveToFile(path, );
if (temp == )
{
MessageBox.Show("保存成功", "温馨提示");
this.Close();
}
else
{
MessageBox.Show("保存异常", "温馨提示");
}
} }