public Task <Stream> ReverseGeocodeStreamAsync(LatLngPoint latLng, IProgress prog = null)
 {
     return(Cache.GetStreamAsync(new ReverseGeocodingRequest(ApiKey)
     {
         Location = latLng
     }, prog));
 }
 /// <summary>
 /// 绘制方法
 /// </summary>
 /// <param name="g"></param>
 /// <param name="center"></param>
 /// <param name="zoom"></param>
 /// <param name="screen_size"></param>
 public override void Draw(Graphics g, LatLngPoint center, int zoom, Size screen_size)
 {
     g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
     using (SolidBrush sb = new SolidBrush(Color.FromArgb(100, Color.White)))
     {
         g.FillRectangle(sb, new Rectangle(LeftTop, new Size(Width, Height)));
     }
     using (Pen pen = new Pen(Color.Black))
     {
         g.DrawRectangle(pen, new Rectangle(LeftTop, new Size(Width, Height)));
     }
     using (SolidBrush sb = new SolidBrush(Color.Black))
     {
         //移动柄
         g.FillRectangle(sb, new Rectangle(new Point(LeftTop.X - 3, LeftTop.Y - 3), new Size(6, 6)));
         g.FillRectangle(sb, new Rectangle(new Point(LeftTop.X - 3 + Width / 2, LeftTop.Y - 3), new Size(6, 6)));
         g.FillRectangle(sb, new Rectangle(new Point(LeftTop.X - 3 + Width, LeftTop.Y - 3), new Size(6, 6)));
         g.FillRectangle(sb, new Rectangle(new Point(LeftTop.X - 3 + Width, LeftTop.Y - 3 + Height / 2), new Size(6, 6)));
         g.FillRectangle(sb, new Rectangle(new Point(LeftTop.X - 3 + Width, LeftTop.Y - 3 + Height), new Size(6, 6)));
         g.FillRectangle(sb, new Rectangle(new Point(LeftTop.X - 3 + Width / 2, LeftTop.Y - 3 + Height), new Size(6, 6)));
         g.FillRectangle(sb, new Rectangle(new Point(LeftTop.X - 3, LeftTop.Y - 3 + Height), new Size(6, 6)));
         g.FillRectangle(sb, new Rectangle(new Point(LeftTop.X - 3, LeftTop.Y - 3 + Height / 2), new Size(6, 6)));
         //高宽
         g.FillRectangle(sb, new Rectangle(new Point(LeftTop.X - 2, LeftTop.Y - 23), new Size(60, 18)));
         using (Font f = new Font("微软雅黑", 9))
         {
             g.DrawString(Width + "×" + Height, f, Brushes.White, new PointF(LeftTop.X - 1, LeftTop.Y - 21));
         }
     }
 }
Exemple #3
0
 /// <summary>
 /// 更新最后一点
 /// </summary>
 /// <param name="p"></param>
 public void UpdateTheEnd(LatLngPoint p)
 {
     if (Points != null)
     {
         Points[Points.Count - 1] = p;
     }
 }
Exemple #4
0
 /// <summary>
 /// 更新最后一点
 /// </summary>
 /// <param name="p"></param>
 public void UpdateTheEnd(LatLngPoint p)
 {
     if (Points != null)
     {
         Points[Points.Count - 1] = p;
     }
 }
        private bool ParseSearchParams(string searchLocation, out string searchPano, out LatLngPoint searchPoint)
        {
            searchPano  = null;
            searchPoint = null;

            if (!string.IsNullOrEmpty(searchLocation))
            {
                var panoMatch   = GMAPS_URL_PANO_PATTERN.Match(searchLocation);
                var latLngMatch = GMAPS_URL_LATLNG_PATTERN.Match(searchLocation);

                if (panoMatch.Success && MetadataResponse.IsPano(panoMatch.Groups[1].Value))
                {
                    searchPano = panoMatch.Groups[1].Value;
                }
                else if (MetadataResponse.IsPano(searchLocation))
                {
                    searchPano = searchLocation;
                }

                if (latLngMatch.Success && LatLngPoint.TryParse(latLngMatch.Groups[1].Value, out var point))
                {
                    searchPoint = point;
                }
                else if (LatLngPoint.TryParse(searchLocation, out var point2))
                {
                    searchPoint = point2;
                }
            }

            return(metadata == null ||
                   searchPano != null &&
                   metadata.Pano_ID != searchPano ||
                   searchPoint != null &&
                   searchPoint.Distance(metadata.Location) > 3f);
        }
        private static bool OutOfChina(LatLngPoint point)
        {
            double lng = point.LonX;
            double lat = point.LatY;

            return((lng < 72.004 || lng > 137.8347) || ((lat < 0.8293 || lat > 55.8271) || false));
        }
Exemple #7
0
 /// <summary>
 /// 绘制方法
 /// </summary>
 /// <param name="g">画布</param>
 /// <param name="center">地图中心点</param>
 /// <param name="zoom">地图缩放级别</param>
 /// <param name="screen_size">地图大小</param>
 public override void Draw(System.Drawing.Graphics g, LatLngPoint center, int zoom, System.Drawing.Size screen_size)
 {
     if (Points != null && Points.Count >= 2)
     {
         g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
         List <Point> l = new List <Point>();
         foreach (LatLngPoint p in Points)
         {
             l.Add(MapHelper.GetScreenLocationByLatLng(p, center, zoom, screen_size));
         }
         using (Pen pen = new Pen(Color.FromArgb(150, Color.Blue), 4))
         {
             if (Points.Count == 2)
             {
                 g.DrawLine(pen, l[0], l[1]);
             }
             else
             {
                 using (SolidBrush sb = new SolidBrush(Color.FromArgb(30, Color.Blue)))
                 {
                     g.FillPolygon(sb, l.ToArray());
                 }
                 g.DrawPolygon(pen, l.ToArray());
             }
         }
     }
 }
Exemple #8
0
        public Bitmap ConvertToSquare(Bitmap img, Point leftTop, Point rightTop, Point leftBottom, Point rightBottom)
        {
            int WEIGHT = PIC_SIZE - 1;

            loadBitMap(img);
            destBitmap = new Bitmap(PIC_SIZE, PIC_SIZE);
            double      topSlopeX = ((double)(rightTop.X - leftTop.X)) / WEIGHT;
            double      bottomSlopeX = ((double)(rightBottom.X - leftBottom.X)) / WEIGHT;
            double      topSlopeY = ((double)(leftTop.Y - rightTop.Y)) / WEIGHT;
            double      bottomSlopeY = ((double)(leftBottom.Y - rightBottom.Y)) / WEIGHT;
            LatLngPoint top, bottom;

            for (int i = 0; i < PIC_SIZE; i++)
            {
                top    = new LatLngPoint(i * topSlopeX + leftTop.X, leftTop.Y - i * topSlopeY);
                bottom = new LatLngPoint(i * bottomSlopeX + leftBottom.X, leftBottom.Y - i * bottomSlopeY);

                for (int j = 0; j < PIC_SIZE; j++)
                {
                    SetPixel(i, j, FourSquareAvg(img, new LatLngPoint((top.Lng * (WEIGHT - j) + bottom.Lng * j) / WEIGHT, (top.Lat * (WEIGHT - j) + bottom.Lat * j) / WEIGHT)));
                }
            }
            destBitmap = packetBitMap();
            return(destBitmap);
        }
