private void geoImage_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            var mousePosition = e.GetPosition(geoImage);

            if (((WriteableBitmap)geoImage.Source).GetPixel((int)mousePosition.X, (int)mousePosition.Y) == editColor)
            {
                // Edit mode and user rightclicked an edit point
                LatLongRegion      foundRegion = null;
                LatLongDegreePoint hitPoint    = FindHitPoint(mousePosition, out foundRegion);
                if (hitPoint != null)
                {
                    var msg = LatLongUtil.GetLatLongStringFromPoint(new Point(hitPoint.X, hitPoint.Y));
                    if (foundRegion != null)
                    {
                        msg += "\nRegion: " + foundRegion.Name
                               + "\nColor code: " + foundRegion.ColorName;
                    }
                    MessageBox.Show(msg);
                }
            }
            else
            {
                // Enter pan mode
                origin      = e.GetPosition(this);
                this.Cursor = Cursors.Hand;
                geoImage.CaptureMouse();
            }
        }
示例#2
0
        public void TestGetCoordinate()
        {
            var coord = LatLongUtil.GetCoordinate(91.5);

            Assert.AreEqual(new Coordinate()
            {
                Degree = 91, Minutes = 30, Seconds = 0, Mseconds = 0
            }, coord);
        }
示例#3
0
        public void TestConvertDegreeAngleToDouble()
        {
            var coord1 = LatLongUtil.ConvertDegreeAngleToDouble("N055.37.40.078");

            Assert.AreEqual(55, (int)coord1);

            var coord2 = LatLongUtil.ConvertDegreeAngleToDouble("N055.40.40.078");

            Assert.AreEqual(55, (int)coord2);
            Assert.IsTrue(coord1 < coord2);
        }
 private void geoImage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     if (draggingEditPoint)
     {
         draggingEditPoint = false;
         var mousePosition = e.GetPosition(geoImage);
         DraggingEditPoint.X = mousePosition.X;
         DraggingEditPoint.Y = mousePosition.Y;
         double latitude;
         double longitude;
         LatLongUtil.GetLatLongDegreeFromPoint(mousePosition, out latitude, out longitude);
         DraggingEditPoint.Latitude  = latitude;
         DraggingEditPoint.Longitude = longitude;
         previousEditPointRect       = null;
         DrawLines();
     }
 }
        private void geoImage_MouseMove(object sender, MouseEventArgs e)
        {
            var mousePosition = e.GetPosition(geoImage);

            textBlockLatLong.Text = LatLongUtil.GetLatLongStringFromPoint(mousePosition);

            if (geoImage.IsMouseCaptured)
            {
                // Panning mode
                Vector v   = e.GetPosition(this) - origin;
                var    pos = e.GetPosition(this);

                var dragVector = new Point(v.X / LatLongUtil.ScaleTransform.ScaleX, v.Y / LatLongUtil.ScaleTransform.ScaleY);
                LatLongUtil.TranslateTransform.X += dragVector.X;
                LatLongUtil.TranslateTransform.Y += dragVector.Y;
                origin = e.GetPosition(this);
                toolWindow.UpdateLabels();
            }


            else if (draggingEditPoint)
            {
                // Move point
                Debug.WriteLine("Moving in edit mode");

                var bitmap = (WriteableBitmap)geoImage.Source;

                // Restore previous area
                if (previousEditPointRect.HasValue)
                {
                    bitmap.Blit(previousEditPointRect.Value, savedBackground, savedBackgroundRect);
                }

                // Save area before drawing

                previousEditPointRect = new Rect(mousePosition.X - editPointDelta, mousePosition.Y - editPointDelta, 2 * editPointDelta, 2 * editPointDelta);
                savedBackground.Blit(savedBackgroundRect, bitmap, previousEditPointRect.Value);
                // Draw moved edit point
                bitmap.FillRectangle((int)mousePosition.X - editPointDelta, (int)mousePosition.Y - editPointDelta, (int)mousePosition.X + editPointDelta, (int)mousePosition.Y + editPointDelta, editColor);


                // Draw lines from each neighbor to point being edited
            }
        }
