コード例 #1
0
        public PointD FromLatLngToPoint(GpsPoint gps)
        {
            var x    = PixelOrigin.X + gps.Longitude * PixelsPerLonDegree;
            var siny = Bound(Math.Sin(DegreesToRadians(gps.Latitude)), -0.9999, 0.9999);
            var y    = PixelOrigin.Y + 0.5 * Math.Log((1 + siny) / (1 - siny)) * -PixelsPerLonRadian;

            return(new PointD(x, y));
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: ardor91/DroneController
        private void button5_Click(object sender, EventArgs e)
        {
            //map.Points.Clear();
            map.Latitude  = Convert.ToDouble(txtCenterLat.Text);
            map.Longitude = Convert.ToDouble(txtCenterLng.Text);

            relativeCenter = prj.FromLatLngToPoint(new GpsPoint(Convert.ToDouble(txtCenterLat.Text), Convert.ToDouble(txtCenterLng.Text)));
            var scale   = Math.Pow(2, map.Zoom);
            var pointSW = new PointD((relativeCenter.X - (640.0 / 2.0) / scale), (relativeCenter.Y + (640.0 / 2.0) / scale));

            AddDebug(Color.Black, pointSW);
            var latLonSW = prj.FromPointToLatLong(pointSW);

            var pointNE = new PointD((relativeCenter.X + (640.0 / 2) / scale), (relativeCenter.Y - (640.0 / 2) / scale));

            AddDebug(Color.Red, pointNE);
            var latLonNE = prj.FromPointToLatLong(pointNE);

            lblLat.Text = latLonSW.Latitude.ToString();
            lblLng.Text = latLonSW.Longitude.ToString();

            var diffY = Math.Abs(latLonSW.Latitude - latLonNE.Latitude);   // latitude
            var diffX = Math.Abs(latLonSW.Longitude - latLonNE.Longitude); // longitude

            stepPerX = diffX / 640.0;
            stepPerY = diffY / 640.0;

            leftBottomCorner = latLonSW;

            map.Points.AddRange(new List <GpsPoint>()
            {
                latLonSW, latLonNE
            });

            if (originalLines.Count > 0)
            {
                var order = true;
                foreach (var line in originalLines)
                {
                    var p1 = new GpsPoint((leftBottomCorner.Latitude + (640 - (line.P1.Y + offsetY)) * stepPerY),
                                          (leftBottomCorner.Longitude + ((line.P1.X + offsetX)) * stepPerX));
                    var p2 = new GpsPoint((leftBottomCorner.Latitude + (640 - (line.P2.Y + offsetY)) * stepPerY),
                                          (leftBottomCorner.Longitude + ((line.P2.X + offsetX)) * stepPerX));

                    /*var longitude = (leftBottomCorner.Longitude + e.Location.X * stepPerX);
                     *  var latitude = (leftBottomCorner.Latitude + (640 - e.Location.Y) * stepPerY);*/

                    if (order)
                    {
                        map.Path.Add(p1);
                        map.Path.Add(p2);
                    }
                    else
                    {
                        map.Path.Add(p2);
                        map.Path.Add(p1);
                    }
                    order = !order;
                }
            }

            googleImage   = map.GetImage();
            REDRAW_NEEDED = true;
            //MessageBox.Show(diffX + " : " + diffY);
        }