Exemple #9
0
        public int FourSquareAvg(Bitmap img, LatLngPoint exactlyPoint)
        {
            int    minX             = Convert.ToInt32(Math.Floor(exactlyPoint.Lng));
            int    minY             = Convert.ToInt32(Math.Floor(exactlyPoint.Lat));
            int    leftTopBytes     = GetPixel(minX, minY);
            int    rightTopBytes    = GetPixel(minX + 1, minY);
            int    leftBottomBytes  = GetPixel(minX, minY + 1);
            int    rightBottomBytes = GetPixel(minX + 1, minY + 1);
            double deltX            = exactlyPoint.Lng - minX;
            double deltY            = exactlyPoint.Lat - minY;
            int    result;

            unsafe
            {
                byte *leftTop = (byte *)&leftTopBytes, rightTop = (byte *)&rightTopBytes, leftBottom = (byte *)&leftBottomBytes, rightBottom = (byte *)&rightBottomBytes;
                byte  colorR = (byte)((leftTop[2] * (1 - deltX) + deltX * rightTop[2]) * (1 - deltY) + deltY * (leftBottom[2] * (1 - deltX) + deltX * rightBottom[2]));
                byte  colorB = (byte)((leftTop[0] * (1 - deltX) + deltX * rightTop[0]) * (1 - deltY) + deltY * (leftBottom[0] * (1 - deltX) + deltX * rightBottom[0]));
                byte  colorG = (byte)((leftTop[1] * (1 - deltX) + deltX * rightTop[1]) * (1 - deltY) + deltY * (leftBottom[1] * (1 - deltX) + deltX * rightBottom[1]));
                byte  colorA = (byte)((leftTop[3] * (1 - deltX) + deltX * rightTop[3]) * (1 - deltY) + deltY * (leftBottom[3] * (1 - deltX) + deltX * rightBottom[3]));
                result = ((colorA << 24) | (colorR << 16) | (colorG << 8) | colorB);
            }
            if (result == 0)
            {
                result = 16777215;
            }
            return(result);
        }
Exemple #10
0
    //百度坐标转墨卡托
    private static PointF LatLng2Mercator(LatLngPoint p)
    {
        double[] arr   = null;
        double   n_lat = p.Lat > 74 ? 74 : p.Lat;

        n_lat = n_lat < -74 ? -74 : n_lat;
        for (var i = 0; i < array1.Length; i++)
        {
            if (p.Lat >= array1[i])
            {
                arr = array2[i];
                break;
            }
        }
        if (arr == null)
        {
            for (var i = array1.Length - 1; i >= 0; i--)
            {
                if (p.Lat <= -array1[i])
                {
                    arr = array2[i];
                    break;
                }
            }
        }
        double[] res = Convertor(p.Lng, p.Lat, arr);
        return(new PointF((float)res[0], (float)res[1]));
    }
Exemple #11
0
        /// <summary>
        /// Calculate the position of the Sun at the given time as an azimuth and altitude bearing
        /// from the given location on spaceship Earth. /// SEE: https://en.wikipedia.org/wiki/Position_of_the_Sun
        /// </summary>
        /// <param name="location">The position of the viewer on earth</param>
        /// <param name="time">The time of day</param>
        /// <returns>The position of the sun in the sky</returns>
        public static HorizontalSphericalPosition ToSunPosition(this LatLngPoint location, DateTime time)
        {
            var n  = time.ToJulianDays();
            var ec = n.ToGeocentricEclipticSphericalFromJulianDay();
            var eq = ec.ToEquitorial(n);

            return(eq.ToHorizontal(location, n));
        }
 public Task <Stream> GetMetadataStreamAsync(LatLngPoint latLng, int searchRadius = 50, IProgress prog = null)
 {
     return(Cache.GetStreamAsync(new MetadataRequest(ApiKey, SigningKey)
     {
         Location = latLng,
         Radius = searchRadius
     }, prog));
 }
Exemple #13
0
 /// <summary>
 /// 绘制方法
 /// </summary>
 /// <param name="g">画布</param>
 /// <param name="center">中心</param>
 /// <param name="zoom">地图缩放级别</param>
 /// <param name="screen_size">地图大小</param>
 public override void Draw(System.Drawing.Graphics g, LatLngPoint center, int zoom, System.Drawing.Size screen_size)
 {
     g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
     if (_points_arounds == null)
     {
         _points_arounds = new List <LatLngPoint>();
     }
 }
Exemple #14
0
 private void _add1stLocation(object sender, RoutedEventArgs e, LatLngPoint lc)
 {
     MeasureLocation1 = lc;
     if (_measureLocation2 != null)
     {
         MeasuredDistance = MeasureLocation1.GetDistance(MeasureLocation2);
     }
 }
Exemple #15
0
        /// <summary>
        /// 绘制方法
        /// </summary>
        /// <param name="g"></param>
        /// <param name="center"></param>
        /// <param name="zoom"></param>
        /// <param name="screen_size"></param>
        public override void Draw(System.Drawing.Graphics g, LatLngPoint center, int zoom, System.Drawing.Size screen_size)
        {
            if (Points != null && Points.Count >= 2)
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                List <Point> l = new List <Point>();
                foreach (LatLngPoint p in Points)
                {
                    l.Add(MapHelper.GetScreenLocationByLatLng(p, center, zoom, screen_size));  //屏幕坐标
                }

                double total = 0; double step = 0;
                using (Pen pen = new Pen(Color.FromArgb(150, Color.OrangeRed), 4))
                {
                    for (int i = 0; i < l.Count - 1; ++i)
                    {
                        g.DrawLine(pen, l[i], l[i + 1]);
                        g.FillEllipse(Brushes.White, new Rectangle(new Point(l[i].X - 4, l[i].Y - 4), new Size(8, 8)));
                        g.DrawEllipse(Pens.OrangeRed, new Rectangle(new Point(l[i].X - 4, l[i].Y - 4), new Size(8, 8)));

                        if (i == 0)  //起点
                        {
                            g.FillRectangle(Brushes.White, new Rectangle(l[i].X + 3, l[i].Y, 35, 20));
                            g.DrawRectangle(Pens.DarkGray, new Rectangle(l[i].X + 3, l[i].Y, 35, 20));
                            g.DrawString("起点", new Font("微软雅黑", 9), Brushes.OrangeRed, new PointF(l[i].X + 6, l[i].Y + 2));

                            if (i == l.Count - 2)  //终点 只有两点的时候
                            {
                                step   = MapHelper.GetDistanceByLatLng(Points[i], Points[i + 1]);
                                total += step;

                                g.FillRectangle(Brushes.White, new Rectangle(l[i + 1].X + 3, l[i + 1].Y, 90, 20));
                                g.DrawRectangle(Pens.DarkGray, new Rectangle(l[i + 1].X + 3, l[i + 1].Y, 90, 20));
                                g.DrawString("总长:" + Math.Round(total, 2) + "公里", new Font("微软雅黑", 9), Brushes.OrangeRed, new PointF(l[i + 1].X + 10, l[i + 1].Y + 2));
                            }
                        }
                        else //其它点
                        {
                            step   = MapHelper.GetDistanceByLatLng(Points[i - 1], Points[i]);
                            total += step;

                            g.FillRectangle(Brushes.White, new Rectangle(l[i].X + 3, l[i].Y, 70, 20));
                            g.DrawRectangle(Pens.DarkGray, new Rectangle(l[i].X + 3, l[i].Y, 70, 20));
                            g.DrawString(Math.Round(step, 2) + "公里", new Font("微软雅黑", 9), Brushes.OrangeRed, new PointF(l[i].X + 10, l[i].Y + 2));

                            if (i == l.Count - 2)  //终点
                            {
                                step   = MapHelper.GetDistanceByLatLng(Points[i], Points[i + 1]);
                                total += step;
                                g.FillRectangle(Brushes.White, new Rectangle(l[i + 1].X + 3, l[i + 1].Y, 100, 20));
                                g.DrawRectangle(Pens.DarkGray, new Rectangle(l[i + 1].X + 3, l[i + 1].Y, 100, 20));
                                g.DrawString("总长:" + Math.Round(total, 2) + "公里", new Font("微软雅黑", 9), Brushes.OrangeRed, new PointF(l[i + 1].X + 10, l[i + 1].Y + 2));
                            }
                        }
                    }
                }
            }
        }
