Example #1
0
        //private void SystemPreferences_PropertyChanged(object sender, PropertyChangedEventArgs e)
        //{
        //    if (e.PropertyName == "RouteSettings.ShowGPSPoints" ||
        //        e.PropertyName == "RouteSettings.MarkerShape" ||
        //        e.PropertyName == "RouteSettings.MarkerSize" ||
        //        e.PropertyName == "RouteSettings.MarkerColor")
        //    {
        //        if (RouteControl.Visible)
        //        {
        //            RefreshOverlays();
        //        }
        //        else
        //        {
        //            routeSettingsChanged = true;
        //        }
        //    }
        //}

        //private void OnRouteItemsPropertyChanged(object sender, PropertyChangedEventArgs e)
        //{
        //    if (e.PropertyName == Activity.PropertyName.GPSRoute ||
        //        e.PropertyName == Route.PropertyName.GPSRoute ||
        //        e.PropertyName == Activity.PropertyName.Category )
        //    {
        //        ClearCachedLocations();
        //        RefreshOverlays();
        //    }
        //}

        private static void pixelSize(IMapControl mapControl, out float x, out float y)
        {
            //Use an "arbitrary" circlePixelSize to find the distance/size for a pixel - can differ X and Y
            //TBD: Cache per zoom level
            const int circlePixelSize = 1000;
            IGPSPoint point0          = Utils.GPS.LocationToPoint(mapControl.MapProjection.PixelToGPS(mapControl.Center, mapControl.Zoom,
                                                                                                      new Point(0, 0)));
            IGPSPoint pointX = Utils.GPS.LocationToPoint(mapControl.MapProjection.PixelToGPS(mapControl.Center, mapControl.Zoom,
                                                                                             new Point(circlePixelSize / 2, 0)));
            IGPSPoint pointY = Utils.GPS.LocationToPoint(mapControl.MapProjection.PixelToGPS(mapControl.Center, mapControl.Zoom,
                                                                                             new Point(0, circlePixelSize / 2)));

            x = (float)circlePixelSize / point0.DistanceMetersToPoint(pointX);
            y = (float)circlePixelSize / point0.DistanceMetersToPoint(pointY);
        }
Example #2
0
        public static float DistanceMetersToPointGpsSimple(IGPSPoint point, IGPSPoint point2)
        {
#if NO_SIMPLE_DISTANCE
            return(point.DistanceMetersToPoint(point2));
#else
            float _cosmean = (float)Math.Cos(point2.LatitudeDegrees * DegToRad);
            float dlat     = point.LatitudeDegrees - point2.LatitudeDegrees;
            float dlon     = point.LongitudeDegrees - point2.LongitudeDegrees;
            float result   = dlat * dlat + dlon * dlon * _cosmean;

#if SQUARE_DISTANCE
            return(result);
#else
            return(EarthRadius * DegToRad * (float)Math.Sqrt(result));
#endif
#endif
        }
Example #3
0
        public void Draw(IMapDrawContext drawContext)
        {
            if (m_CaptureSelectedGPSLocations)
            {
                m_CaptureSelectedGPSLocations = false;
                if (m_SelectedGPSLocations.Count != MapControl.Selected.Count)
                {
                    m_SelectedGPSLocations = getSelectedGPSLocations(drawContext);
                    SelectedGPSLocationsChanged(this, new System.EventArgs());
                }
            }

            if (_showPage)
            {
                //drawContext.Center

                IGPSLocation loc1           = drawContext.Projection.PixelToGPS(drawContext.Center, drawContext.ZoomLevel, new Point(0, 0));
                IGPSLocation loc2           = drawContext.Projection.PixelToGPS(drawContext.Center, drawContext.ZoomLevel, new Point(0, 100));
                IGPSPoint    point1         = Utils.GPS.LocationToPoint(loc1);
                IGPSPoint    point2         = Utils.GPS.LocationToPoint(loc2);
                float        meters         = point1.DistanceMetersToPoint(point2) / 100;
                float        radiusInPixels = m_highlightRadius / meters;

                foreach (TrailGPSLocation gpsLocation in m_TrailPoints)
                {
                    Point point = drawContext.Projection.GPSToPixel(drawContext.Center, drawContext.ZoomLevel, gpsLocation.GpsLocation);
                    Pen   pen   = new Pen(Color.Red, 5.0F);

                    drawContext.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    float X = point.X + (drawContext.DrawRectangle.Width / 2) - radiusInPixels;
                    float Y = point.Y + (drawContext.DrawRectangle.Height / 2) - radiusInPixels;
                    if (X > 0 && X < 1000 && Y > 0 && Y < 1000)
                    {
                        //Prevent crashes at large elipses
                        drawContext.Graphics.DrawEllipse(pen, X, Y, radiusInPixels * 2, radiusInPixels * 2);
                    }
                }
            }
        }
