电子围栏模拟

时间:2021-01-22 17:17:02

关于电子围栏简单模拟

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ClientSpace;

namespace 电子围栏
{  //只要在地图中加入墨西哥州地图即可简易模拟电子围栏功能
    public partial class Form1 : Form
    {
       // private MapOperation m_mapOperation;
        private MapObjects2.Polygon m_enclosure = new MapObjects2.PolygonClass();//.Polygon();
        private MapObjects2.Point pt = new MapObjects2.PointClass();
        public Form1()
        {
            InitializeComponent();
        //  m_mapOperation = new MapOperation();//实例化MapOperation
        //  m_mapOperation.SetAxMap(this.axMap1, this.axMap2);
        }

        private void button1_Click(object sender, EventArgs e)
        { //测试 pt点是否在所选的m_enclosure区域中
           pt.X=-99;
           pt.Y=24;
           if (m_enclosure.IsPointIn(pt) == false)
           {
               //此处应该添加事件,以提示系统某点是否越界或已经不在围栏
               MessageBox.Show("不在其中");
           }
           else
           {
               MessageBox.Show("在其中");
           }
         
        }

        private void axMap1_MouseDownEvent(object sender, AxMapObjects2._DMapEvents_MouseDownEvent e)
        {
            MapObjects2.Polygon polygonLimit = axMap1.TrackPolygon();
            m_enclosure = polygonLimit;
            axMap1.TrackingLayer.Refresh(true, null);
         
        }

        private void axMap1_AfterTrackingLayerDraw(object sender, AxMapObjects2._DMapEvents_AfterTrackingLayerDrawEvent e)
        {
            if (m_enclosure != null)
            {
                MapObjects2.Symbol symLine = new MapObjects2.SymbolClass();
                symLine.SymbolType = MapObjects2.SymbolTypeConstants.moFillSymbol;
                symLine.Style = (short)MapObjects2.FillStyleConstants.moTransparentFill;
                symLine.OutlineColor = (uint)MapObjects2.ColorConstants.moRed;
                symLine.Size = 3;

                axMap1.DrawShape(m_enclosure, symLine);
            }
        }

        private void axMap1_MouseMoveEvent(object sender, AxMapObjects2._DMapEvents_MouseMoveEvent e)
        {
            MapObjects2.Point pt;
            pt = axMap1.ToMapPoint(e.x, e.y);
            this.textBox1.Text = "经度:" + pt.X.ToString("F4");
            this.textBox2.Text = "纬度:" + pt.Y.ToString("F4");
        }
    }
}