Exemple #16
0
        /// <summary>
        /// 绘制方法
        /// </summary>
        /// <param name="g"></param>
        /// <param name="center"></param>
        /// <param name="zoom"></param>
        /// <param name="screen_size"></param>
        public override void Draw(System.Drawing.Graphics g, LatLngPoint center, int zoom, System.Drawing.Size screen_size)
        {
            if (Points != null && Points.Count >= 2)
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                List<Point> l = new List<Point>();
                foreach (LatLngPoint p in Points)
                {
                    l.Add(MapHelper.GetScreenLocationByLatLng(p, center, zoom, screen_size));  //屏幕坐标
                }
                
                double total = 0; double step = 0;
                using (Pen pen = new Pen(Color.FromArgb(150, Color.OrangeRed), 4))
                {
                    for (int i = 0; i < l.Count - 1; ++i)
                    {
                        g.DrawLine(pen, l[i], l[i + 1]);
                        g.FillEllipse(Brushes.White, new Rectangle(new Point(l[i].X - 4, l[i].Y - 4), new Size(8, 8)));
                        g.DrawEllipse(Pens.OrangeRed, new Rectangle(new Point(l[i].X - 4, l[i].Y - 4), new Size(8, 8)));

                        if (i == 0)  //起点
                        {
                            g.FillRectangle(Brushes.White, new Rectangle(l[i].X + 3, l[i].Y, 35, 20));
                            g.DrawRectangle(Pens.DarkGray, new Rectangle(l[i].X + 3, l[i].Y, 35, 20));
                            g.DrawString("起点", new Font("微软雅黑", 9), Brushes.OrangeRed, new PointF(l[i].X + 6, l[i].Y + 2));

                            if (i == l.Count - 2)  //终点 只有两点的时候
                            {
                                step = MapHelper.GetDistanceByLatLng(Points[i], Points[i + 1]);
                                total += step;

                                g.FillRectangle(Brushes.White, new Rectangle(l[i + 1].X + 3, l[i + 1].Y, 90, 20));
                                g.DrawRectangle(Pens.DarkGray, new Rectangle(l[i + 1].X + 3, l[i + 1].Y, 90, 20));
                                g.DrawString("总长:" + Math.Round(total,2) + "公里", new Font("微软雅黑", 9), Brushes.OrangeRed, new PointF(l[i + 1].X + 10, l[i + 1].Y + 2));
                            }
                        }
                        else //其它点
                        {
                            step = MapHelper.GetDistanceByLatLng(Points[i-1], Points[i]);
                            total += step;

                            g.FillRectangle(Brushes.White, new Rectangle(l[i].X + 3, l[i].Y, 70, 20));
                            g.DrawRectangle(Pens.DarkGray, new Rectangle(l[i].X + 3, l[i].Y, 70, 20));
                            g.DrawString(Math.Round(step,2) + "公里", new Font("微软雅黑", 9), Brushes.OrangeRed, new PointF(l[i].X + 10, l[i].Y + 2));

                            if (i == l.Count - 2)  //终点
                            {
                                step = MapHelper.GetDistanceByLatLng(Points[i], Points[i + 1]);
                                total += step;
                                g.FillRectangle(Brushes.White, new Rectangle(l[i + 1].X + 3, l[i + 1].Y, 100, 20));
                                g.DrawRectangle(Pens.DarkGray, new Rectangle(l[i + 1].X + 3, l[i + 1].Y, 100, 20));
                                g.DrawString("总长:" + Math.Round(total, 2) + "公里", new Font("微软雅黑", 9), Brushes.OrangeRed, new PointF(l[i + 1].X + 10, l[i + 1].Y + 2));
                            }
                        }
                    }
                }
            }
        }
        private async Task SearchData(string searchPano, LatLngPoint searchPoint, IProgress prog)
        {
            prog.Report(0);

            metadata = await gmaps.SearchMetadataAsync(searchLocation, searchPano, searchPoint, searchRadius, prog)
                       .ConfigureAwait(false);

            if (metadata != null)
            {
                searchPoint    = metadata.Location;
                searchLocation = searchPano = metadata.Pano_ID;

                if (lastSphere == null)
                {
                    origin = metadata.Location;
                }

                if (gps != null)
                {
                    gps.FakeCoord = true;
                    gps.Coord     = metadata.Location;
                }

#if UNITY_EDITOR
                if (locationInput != null)
                {
                    locationInput.value = searchLocation;
                }
#endif

                loadingBar.Activate();
                var curSphere = await GetPhotosphere();

                if (lastSphere != null)
                {
                    await JuniperSystem.OnMainThreadAsync(lastSphere.Deactivate);
                }

                await JuniperSystem.OnMainThreadAsync(curSphere.Activate);

                if (lastSphere == null)
                {
                    await prog.WaitOnAsync(curSphere, "Loading photosphere");

                    Complete();
                }

                await JuniperSystem.OnMainThreadAsync(() =>
                {
                    avatar.transform.position    = GetRelativeVector3(metadata);
                    curSphere.transform.position = avatar.Head.position;
                });

                prog.Report(1);

                lastSphere = curSphere;
            }
        }