Example #4
0
        //Get a close enough point, not necessarily the closest or best match
        public int getClosePoint(IGPSPoint point)
        {
            IList<int> result = new List<int>();
            int x = (int)Math.Floor(point.LongitudeDegrees / m_lngWidth);
            int y = (int)Math.Floor(point.LatitudeDegrees / m_latWidth);
            foreach (int i in new int[] { x, x - 1, x + 1 })
            {
                if (m_Grid.ContainsKey(i))
                {
                    foreach (int j in new int[] { y, y - 1, y + 1 })
                    {
                        if (m_Grid[i].ContainsKey(j))
                        {
                            foreach (int p in m_Grid[i][j])
                            {
                                IGPSPoint pointInGrid = m_Route[p].Value;
                                double diffDist = point.DistanceMetersToPoint(pointInGrid);
                                if (diffDist < m_Distance)
                                {
                                    return p;
                                }
                            }
                        }
                    }
                }
            }

            return -1;
        }
Example #5
0
        //Get all points close to the asking point, but merge in "stretches" to let caller find best match
        public IList<IndexDiffDist> getAllCloseStretch(IGPSPoint point)
        {
            const int boxsize = 2;
            IList<IndexDiffDist> result = new List<IndexDiffDist>();
            int x = (int)Math.Floor(point.LongitudeDegrees / m_lngWidth);
            int y = (int)Math.Floor(point.LatitudeDegrees / m_latWidth);
            for (int i = x - boxsize; i <= x + boxsize; i++)
            {
                if (m_Grid.ContainsKey(i))
                {
                    for (int j = y - boxsize; j <= y + boxsize; j++)
                    {
                        if (m_Grid[i].ContainsKey(j))
                        {
                            foreach (int p in m_Grid[i][j])
                            {
                                IGPSPoint pointInGrid = m_Route[p].Value;
                                double diffDist = point.DistanceMetersToPoint(pointInGrid);
                                if (diffDist < m_Distance)
                                {
                                    double totDist = double.MaxValue;
                                    if (null != m_Dist)
                                    {
                                        totDist = m_Dist[p].Value;
                                    }
                                    IndexDiffDist t = new IndexDiffDist(p, p, p, diffDist, totDist);
                                    result.Add(t);
                                }
                            }
                        }
                    }
                }
            }

            //Group the results with local minimums in "stretches"
            //Only directly adjacent stretches are merged now, so single points out of the box will split stretches
            if (result.Count > 0)
            {
                for (int i = 0; i < result.Count; i++)
                {
                    for (int j = 0; j < result.Count; j++)
                    {
                        if (i != j && result[i].Index > -1 && result[j].Index > -1)
                        {
                            int k = Math.Min(i, j);
                            int l = Math.Max(i, j);
                            //Try merge with lower
                            if ((result[k].high + 1 >= result[l].low && result[k].high <= result[l].high) ||
                                Math.Abs(result[k].Dist - result[l].Dist) < m_Distance)
                            {
                                int tmp;
                                if (result[k].Diff < result[l].Diff)
                                {
                                    //Use lower also at equal
                                    tmp = k;
                                    result[l].Index = -1;
                                }
                                else
                                {
                                    tmp = l;
                                    result[k].Index = -1;
                                }
                                result[tmp].low = Math.Min(result[i].low, result[j].low);
                                result[tmp].high = Math.Max(result[i].high, result[j].high);
                            }
                        }
                    }
                }
                for (int i = result.Count-1; i >= 0; i--)
                {
                    if (result[i].Index == -1)
                    {
                        result.RemoveAt(i);
                    }
                }
            }
            return result;
        }
		public float DistanceMetersToPoint(IGPSPoint point) {
			GPSPoint thisPoint = new GPSPoint(
				this.LatitudeDegrees,
				this.LongitudeDegrees,
				0);
            if (point == null)
            {
                return float.MaxValue;
            }
			return point.DistanceMetersToPoint(thisPoint);
		}