zoukankan      html  css  js  c++  java
  • 矢量做图组件OTGisX的使用(类似Mapbase)

    一:组件添加到工具栏

    要在应用程序中应用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 = 0;
                }
            #endregion
    
            #region 事件:选中一个元素触发,选中井元素,将井号赋给文本框
                private void axOTGisForm1_OnSelectedOneElement(object sender, AxOTGisX.IOTGisFormEvents_OnSelectedOneElementEvent e)
                {
                    txt_Jname.Text = "";
                    OTMap _OTMap = this.Otg.GetActiveMap();
                    OTElement _OTElement = _OTMap.GetSelectedElement(0);
                    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(0);
    
                    if (_OTElement != null && _OTElement.ElementClassCodeID == ElementType.etWell)
                    {
                        OTWell aOtwell = (OTWell)_OTElement;
                        if (txt_Jname.Text.Trim().Length > 0)
                        {
                            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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                        switch (cbx_Type.SelectedIndex)
                        {
                            case 0:
                                aOtmap.CoordinateType = TOTCoordinateType.User;
                                break;
                            case 1:
                                aOtmap.CoordinateType = TOTCoordinateType.LonLat;
                                break;
                            case 2:
                                aOtmap.CoordinateType = TOTCoordinateType.Projection;
                                break;
                            case 3:
                                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 = 0, zy = 0, yx = 0, yy = 0;
                    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(1, 1, 1);
                            aOtwell.TextStr = txt_ty_mc.Text;
                            aOtwell.TopSymID = 24430001;
                            aOtwell.TopSymSize = 50;
                            aOtwell.BottomSymID = 24430001;
                            aOtwell.BottomSymSize = 80;
                            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(0);
                            if (_OTElement != null && _OTElement.ElementClassCodeID == ElementType.etWell)
                            {
                                OTWell aOtwell = (OTWell)_OTElement;
                                aOtwell.TextStr = ConstInfo.J_Number;
                                aOtwell.TopSymID = int.Parse(ds.Tables[0].Rows[0]["jkfhlx_id"].ToString());//井口符号类型ID;
                                aOtwell.TopSymSize = double.Parse(ds.Tables[0].Rows[0]["jkfhlxdx"].ToString());//井口符号大小;
                                aOtwell.BottomSymID = int.Parse(ds.Tables[0].Rows[0]["jdfhlx_id"].ToString());//井底符号类型ID;
                                aOtwell.BottomSymSize = double.Parse(ds.Tables[0].Rows[0]["jdfhdx"].ToString());//井底符号大小
                                aOtwell.TopPosX = ConstInfo.J_jkx - 19000000;
                                aOtwell.TopPosY = ConstInfo.J_jky;
                                aOtwell.BottomPosX = ConstInfo.J_jdx - 19000000;
                                aOtwell.BottomPosY = ConstInfo.J_jdy;
                                aOtwell.TextHeight = 10;
                                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 = 2;
                sw.Title = this.Text;
                sw.RestoreDirectory = true;
                if (sw.ShowDialog() == DialogResult.OK)
                {
                    string path = sw.FileName.ToString() + ".OTP";
                    for (int j = 0; j < axOTGisForm1.Count(); j++)
                    {
                        OTMap fMap = axOTGisForm1.GetMap(j);
                        for (int i = 0; i < fMap.Count(); i++)
                        {
                            OTLayer aOtlayer = fMap.GetLayer(i);
                            string layerN = aOtlayer.LayerName.ToString().Trim();
                            if (j == 1 && layerN.Length >= 4 && layerN.Substring(0, 4) == "1000")
                            {
                                fMap.RemoveLayer(i);
                            }
                            if (cmb_imageType.Text.Trim() == "黑白图" && layerN.Length >= 4 && layerN.Substring(3, 1) == "2")//去彩色线
                            {
                                fMap.RemoveLayer(i);
                            }
                            if (cmb_imageType.Text.Trim() == "彩色图" && layerN.Length >= 4 && layerN.Substring(3, 1) == "1")//去黑白线
                            {
                                fMap.RemoveLayer(i);
                            }
                        }
                        fMap.UpdateAllPosition();
                    }
                    int temp =axOTGisForm1.SaveToFile(path, 1);
                    if (temp == 0)
                    {
                        MessageBox.Show("保存成功", "温馨提示");
                        this.Close();
                    }
                    else 
                    {
                        MessageBox.Show("保存异常", "温馨提示");
                    }
                }
      
            }
  • 相关阅读:
    简单理解Socket
    进程间8种通信方式详解
    底部漂浮DIV
    Table样式
    QQ授权登录
    C#_批量插入数据到Sqlserver中的四种方式
    Asp.Net_单点登录
    html之meta详解
    程序员常用工具
    工厂模式理解
  • 原文地址:https://www.cnblogs.com/hongmaju/p/4271666.html
Copyright © 2011-2022 走看看