Exemple #18
0
        public void Add(LatLngPoint item)
        {
            if (item is null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            Points.Add(item.ToString(CultureInfo.InvariantCulture));
        }
Exemple #19
0
        /// <summary>
        /// 计算瓦片地图的行列号范围
        /// </summary>
        /// <param name="startcoord">左下角经纬度</param>
        /// <param name="endcoord">右上角经纬度</param>
        /// <param name="z">地图层级</param>
        /// <returns></returns>
        public Tuple <int, int, int, int> GetTileBound(LatLngPoint startcoord, LatLngPoint endcoord, int z)
        {
            PointF StartMCPoint   = CoordTransferHelper.LatLng2Mercator(startcoord);
            Point  StartTilePoint = GetTileCoord(StartMCPoint, z);
            PointF EndPoint       = CoordTransferHelper.LatLng2Mercator(endcoord);
            Point  EndTilePoint   = GetTileCoord(EndPoint, z);

            return(new Tuple <int, int, int, int>(StartTilePoint.X, StartTilePoint.Y, EndTilePoint.X, EndTilePoint.Y));
        }
Exemple #20
0
        /// <summary>
        /// 绘制方法
        /// </summary>
        /// <param name="g">画布</param>
        /// <param name="center">中心</param>
        /// <param name="zoom">地图缩放级别</param>
        /// <param name="screen_size">地图大小</param>
        public override void Draw(System.Drawing.Graphics g, LatLngPoint center, int zoom, System.Drawing.Size screen_size)
        {
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            if (_points_arounds == null)
            {
                _points_arounds = new List<LatLngPoint>();

            }
        }
Exemple #21
0
        public bool Remove(LatLngPoint item)
        {
            if (item is null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            return(Remove(item.ToString(CultureInfo.InvariantCulture)));
        }
Exemple #22
0
        /// <summary>
        /// Calculate a rough distance, in meters, between two LatLngPoints.
        /// </summary>
        /// <param name="p">The second point to which to measure</param>
        /// <returns>The distance between the two points, after conversion to UTM</returns>
        public static float Distance(this LatLngPoint A, LatLngPoint B)
        {
            var a  = A.ToUTM();
            var b  = B.ToUTM();
            var dx = b.X - a.X;
            var dy = b.Y - a.Y;

            return((float)Sqrt((dx * dx) + (dy * dy)));
        }
Exemple #23
0
        protected GeometryViewport(SerializationInfo info, StreamingContext context)
        {
            if (info is null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            SouthWest = info.GetValue <LatLngPoint>(SOUTHWEST_FIELD);
            NorthEast = info.GetValue <LatLngPoint>(NORTHEAST_FIELD);
        }
Exemple #24
0
        /// <summary>
        /// 将BD-09坐标转换成GCJ-02坐标
        /// </summary>
        /// <param name="bdPoint">BD-09坐标</param>
        /// <returns>GCJ-02坐标</returns>
        public LatLngPoint BD09ToGCJ02(LatLngPoint bdPoint)
        {
            LatLngPoint _gcjPoint = new LatLngPoint();
            double      _x = bdPoint.LonX - 0.0065, _y = bdPoint.LatY - 0.006;
            double      _z     = Math.Sqrt(_x * _x + _y * _y) - 0.00002 * Math.Sin(_y * pi);
            double      _theta = Math.Atan2(_y, _x) - 0.000003 * Math.Cos(_x * pi);

            _gcjPoint.LonX = _z * Math.Cos(_theta);
            _gcjPoint.LatY = _z * Math.Sin(_theta);
            return(_gcjPoint);
        }
        /// <summary>
        /// 将墨卡托坐标转换成地球坐标(WGS-84)
        /// </summary>
        /// <param name="mercator">墨卡托坐标</param>
        /// <returns>球坐标(WGS-84)</returns>
        public static LatLngPoint MercatorToWGS84(LatLngPoint mercator)
        {
            LatLngPoint _wgsPoint = new LatLngPoint();
            double      _lonX     = mercator.LonX / 20037508.34 * 180;
            double      _latY     = mercator.LatY / 20037508.34 * 180;

            _latY          = 180 / Math.PI * (2 * Math.Atan(Math.Exp(_latY * Math.PI / 180)) - Math.PI / 2);
            _wgsPoint.LonX = _lonX;
            _wgsPoint.LatY = _latY;
            return(_wgsPoint);
        }
        /// <summary>
        /// 将地球坐标(WGS-84)转换成墨卡托坐标
        /// </summary>
        /// <param name="wgsPoint">地球坐标(WGS-84)</param>
        /// <returns>墨卡托坐标</returns>
        public static LatLngPoint WGS84ToMercator(LatLngPoint wgsPoint)
        {
            LatLngPoint _mercatorPoint = new LatLngPoint();
            double      _lonX          = wgsPoint.LonX * 20037508.34 / 180;
            double      _latY          = Math.Log(Math.Tan((90 + wgsPoint.LatY) * Math.PI / 360)) / (Math.PI / 180);

            _latY = _latY * 20037508.34 / 180;
            _mercatorPoint.LonX = _lonX;
            _mercatorPoint.LatY = _latY;
            return(_mercatorPoint);
        }
Exemple #27
0
        /// <summary>
        /// 火星坐标转 (GCJ-02)地球坐标(WGS-84)
        /// </summary>
        /// <param name="gcjPoint">火星坐标转 (GCJ-02)</param>
        /// <returns>地球坐标(WGS-84)</returns>
        public static LatLngPoint GCJ02ToWGS84(LatLngPoint gcjPoint)
        {
            if (GeoHelper.OutOfChina(gcjPoint))
            {
                return(gcjPoint);
            }

            LatLngPoint _transPoint = Transform(gcjPoint);

            return(new LatLngPoint(gcjPoint.LatY - _transPoint.LatY, gcjPoint.LonX - _transPoint.LonX));
        }
        /// <summary>
        ///     将BD-09坐标转换成GCJ-02坐标
        /// </summary>
        /// <param name="bdPoint">BD-09坐标</param>
        /// <returns>GCJ-02坐标</returns>
        public LatLngPoint Bd09ToGcj02(LatLngPoint bdPoint)
        {
            var    latLngPoint = new LatLngPoint();
            double x = bdPoint.LonX - 0.0065, y = bdPoint.LatY - 0.006;
            var    z     = Math.Sqrt(x * x + y * y) - 0.00002 * Math.Sin(y * Pi);
            var    theta = Math.Atan2(y, x) - 0.000003 * Math.Cos(x * Pi);

            latLngPoint.LonX = z * Math.Cos(theta);
            latLngPoint.LatY = z * Math.Sin(theta);
            return(latLngPoint);
        }
        /// <summary>
        ///     将GCJ-02坐标转换成BD-09坐标
        /// </summary>
        /// <param name="gcjPoint">GCJ-02坐标</param>
        /// <returns>BD-09坐标</returns>
        public LatLngPoint Gcj02ToBd09(LatLngPoint gcjPoint)
        {
            var    latLng = new LatLngPoint();
            double x = gcjPoint.LonX, y = gcjPoint.LatY;
            var    z     = Math.Sqrt(x * x + y * y) + 0.00002 * Math.Sin(y * Pi);
            var    theta = Math.Atan2(y, x) + 0.000003 * Math.Cos(x * Pi);

            latLng.LonX = z * Math.Cos(theta) + 0.0065;
            latLng.LatY = z * Math.Cos(theta) + 0.006;
            return(latLng);
        }
Exemple #30
0
        /// <summary>
        /// 地球坐标(WGS-84)转火星坐标 (GCJ-02)
        /// </summary>
        /// <param name="wgsPoint">地球坐标(WGS-84)</param>
        /// <returns>火星坐标 (GCJ-02)</returns>
        public static LatLngPoint WGS84ToGCJ02(LatLngPoint wgsPoint)
        {
            if (GeoHelper.OutOfChina(wgsPoint))
            {
                return(wgsPoint);
            }

            LatLngPoint _transPoint = Transform(wgsPoint);

            return(new LatLngPoint(wgsPoint.LatY + _transPoint.LatY, wgsPoint.LonX + _transPoint.LonX));
        }
Exemple #31
0
        /// <summary>
        /// 将BD-09坐标转换成GCJ-02坐标
        /// </summary>
        /// <param name="bdPoint">BD-09坐标</param>
        /// <returns>GCJ-02坐标</returns>
        public LatLngPoint BD09ToGCJ02(LatLngPoint bdPoint)
        {
            LatLngPoint latLngPoint = new LatLngPoint();
            double      x = bdPoint.LonX - 0.0065, _y = bdPoint.LatY - 0.006;
            double      z     = Math.Sqrt(x * x + _y * _y) - 0.00002 * Math.Sin(_y * pi);
            double      theta = Math.Atan2(_y, x) - 0.000003 * Math.Cos(x * pi);

            latLngPoint.LonX = z * Math.Cos(theta);
            latLngPoint.LatY = z * Math.Sin(theta);
            return(latLngPoint);
        }
Exemple #32
0
        /// <summary>
        /// 将GCJ-02坐标转换成BD-09坐标
        /// </summary>
        /// <param name="gcjPoint">GCJ-02坐标</param>
        /// <returns>BD-09坐标</returns>
        public LatLngPoint GCJ02ToBD09(LatLngPoint gcjPoint)
        {
            LatLngPoint _bdPoint = new LatLngPoint();
            double      _x = gcjPoint.LonX, y = gcjPoint.LatY;
            double      _z     = Math.Sqrt(_x * _x + y * y) + 0.00002 * Math.Sin(y * pi);
            double      _theta = Math.Atan2(y, _x) + 0.000003 * Math.Cos(_x * pi);

            _bdPoint.LonX = _z * Math.Cos(_theta) + 0.0065;
            _bdPoint.LatY = _z * Math.Cos(_theta) + 0.006;
            return(_bdPoint);
        }
Exemple #33
0
        private MapCoord QueryOffSetData(LatLngPoint point)
        {
            MapCoord _search = new MapCoord();

            _search.Lat = (int)(point.LatY * 100);
            _search.Lon = (int)(point.LonX * 100);
            MapOffsetComparer rc  = new MapOffsetComparer();
            int      _findedIndex = mapCoordArrayList.BinarySearch(0, mapCoordArrayList.Count, _search, rc);
            MapCoord _findedCoord = (MapCoord)mapCoordArrayList[_findedIndex];

            return(_findedCoord);
        }
Exemple #34
0
 /// <summary>
 /// 绘制
 /// </summary>
 /// <param name="g"></param>
 /// <param name="center"></param>
 /// <param name="zoom"></param>
 /// <param name="screen_size"></param>
 public override void Draw(System.Drawing.Graphics g, LatLngPoint center, int zoom, System.Drawing.Size screen_size)
 {
     Point p = MapHelper.GetScreenLocationByLatLng(Location, center, zoom, screen_size);  //屏幕坐标
     Bitmap b = null;
     if (Type == PointType.RouteEnd)
     {
         b = Properties.BMap.ico_route_end;
     }
     else if (Type == PointType.RouteStart)
     {
         b = Properties.BMap.ico_route_start;
     }
     else if(Type == PointType.Strange)
     {
         b = Properties.BMap.ico_strange_point;
     }
     _rect = new Rectangle(p.X - b.Width / 2, p.Y - b.Height, b.Width, b.Height);
     g.DrawImage(b, _rect);
 }
Exemple #35
0
 /// <summary>
 /// 绘制方法
 /// </summary>
 /// <param name="g">画布</param>
 /// <param name="center">地图中心</param>
 /// <param name="zoom">地图缩放级别</param>
 /// <param name="screen_size">地图大小</param>
 public override void Draw(System.Drawing.Graphics g, LatLngPoint center, int zoom, System.Drawing.Size screen_size)
 {
     if (Points != null && Points.Count >= 2)
     {
         g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
         List<Point> l = new List<Point>();
         foreach (LatLngPoint p in Points)
         {
             l.Add(MapHelper.GetScreenLocationByLatLng(p, center, zoom, screen_size));  //屏幕坐标
         }
         using (Pen pen = new Pen(Color.FromArgb(150,Color.Blue), 4))
         {
             for (int i = 0; i < l.Count - 1; ++i)
             {
                 g.DrawLine(pen, l[i], l[i + 1]);
             }
         }
     }
 }
Exemple #36
0
 /// <summary>
 /// 绘制方法
 /// </summary>
 /// <param name="g">画布</param>
 /// <param name="center">地图中心</param>
 /// <param name="zoom">地图缩放级别</param>
 /// <param name="screen_size">地图大小</param>
 public override void Draw(System.Drawing.Graphics g, LatLngPoint center, int zoom, System.Drawing.Size screen_size)
 {
     g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
     Point theScreenCenter = MapHelper.GetScreenLocationByLatLng(Center, center, zoom, screen_size);  //椭圆中心点的屏幕坐标
     Point theScreenRightBottom = MapHelper.GetScreenLocationByLatLng(RightBottom, center, zoom, screen_size);  //椭圆矩形任意一角的屏幕坐标
     int width = Math.Abs(2 * (theScreenRightBottom.X - theScreenCenter.X));
     int height = Math.Abs(2 * (theScreenRightBottom.Y - theScreenCenter.Y));
     if (new Rectangle(new Point(0,0), screen_size).IntersectsWith(new Rectangle(theScreenCenter.X - width/2, theScreenCenter.Y - height/2, width, height)))  //需要绘制
     {
         using (SolidBrush sb = new SolidBrush(Color.FromArgb(30, Color.Blue)))
         {
             g.FillEllipse(sb, new Rectangle(theScreenCenter.X - width / 2, theScreenCenter.Y - height / 2, width, height));
         }
         using (Pen pen = new Pen(Color.FromArgb(150,Color.Blue), 4))
         {
             g.DrawEllipse(pen, new Rectangle(theScreenCenter.X - width / 2, theScreenCenter.Y - height / 2, width, height));
         }
     }
 }
Exemple #37
0
        /// <summary>
        /// 绘制方法
        /// </summary>
        /// <param name="g"></param>
        /// <param name="center"></param>
        /// <param name="zoom"></param>
        /// <param name="screen_size"></param>
        public override void Draw(System.Drawing.Graphics g, LatLngPoint center, int zoom, System.Drawing.Size screen_size)
        {
            Point p = MapHelper.GetScreenLocationByLatLng(Location, center, zoom, screen_size);  //屏幕坐标

            Bitmap b;
            if (_selected)
            {
                b = Properties.BMap.ico_blue_point_big;
            }
            else
            {
                b = Properties.BMap.ico_red_point_small;
            }
            g.DrawImage(b, new Rectangle(p.X - b.Width / 2, p.Y - b.Height, b.Width, b.Height));
            using (Font f = new Font("微软雅黑", 10, FontStyle.Bold))
            {
                g.DrawString(((Char)(Index + 65)).ToString(), f, Brushes.White, new PointF(_selected ? (p.X - 5) : (p.X - 6), _selected ? (p.Y - 30) : (p.Y - 26)));
            }
            _rect = new Rectangle(p.X - b.Width / 2, p.Y - b.Height, b.Width, b.Height);
        }
Exemple #38
0
        /// <summary>
        /// 绘制方法
        /// </summary>
        /// <param name="g"></param>
        /// <param name="center"></param>
        /// <param name="zoom"></param>
        /// <param name="screen_size"></param>
        public override void Draw(System.Drawing.Graphics g, LatLngPoint center, int zoom, System.Drawing.Size screen_size)
        {
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            Point theScreenLeftTop = MapHelper.GetScreenLocationByLatLng(LeftTop, center, zoom, screen_size);  //矩形左上角屏幕坐标
            Point theScreenRightBottom = MapHelper.GetScreenLocationByLatLng(RightBottom, center, zoom, screen_size);  //矩形右下角屏幕坐标

            int width = Math.Abs(theScreenRightBottom.X - theScreenLeftTop.X);
            int height = Math.Abs(theScreenRightBottom.Y - theScreenLeftTop.Y);
            Rectangle r = new Rectangle(Math.Min(theScreenLeftTop.X, theScreenRightBottom.X), Math.Min(theScreenLeftTop.Y, theScreenRightBottom.Y), width, height);
            if (new Rectangle(new Point(0, 0), screen_size).IntersectsWith(r))
            {
                using (SolidBrush sb = new SolidBrush(Color.FromArgb(30, Color.Blue)))
                {
                    g.FillRectangle(sb, r);
                }
                using (Pen pen = new Pen(Color.FromArgb(150,Color.Blue), 4))
                {
                    g.DrawRectangle(pen, r);
                }
            }
        }
Exemple #39
0
        /// <summary>
        /// 绘制方法
        /// </summary>
        /// <param name="g"></param>
        /// <param name="center"></param>
        /// <param name="zoom"></param>
        /// <param name="screen_size"></param>
        public override void Draw(System.Drawing.Graphics g, LatLngPoint center, int zoom, System.Drawing.Size screen_size)
        {
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            Point theScreenLeftTop = MapHelper.GetScreenLocationByLatLng(LeftTop, center, zoom, screen_size);  //矩形左上角屏幕坐标
            Point theScreenRightBottom = MapHelper.GetScreenLocationByLatLng(RightBottom, center, zoom, screen_size);  //矩形右下角屏幕坐标

            int width = Math.Abs(theScreenRightBottom.X - theScreenLeftTop.X);
            int height = Math.Abs(theScreenRightBottom.Y - theScreenLeftTop.Y);
            Rectangle r = new Rectangle(Math.Min(theScreenLeftTop.X, theScreenRightBottom.X), Math.Min(theScreenLeftTop.Y, theScreenRightBottom.Y), width, height);
            if (new Rectangle(new Point(0, 0), screen_size).IntersectsWith(r))
            {
                using (SolidBrush sb = new SolidBrush(Color.FromArgb(15, Color.DarkBlue)))
                {
                    g.FillRectangle(sb, r);
                }
                using (Pen pen = new Pen(Color.FromArgb(150,Color.DarkBlue), 2))
                {
                    g.DrawRectangle(pen, r);
                }
            }

            double d1 = MapHelper.GetDistanceByLatLng(LeftTop, new LatLngPoint(LeftTop.Lng, RightBottom.Lat));
            double d2 = MapHelper.GetDistanceByLatLng(LeftTop, new LatLngPoint(RightBottom.Lng, LeftTop.Lat));
            double d3 = MapHelper.GetDistanceByLatLng(new LatLngPoint(LeftTop.Lng, RightBottom.Lat), RightBottom);
            double d4 = MapHelper.GetDistanceByLatLng(new LatLngPoint(RightBottom.Lng, LeftTop.Lat), RightBottom);

            using (Font f = new Font("微软雅黑", 9))
            {
                g.FillRectangle(Brushes.DarkBlue, new Rectangle(theScreenLeftTop.X, (theScreenLeftTop.Y + theScreenRightBottom.Y) / 2 - 10, 60, 20));
                g.DrawString(Math.Round(d1, 2).ToString() + "km", f, Brushes.White, new PointF(theScreenLeftTop.X + 5, (theScreenLeftTop.Y + theScreenRightBottom.Y) / 2 - 8));
                g.FillRectangle(Brushes.DarkBlue, new Rectangle((theScreenLeftTop.X + theScreenRightBottom.X) / 2 - 30, theScreenLeftTop.Y, 60, 20));
                g.DrawString(Math.Round(d2, 2).ToString() + "km", f, Brushes.White, new PointF((theScreenLeftTop.X + theScreenRightBottom.X) / 2 - 30 + 5, theScreenLeftTop.Y + 2));
                g.FillRectangle(Brushes.DarkBlue, new Rectangle((theScreenLeftTop.X + theScreenRightBottom.X) / 2 - 30, theScreenRightBottom.Y - 20, 60, 20));
                g.DrawString(Math.Round(d3, 2).ToString() + "km", f, Brushes.White, new PointF((theScreenLeftTop.X + theScreenRightBottom.X) / 2 - 30 + 5, theScreenRightBottom.Y + 4 - 20));
                g.FillRectangle(Brushes.DarkBlue, new Rectangle(theScreenRightBottom.X - 60, (theScreenLeftTop.Y + theScreenRightBottom.Y) / 2 - 10, 60, 20));
                g.DrawString(Math.Round(d4, 2).ToString() + "km", f, Brushes.White, new PointF(theScreenRightBottom.X - 60 + 3, (theScreenLeftTop.Y + theScreenRightBottom.Y) / 2 - 10));
            }
        }
Exemple #40
0
        /// <summary>
        /// 绘制
        /// </summary>
        /// <param name="g"></param>
        /// <param name="center"></param>
        /// <param name="zoom"></param>
        /// <param name="screen_size"></param>
        public override void Draw(System.Drawing.Graphics g, LatLngPoint center, int zoom, System.Drawing.Size screen_size)
        {
            //不同路线绘制不一样 数据源结构也不一样
            if (DataSource != null)
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //质量优先
                
                LatLngPoint first, second;
                Point s_first = new Point(), s_second = new Point();
                if (Type == RouteType.Transit) //公交
                {
                    using (Pen p = new Pen(Color.FromArgb(250, Color.Blue),6))  //蓝色
                    {
                        p.StartCap = System.Drawing.Drawing2D.LineCap.Round; //连接圆滑
                        p.EndCap = System.Drawing.Drawing2D.LineCap.Round;
                        p.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                        JToken route = DataSource["scheme"][0];
                        foreach (JArray array in route["steps"])
                        {
                            if ((string)array[0]["type"] == "5") //步行
                            {
                                using (Pen p2 = new Pen(Color.FromArgb(250, Color.Gray), 6))
                                {
                                    p2.StartCap = System.Drawing.Drawing2D.LineCap.Round; //连接圆滑
                                    p2.EndCap = System.Drawing.Drawing2D.LineCap.Round;
                                    p2.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;

                                    string[] points = ((string)array[0]["path"]).Split(';'); //每一步骤中的点

                                    for (int i = points.Length - 1; i > 0; --i)
                                    {
                                        first = new LatLngPoint(double.Parse(points[i - 1].Split(',')[0]), double.Parse(points[i - 1].Split(',')[1]));
                                        second = new LatLngPoint(double.Parse(points[i].Split(',')[0]), double.Parse(points[i].Split(',')[1]));
                                        s_first = MapHelper.GetScreenLocationByLatLng(first, center, zoom, screen_size);
                                        s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                                        if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                                            g.DrawLine(p2, s_first, s_second);
                                    }
                                }
                            }
                            else //公交 地铁
                            {
                                string transits = "";
                                double duration = 0;
                                int type = 0;  //公交 还是 地铁
                                string start_name = "";
                                duration = double.Parse((string)array[0]["duration"]);
                                type = int.Parse((string)array[0]["vehicle"]["type"]);
                                start_name = (string)array[0]["vehicle"]["start_name"];
                                foreach (JObject jo in array) //多种方案
                                {
                                    transits += ((string)jo["vehicle"]["name"] + "/");
                                }
                                transits = transits.TrimEnd(new char[] { '/'});
                                //只绘制一个方案即可

                                string[] points = ((string)array[0]["path"]).Split(';'); //每一步骤中的点

                                for (int i = points.Length - 1; i > 0; --i)
                                {
                                    first = new LatLngPoint(double.Parse(points[i - 1].Split(',')[0]), double.Parse(points[i - 1].Split(',')[1]));
                                    second = new LatLngPoint(double.Parse(points[i].Split(',')[0]), double.Parse(points[i].Split(',')[1]));
                                    s_first = MapHelper.GetScreenLocationByLatLng(first, center, zoom, screen_size);
                                    s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                                    if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                                        g.DrawLine(p, s_first, s_second);

                                    if (i == 1) //起点
                                    {
                                        using (Font f = new Font("微软雅黑", 8))
                                        {
                                            string info = start_name + " 上车\n乘坐" + transits + " \n车程约" + Math.Round(duration / 60, 0) + "分钟";
                                            Size info_size = TextRenderer.MeasureText(info, f);

                                            GraphicsPath pt = new GraphicsPath();

                                            pt.AddPolygon(new Point[] { new Point(s_first.X - info_size.Width / 2 - 5, s_first.Y - 25), 
                                                new Point(s_first.X - info_size.Width / 2 - 5, s_first.Y - 25 - info_size.Height - 10),
                                                new Point(s_first.X + info_size.Width / 2 + 5, s_first.Y - 25 - info_size.Height - 10),
                                                new Point(s_first.X + info_size.Width / 2 + 5,s_first.Y - 25),
                                                    new Point(s_first.X + 8,s_first.Y - 25),
                                                    new Point(s_first.X,s_first.Y-15),
                                                new Point(s_first.X - 8,s_first.Y-25)});
                                            g.FillPath(Brushes.Wheat, pt);
                                            g.DrawPath(Pens.LightGray, pt);
                                            g.DrawString(info, new Font("微软雅黑", 9), Brushes.Black, new PointF(s_first.X - info_size.Width/2, s_first.Y - info_size.Height - 25 - 5));

                                            Bitmap b = type == 0 ? Properties.BMap.ico_bybus : Properties.BMap.ico_bysubway; //0公交 1地铁轻轨

                                            g.DrawImage(b, new Rectangle(s_first.X - b.Width / 2, s_first.Y - b.Height / 2, b.Width, b.Height));
                                        }
                                    }
                                    if (i == points.Length - 1) //终点
                                    {
                                        Bitmap b = type == 0 ? Properties.BMap.ico_bybus : Properties.BMap.ico_bysubway; //0公交 1地铁轻轨

                                        g.DrawImage(b, new Rectangle(s_second.X - b.Width / 2, s_second.Y - b.Height / 2, b.Width, b.Height));
                                    }

                                }
                            }
                        }
                    }
                }
                else if (Type == RouteType.Driving) //驾车
                {
                    using (Pen p = new Pen(Color.FromArgb(250, Color.Green), 6)) //绿色 
                    {
                        p.StartCap = System.Drawing.Drawing2D.LineCap.Round; //连接圆滑
                        p.EndCap = System.Drawing.Drawing2D.LineCap.Round;
                        p.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                        foreach (JObject step in DataSource["steps"])
                        {
                            first = new LatLngPoint(double.Parse((string)step["stepOriginLocation"]["lng"]), double.Parse((string)step["stepOriginLocation"]["lat"]));
                            s_first = MapHelper.GetScreenLocationByLatLng(first, center, zoom, screen_size); //第一点

                            string[] points = ((string)step["path"]).Split(';'); //每一步骤中的点
                            for (int i = 0; i < points.Length; ++i)
                            {
                                if (i == 0) //与前一点连接
                                {
                                    second = new LatLngPoint(double.Parse(points[i].Split(',')[0]), double.Parse(points[i].Split(',')[1]));
                                    s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                                    if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                                        g.DrawLine(p, s_first, s_second);
                                }
                                else
                                {
                                    first = new LatLngPoint(double.Parse(points[i - 1].Split(',')[0]), double.Parse(points[i - 1].Split(',')[1]));
                                    second = new LatLngPoint(double.Parse(points[i].Split(',')[0]), double.Parse(points[i].Split(',')[1]));
                                    s_first = MapHelper.GetScreenLocationByLatLng(first, center, zoom, screen_size);
                                    s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                                    if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                                        g.DrawLine(p, s_first, s_second);
                                }
                            }
                            s_first = s_second;

                            second = new LatLngPoint(double.Parse((string)step["stepDestinationLocation"]["lng"]), double.Parse((string)step["stepDestinationLocation"]["lat"]));
                            s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                            if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                                g.DrawLine(p, s_first, s_second);  //最后一点
                        }
                    }
                }
                else //步行
                {
                    using (Pen p = new Pen(Color.FromArgb(250, Color.Gray), 6)) //灰色 
                    {
                        p.StartCap = System.Drawing.Drawing2D.LineCap.Round; //连接圆滑
                        p.EndCap = System.Drawing.Drawing2D.LineCap.Round;
                        p.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                        foreach (JObject step in DataSource["steps"])
                        {
                            first = new LatLngPoint(double.Parse((string)step["stepOriginLocation"]["lng"]), double.Parse((string)step["stepOriginLocation"]["lat"]));
                            s_first = MapHelper.GetScreenLocationByLatLng(first, center, zoom, screen_size); //第一点

                            string[] points = ((string)step["path"]).Split(';'); //每一步骤中的点
                            for (int i = 0; i < points.Length; ++i)
                            {
                                if (i == 0) //与前一点连接
                                {
                                    second = new LatLngPoint(double.Parse(points[i].Split(',')[0]), double.Parse(points[i].Split(',')[1]));
                                    s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                                    if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                                        g.DrawLine(p, s_first, s_second);
                                }
                                else
                                {
                                    first = new LatLngPoint(double.Parse(points[i - 1].Split(',')[0]), double.Parse(points[i - 1].Split(',')[1]));
                                    second = new LatLngPoint(double.Parse(points[i].Split(',')[0]), double.Parse(points[i].Split(',')[1]));
                                    s_first = MapHelper.GetScreenLocationByLatLng(first, center, zoom, screen_size);
                                    s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                                    if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                                        g.DrawLine(p, s_first, s_second);
                                }
                            }
                            s_first = s_second;

                            second = new LatLngPoint(double.Parse((string)step["stepDestinationLocation"]["lng"]), double.Parse((string)step["stepDestinationLocation"]["lat"]));
                            s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                            if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                                g.DrawLine(p, s_first, s_second);  //最后一点
                        }
                    }
                }

                if (HighlightPath != null)
                {
                    using (Pen p3 = new Pen(Color.FromArgb(250, Color.Red), 6))
                    {
                        p3.StartCap = System.Drawing.Drawing2D.LineCap.Round; //连接圆滑
                        p3.EndCap = System.Drawing.Drawing2D.LineCap.Round;
                        p3.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                        string[] points = HighlightPath.Split(';'); //高亮部分中的点
                        for (int i = points.Length - 1; i > 0; --i)
                        {
                            first = new LatLngPoint(double.Parse(points[i - 1].Split(',')[0]), double.Parse(points[i - 1].Split(',')[1]));
                            second = new LatLngPoint(double.Parse(points[i].Split(',')[0]), double.Parse(points[i].Split(',')[1]));
                            s_first = MapHelper.GetScreenLocationByLatLng(first, center, zoom, screen_size);
                            s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                            if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                                g.DrawLine(p3, s_first, s_second);
                        }
                    }
                }
            }
        }
Exemple #41
0
        /// <summary>
        /// 绘制
        /// </summary>
        /// <param name="g"></param>
        /// <param name="center"></param>
        /// <param name="zoom"></param>
        /// <param name="screen_size"></param>
        public override void Draw(System.Drawing.Graphics g, LatLngPoint center, int zoom, Size screen_size)
        {
            //偏移处理
            //LatLngPoint offset = new LatLngPoint(MapHelper.OFFSET_LNG, MapHelper.OFFSET_LAT);
            //PointF offset_p = MapHelper.GetLocationByLatLng(offset, zoom);

            PointF center_p = MapHelper.GetLocationByLatLng(center, zoom); //中心点像素坐标
            PointF toleft_p = new PointF(X * 256, (Y + 1) * 256); //瓦片左上角像素坐标
            PointF p = new PointF((int)(screen_size.Width / 2 + (toleft_p.X - center_p.X)), (int)(screen_size.Height / 2 + (toleft_p.Y - center_p.Y) * (-1)));  //屏幕坐标
            //在绘制范围之内
            if (!new Rectangle(-256, -256, screen_size.Width + 256, screen_size.Height + 256).Contains(new Point((int)p.X, (int)p.Y)))
            {
                return;
            }
            if (Mode == MapMode.Normal && _normal == null && !_loading)  //开始下载普通瓦片
            {
                _loading = true;
                if (!_load_error)
                    ((Action)(delegate()
                    {
                        MapService ms = new MapService();
                        _normal = ms.LoadMapTile(X, Y, Zoom, Mode, LoadMode);
                        _loading = false;
                        if (_normal == null)
                        {
                            _load_error = true;
                        }
                        BMapControl.Invoke((Action)delegate()
                        {
                            BMapControl.Invalidate();
                        });

                    })).BeginInvoke(null, null);
            }
            if (Mode == MapMode.RoadNet && _road_net == null && !_loading)  //开始下载道路网瓦片
            {
                _loading = true;
                if (!_load_error)
                ((Action)(delegate()
                {
                    MapService ms = new MapService();
                    _road_net = ms.LoadMapTile(X, Y, Zoom, Mode, LoadMode);
                    _loading = false;
                    if (_road_net == null)
                    {
                        _load_error = true;
                    }
                    BMapControl.Invoke((Action)delegate()
                    {
                        BMapControl.Invalidate();
                    });

                })).BeginInvoke(null, null);
            }
            if (Mode == MapMode.Satellite && _sate == null && !_loading)  //开始下载卫星图瓦片
            {
                _loading = true;
                if (!_load_error)
                ((Action)(delegate()
                {
                    MapService ms = new MapService();
                    _sate = ms.LoadMapTile(X, Y, Zoom, Mode, LoadMode);
                    _loading = false;
                    if (_sate == null)
                    {
                        _load_error = true;
                    }
                    BMapControl.Invoke((Action)delegate()
                    {
                        BMapControl.Invalidate();
                    });

                })).BeginInvoke(null, null);
            }
            if (Mode == MapMode.Sate_RoadNet && _sate == null && !_loading)  //开始下载卫星图瓦片
            {
                _loading = true;
                if (!_load_error)
                ((Action)(delegate()
                {
                    MapService ms = new MapService();
                    _sate = ms.LoadMapTile(X, Y, Zoom, MapMode.Satellite, LoadMode);
                    _loading = false;
                    if (_sate == null)
                    {
                        _load_error = true;
                    }
                    BMapControl.Invoke((Action)delegate()
                    {
                        BMapControl.Invalidate();
                    });

                })).BeginInvoke(null, null);
            }
            if (Mode == MapMode.Sate_RoadNet && _road_net == null && !_loading) //开始下载道路网瓦片
            {
                _loading = true;
                if (!_load_error)
                ((Action)(delegate()
                {
                    MapService ms = new MapService();
                    _road_net = ms.LoadMapTile(X, Y, Zoom, MapMode.RoadNet, LoadMode);
                    _loading = false;
                    if (_road_net == null)
                    {
                        _load_error = true;
                    }
                    BMapControl.Invoke((Action)delegate()
                    {
                        BMapControl.Invalidate();
                    });

                })).BeginInvoke(null, null);
            }

            string error = "正在加载图片...";
            if (_load_error)
            {
                error = "图片加载失败...";
            }
            if (Mode == MapMode.Normal)  //绘制普通地图
            {
                if (_normal == null)
                {
                    g.FillRectangle(Brushes.LightGray, new RectangleF(p, new SizeF(256, 256)));
                    g.DrawRectangle(Pens.Gray, p.X, p.Y, 256, 256);
                    using (Font f = new Font("微软雅黑", 10))
                    {
                        g.DrawString(error, f, Brushes.Red, new PointF(p.X + 60, p.Y + 100));
                    }
                }
                else
                {
                    g.DrawImage(_normal, new RectangleF(p, new SizeF(256, 256)));
                }
            }
            if (Mode == MapMode.RoadNet) //绘制道路网
            {
                if (_road_net == null)
                {
                    g.FillRectangle(Brushes.LightGray, new RectangleF(p, new SizeF(256, 256)));
                    g.DrawRectangle(Pens.Gray, p.X, p.Y, 256, 256);
                    using (Font f = new Font("微软雅黑", 10))
                    {
                        g.DrawString(error, f, Brushes.Red, new PointF(p.X + 60, p.Y + 100));
                    }
                }
                else
                {
                    g.DrawImage(_road_net, new RectangleF(p, new SizeF(256, 256)));
                }
            }
            if (Mode == MapMode.Satellite)  //绘制卫星图
            {
                if (_sate == null)
                {
                    g.FillRectangle(Brushes.LightGray, new RectangleF(p, new SizeF(256, 256)));
                    g.DrawRectangle(Pens.Gray, p.X, p.Y, 256, 256);
                    using (Font f = new Font("微软雅黑", 10))
                    {
                        g.DrawString(error, f, Brushes.Red, new PointF(p.X + 60, p.Y + 100));
                    }
                }
                else
                {
                    g.DrawImage(_sate, new RectangleF(p, new SizeF(256, 256)));
                }
            }
            if (Mode == MapMode.Sate_RoadNet) //绘制卫星图和道路网
            {
                if (_sate == null && _road_net == null)
                {
                    g.FillRectangle(Brushes.LightGray, new RectangleF(p, new SizeF(256, 256)));
                    g.DrawRectangle(Pens.Gray, p.X, p.Y, 256, 256);
                    using (Font f = new Font("微软雅黑", 10))
                    {
                        g.DrawString(error, f, Brushes.Red, new PointF(p.X + 60, p.Y + 100));
                    }
                }
                else
                {
                    //先绘制卫星图  再绘制道路网
                    if (_sate != null)
                        g.DrawImage(_sate, new RectangleF(p, new SizeF(256, 256)));
                    if(_road_net != null)
                        g.DrawImage(_road_net, new RectangleF(p, new SizeF(256, 256)));
                }
            }
        }
Exemple #42
0
 /// <summary>
 /// 绘制方法
 /// </summary>
 /// <param name="g"></param>
 /// <param name="center"></param>
 /// <param name="zoom"></param>
 /// <param name="screen_size"></param>
 public override void Draw(System.Drawing.Graphics g, LatLngPoint center, int zoom, System.Drawing.Size screen_size)
 {
     Point p = MapHelper.GetScreenLocationByLatLng(Location, center, zoom, screen_size);  //屏幕坐标
     Bitmap b = Properties.BMap.ico_marker;
     g.DrawImage(b, new Rectangle(p.X - b.Width / 2, p.Y - b.Height, b.Width, b.Height));
     using (Font f = new Font("微软雅黑", 9))
     {
         Size s = TextRenderer.MeasureText(Name, f);  //字体占用像素
         g.FillRectangle(Brushes.Wheat, new Rectangle(new Point(p.X + b.Width / 2 + 5, p.Y - b.Height), new Size(s.Width + 6, s.Height + 6)));
         g.DrawRectangle(Pens.Gray, new Rectangle(new Point(p.X + b.Width / 2 + 5, p.Y - b.Height), new Size(s.Width + 6, s.Height + 6)));
         g.DrawString(Name, f, Brushes.Black, new PointF(p.X + b.Width / 2 + 5 + 3, p.Y - b.Height + 3));
     }
     _rect = new Rectangle(p.X - b.Width / 2, p.Y - b.Height, b.Width, b.Height);
 }
 /// <summary>
 /// 绘制方法
 /// </summary>
 /// <param name="g">画布</param>
 /// <param name="center">地图中心点坐标</param>
 /// <param name="zoom">当前地图缩放级别</param>
 /// <param name="screen_size">屏幕大小</param>
 public abstract void Draw(Graphics g, LatLngPoint center, int zoom, Size screen_size);