示例#6
0
        public void TestGetPointFromLatLongString()
        {
            LatLongUtil.ScaleTransform.ScaleX = 100000;
            LatLongUtil.ScaleTransform.ScaleY = 100000;


            LatLongUtil.TranslateTransform.X = -12.65;
            LatLongUtil.TranslateTransform.Y = -67.239;

            // LatLongUtil.ScaleTransform.CenterX = 1.00; ; //  LatLongUtil.TranslateTransform.X;
            // LatLongUtil.ScaleTransform.CenterY = 80.239; //LatLongUtil.TranslateTransform.Y;

            var point = LatLongUtil.GetPointFromLatLongString("N055.37.40.078 E012.39.12.954");
            var str   = LatLongUtil.GetLatLongStringFromPoint(point);

            Assert.AreEqual("N055.37.40.078 E012.39.12.953", str);  // 1 msec off, probably due to rounding errors

            var point2 = LatLongUtil.GetPointFromLatLongString("N55.37.40.078 E12.39.12.954");

            Assert.AreEqual(point.X, point2.X);
            Assert.AreEqual(point.Y, point2.Y);
        }
        private void ReadSectorFile()
        {
            SctFileReader reader = new SctFileReader();

            reader.GeoLineHandler += line =>
            {
                var from = LatLongUtil.GetLatLongDecimalPointFromLatLongString(line.Start);
                var to   = LatLongUtil.GetLatLongDecimalPointFromLatLongString(line.End);
                geoLines.Add(new LatLongDegreeLine(new LatLongDegreePoint(from.X, from.Y), new LatLongDegreePoint(to.X, to.Y), line.ColorName));
            };
            reader.DefineHandler += (key, color) =>
            {
                byte blue  = (byte)((color & 0xff0000) >> 16);
                byte green = (byte)((color & 0xff00) >> 8);
                byte red   = (byte)(color & 0xff);
                if (!sectorfileColors.ContainsKey(key))
                {
                    sectorfileColors.Add(key, Color.FromRgb(red, green, blue));
                }
            };
            reader.RegionHandler += region =>
            {
                regions.Add(new LatLongRegion(region.Name, region.ColorName,
                                              region.Coordinates
                                              .Select(c =>
                {
                    var point = LatLongUtil.GetLatLongDecimalPointFromLatLongString(c);
                    return(new LatLongDegreePoint(point.X, point.Y));
                }
                                                      )
                                              .ToList()));
            };
            reader.SectorfileInfoHandler += info => fileInfo = info;
            reader.Parse("..\\..\\..\\UnitTestProject1\\Testdata\\EKDK_official_16_13.sct");

            logger.Debug("Read " + geoLines.Count + " geo lines");
        }
        public void CenterAt(String latLong, double zoom)
        {
            // Center
            textBlockLatLong.Text = latLong;
            var splitted = latLong.Split(' ');
            var latdec   = LatLongUtil.ConvertDegreeAngleToDouble(splitted[0]);
            var londec   = LatLongUtil.ConvertDegreeAngleToDouble(splitted[1]);

            LatLongUtil.TranslateTransform.X = -londec;
            LatLongUtil.TranslateTransform.Y = LatLongUtil.LatitudeToY(latdec);

            // Set zoom
            LatLongUtil.ScaleTransform.ScaleX = zoom;
            LatLongUtil.ScaleTransform.ScaleY = zoom;
            textBlockZoom.Text = zoom.ToString("###0.00");

            // Now centered at upper-left corner, center at the windows center
            var dragVector = new Point(ActualWidth / 2 / LatLongUtil.ScaleTransform.ScaleX, ActualHeight / 2 / LatLongUtil.ScaleTransform.ScaleY);

            LatLongUtil.TranslateTransform.X += dragVector.X;
            LatLongUtil.TranslateTransform.Y += dragVector.Y;

            DrawLines();
        }
 private void Window_Closing(object sender, CancelEventArgs e)
 {
     ApplicationSettings.Instance.Center     = LatLongUtil.GetLatLongStringFromPoint(new Point(geoImage.ActualWidth / 2, geoImage.ActualHeight / 2));
     ApplicationSettings.Instance.ZoomFactor = LatLongUtil.ScaleTransform.ScaleX;
 }
        public void DrawLines()
        {
            int             skipped      = 0;
            WriteableBitmap writeableBmp = BitmapFactory.New((int)ActualWidth, (int)ActualHeight);

            geoImage.Source = writeableBmp;
            using (writeableBmp.GetBitmapContext())
            {
                var clearColor = Color.FromRgb(
                    symbolSettings["Sector:inactive sector background"].R,
                    symbolSettings["Sector:inactive sector background"].G,
                    symbolSettings["Sector:inactive sector background"].B);
                writeableBmp.Clear(clearColor);

                skipped = 0;
                if (showRegions)
                {
                    regions.ForEach(region =>
                    {
                        var color = Colors.Black;
                        sectorfileColors.TryGetValue(region.ColorName, out color);
                        var points = new int[(region.Coordinates.Count + 1) * 2];
                        int i      = 0;
                        region.Coordinates.ForEach(c =>
                        {
                            var p       = LatLongUtil.Transform(c.Latitude, c.Longitude);
                            points[i++] = (int)p.X;
                            points[i++] = (int)p.Y;
                            c.X         = (int)p.X;
                            c.Y         = (int)p.Y;
                        });
                        points[i++] = points[0];
                        points[i++] = points[1];

                        writeableBmp.FillPolygon(points, color);
                        if (editRegions)
                        {
                            for (int j = 0; j < region.Coordinates.Count * 2; j += 2)
                            {
                                writeableBmp.FillRectangle(points[j] - editPointDelta, points[j + 1] - editPointDelta, points[j] + editPointDelta, points[j + 1] + editPointDelta, editColor);
                            }
                        }
                    });
                }

                if (showGeo)
                {
                    skipped = 0;
                    var geoColor = Color.FromRgb(
                        symbolSettings["Geo:line"].R,
                        symbolSettings["Geo:line"].G,
                        symbolSettings["Geo:line"].B);

                    geoLines.ForEach(geoLine =>
                    {
                        var from = LatLongUtil.Transform(geoLine.Start.Latitude, geoLine.Start.Longitude);
                        var to   = LatLongUtil.Transform(geoLine.End.Latitude, geoLine.End.Longitude);
                        if (ShouldDrawLine(from, to))
                        {
                            var color = geoColor;
                            if (!string.IsNullOrEmpty(geoLine.Color))
                            {
                                sectorfileColors.TryGetValue(geoLine.Color, out color);
                            }
                            writeableBmp.DrawLine((int)from.X, (int)from.Y, (int)to.X, (int)to.Y, color);
                            geoLine.Start.X = (int)from.X;
                            geoLine.Start.Y = (int)from.Y;
                            geoLine.End.X   = (int)to.X;
                            geoLine.End.Y   = (int)to.Y;
                        }
                        else
                        {
                            skipped++;
                        }
                    });
                    Debug.WriteLine("Skipped " + skipped + " geo points ");
                }
            }
        }
示例#11
0
 public void TestLatitudeToY()
 {
     var y = LatLongUtil.LatitudeToY(55.6);
 }
示例#12
0
 public void TestYToLatIsInverseOfLatToY()
 {
     Assert.AreEqual(20.0, LatLongUtil.LatitudeToY(LatLongUtil.YToLatitude(20)), 0.0001);
 }