⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 map.cs

📁 gps
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace GPSClassLibrary
{
    /// <summary>
    /// 图片号,坐标的结果
    /// </summary>
    public struct MapPoint
    {
        public Point point;// 
        public int IndexOfMap;// 
        /// <summary>
        /// 构造
        /// </summary>
        /// <param name="p">在地图上的位置</param>
        /// <param name="idx">地图的索引号</param>
        public MapPoint(Point p, int idx)
        {
            point = p;
            IndexOfMap = idx;
        }
        /// <summary>
        /// 构造
        /// </summary>
        /// <param name="obj">被复制的对象</param>
        public MapPoint(MapPoint obj)
        {
            point = obj.point;
            IndexOfMap = obj.IndexOfMap;
        }
        /// <summary>
        /// 构造
        /// </summary>
        /// <param name="str">符合导出字符串格式的字符串</param>
        public MapPoint(string str)
        {
            string[] strSplit = str.Split(@" ".ToCharArray());
            this.IndexOfMap = int.Parse(strSplit[0]);
            this.point = new Point(int.Parse(strSplit[1]), int.Parse(strSplit[2]));
        }
        /// <summary>
        /// MapPoint 的!= 定义
        /// </summary>
        /// <param name="A">左操作数</param>
        /// <param name="B">右操作数</param>
        /// <returns>不等为真,等为假</returns>
        public static bool operator != (MapPoint A,MapPoint B)
        {
            if (A.Equals(B))
                return false;
            return true;
        }
        /// <summary>
        /// 等于判断
        /// </summary>
        /// <param name="A"></param>
        /// <param name="B"></param>
        /// <returns></returns>
        public static bool operator ==(MapPoint A, MapPoint B)
        {
            if (A.Equals(B))
                return true;
            return false;
        }
        /// <summary>
        /// Equals重载
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            MapPoint B = (MapPoint)obj;
            if (point == B.point && IndexOfMap == B.IndexOfMap)
                return true;
            return false;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
        /// <summary>
        /// 导出文本
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return this.IndexOfMap.ToString() + " "
            + this.point.X.ToString() + " "
            + this.point.Y.ToString();
        }
    }
    public class Map
    {
        // 轨迹记录
        TraceRecord traceRecord = new TraceRecord();
        // 是否导航追踪
        bool InditeToDisplay = false;

        // 最大坐标和地图大小
        Size maxSize = new Size(4999, 4499);
        Size MapSize = new Size(1000, 900);
        #region Private
        // 现实位置
        Point realPoint = Point.Empty;
        // 当前图显位置
        MapPoint curPosition = new MapPoint(new Point(0, 0), 0);
        // 当前坐标
        Point curPoint = new Point(0, 0);
        // 前一坐标
        Point  lstPoint = new Point(0,0);
        // 方向角度
        float angle_direct = 0.0f;
        // 图形设备
        Graphics graphics;
        // 地图左上角的点
        Point left_top;
        // 方向标图
        Image dr_gif;
        // 地图图片的径
        string MapPath;
        // 显示大小
        Size clientSize;
        // 速度
        double speed = 0;
        // 地图的真实大小
        SizeF realSize = new SizeF(5000 * 10000, 4500 * 10000);
        // 上一真实位置
        PointF lstRealPoint = new PointF(0, 0);

        #region 定位信息
        // 海拔高度
        double Height;
        // 纬度
        double Latitude;
        // 续度类型
        LatitudeType LatitudeType;
        // 经度
        double Longitude;
        // 经度类型
        LongitudeType LongitudeType;
        #endregion

        #endregion

        #region Attribute
        private Point RealPoint
        {
            set 
            {
                this.CurPoint = value;
                realPoint = value;
            }
        }
        /// <summary>
        /// 是否追踪导航
        /// </summary>
        public bool TrackGuide
        {
            set
            {
                InditeToDisplay = value;
            }
        }
        /// <summary>
        /// 是否显示轨迹
        /// </summary>
        public bool ShowTrace
        {
            set
            {
                this.traceRecord.ShowTrace = value;
            }
        }
        /// <summary>
        /// 是否记录轨迹
        /// </summary>
        public bool RecordTrace
        {
            set
            {
                this.traceRecord.RecordTrace = value;
            }
        }
        /// <summary>
        /// 光标的当前坐标
        /// </summary>
        private Point CurPoint
        {
            set
            {
                lstPoint = curPoint;
                curPoint = value;
                // 坐标错误处理
                curPoint.X = curPoint.X < 0 ? 0 : curPoint.X;
                curPoint.Y = curPoint.Y < 0 ? 0 : curPoint.Y;
                curPoint.X = curPoint.X > maxSize.Width ? maxSize.Width : curPoint.X;
                curPoint.Y = curPoint.Y > maxSize.Height ? maxSize.Height : curPoint.Y;
                
                // 计算方向
                if (lstPoint != curPoint)
                {
                    int x = curPoint.X - lstPoint.X;
                    int y = curPoint.Y - lstPoint.Y;
                    if (x == 0)
                        angle_direct = y >= 0 ? 90.0f : -90.0f;
                    else if (y == 0)
                        angle_direct = x > 0 ? 0.0f : 180.0f;
                    else
                        angle_direct = (float)(Math.Atan(y / x) * 180.0 / Math.PI);
                }
                // 计算显示方位
                int i = curPoint.X / MapSize.Width,
                    j = curPoint.Y / MapSize.Height;
                    // 小地图索引号
                curPosition.IndexOfMap = i * 5 + j;
                    // 小地图坐标
                curPosition.point = new Point(curPoint.X % MapSize.Width, curPoint.Y % MapSize.Height);

                // 跟踪显示
                if (InditeToDisplay)
                {
                    left_top.X = curPosition.point.X - clientSize.Width / 2;
                    left_top.Y = curPosition.point.Y - clientSize.Height / 2;
                }
                // 记录轨迹
                traceRecord.Add(curPosition);
                // 显示
                Draw();
            }
            get { return curPoint; }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -