Exemplo n.º 1
0
        internal static void RunTest(MapFile mapFile)
        {
            int  tileX = MercatorProjection.LongitudeToTileX(0, ZOOM_LEVEL);
            int  tileY = MercatorProjection.LatitudeToTileY(0, ZOOM_LEVEL);
            Tile tile  = new Tile(tileX, tileY, ZOOM_LEVEL, 256);

            MapReadResult mapReadResult = mapFile.ReadMapData(tile);

            mapFile.Close();

            Assert.AreEqual(mapReadResult.PointOfInterests.Count, 0);
            Assert.AreEqual(1, mapReadResult.Ways.Count);

            LatLong latLong1 = new LatLong(0.0, 0.0, true);
            LatLong latLong2 = new LatLong(0.0, 0.1, true);
            LatLong latLong3 = new LatLong(-0.1, 0.1, true);
            LatLong latLong4 = new LatLong(-0.1, 0.0, true);

            LatLong[][] latLongsExpected = new LatLong[][]
            {
                new LatLong[] { latLong1, latLong2, latLong3, latLong4, latLong1 }
            };

            Way way = mapReadResult.Ways[0];

            // TODO: Was ArrayEquals()
            Assert.AreEqual(latLongsExpected, way.LatLongs);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts geographic coordinates to view x/y coordinates in the map view.
        /// </summary>
        /// <param name="in">
        ///            the geographic coordinates </param>
        /// <returns> x/y view coordinates for the given location </returns>
        public virtual Point ToPixels(LatLong @in)
        {
            if (@in == null || this.mapView.Width <= 0 || this.mapView.Height <= 0)
            {
                return(null);
            }

            MapPosition mapPosition = this.mapView.Model.mapViewPosition.MapPosition;

            // this means somehow the mapview is not yet properly set up, see issue #308.
            if (mapPosition == null)
            {
                return(null);
            }

            // calculate the pixel coordinates of the top left corner
            LatLong latLong = mapPosition.LatLong;
            long    mapSize = MercatorProjection.GetMapSize(mapPosition.ZoomLevel, this.mapView.Model.displayModel.TileSize);
            double  pixelX  = MercatorProjection.LongitudeToPixelX(latLong.Longitude, mapSize);
            double  pixelY  = MercatorProjection.LatitudeToPixelY(latLong.Latitude, mapSize);

            pixelX -= this.mapView.Width >> 1;
            pixelY -= this.mapView.Height >> 1;

            // create a new point and return it
            return(new Point((int)(MercatorProjection.LongitudeToPixelX(@in.Longitude, mapSize) - pixelX), (int)(MercatorProjection.LatitudeToPixelY(@in.Latitude, mapSize) - pixelY)));
        }
Exemplo n.º 3
0
 /// <param name="latLong">
 ///            the initial geographical coordinates of this marker (may be null). </param>
 /// <param name="bitmap">
 ///            the initial {@code IBitmap} of this marker (may be null). </param>
 /// <param name="horizontalOffset">
 ///            the horizontal marker offset. </param>
 /// <param name="verticalOffset">
 ///            the vertical marker offset. </param>
 public Marker(LatLong latLong, IBitmap bitmap, int horizontalOffset, int verticalOffset) : base()
 {
     this.latLong          = latLong;
     this.bitmap           = bitmap;
     this.horizontalOffset = horizontalOffset;
     this.verticalOffset   = verticalOffset;
 }
Exemplo n.º 4
0
        public virtual void FromStringValidTest()
        {
            LatLong latLong = LatLongUtils.FromString(LATITUDE + DELIMITER + LONGITUDE);

            Assert.AreEqual(LATITUDE, latLong.Latitude, 0);
            Assert.AreEqual(LONGITUDE, latLong.Longitude, 0);
        }
Exemplo n.º 5
0
 /// <param name="latLong">
 ///            the initial center point of this circle (may be null). </param>
 /// <param name="radius">
 ///            the initial non-negative radius of this circle in meters. </param>
 /// <param name="paintFill">
 ///            the initial {@code Paint} used to fill this circle (may be null). </param>
 /// <param name="paintStroke">
 ///            the initial {@code Paint} used to stroke this circle (may be null). </param>
 /// <param name="keepAligned">
 ///            if set to true it will keep the bitmap aligned with the map,
 ///            to avoid a moving effect of a bitmap shader. </param>
 /// <exception cref="IllegalArgumentException">
 ///             if the given {@code radius} is negative or <seealso cref="Float#NaN"/>.
 ///  </exception>
 public Circle(LatLong latLong, float radius, IPaint paintFill, IPaint paintStroke, bool keepAligned) : base()
 {
     this.keepAligned = keepAligned;
     this.latLong     = latLong;
     RadiusInternal   = radius;
     this.paintFill   = paintFill;
     this.paintStroke = paintStroke;
 }
Exemplo n.º 6
0
        public static Point GetTopLeftPoint(MapPosition mapPosition, Dimension canvasDimension, int tileSize)
        {
            LatLong centerPoint = mapPosition.LatLong;

            int halfCanvasWidth  = canvasDimension.Width / 2;
            int halfCanvasHeight = canvasDimension.Height / 2;

            long   mapSize = MercatorProjection.GetMapSize(mapPosition.ZoomLevel, tileSize);
            double pixelX  = Math.Round(MercatorProjection.LongitudeToPixelX(centerPoint.Longitude, mapSize));
            double pixelY  = Math.Round(MercatorProjection.LatitudeToPixelY(centerPoint.Latitude, mapSize));

            return(new Point((int)pixelX - halfCanvasWidth, (int)pixelY - halfCanvasHeight));
        }
Exemplo n.º 7
0
        public override void Draw(BoundingBox boundingBox, sbyte zoomLevel, ICanvas canvas, Point topLeftPoint)
        {
            lock (this)
            {
                if (this.latLongs.Count < 2 || (this.paintStroke == null && this.paintFill == null))
                {
                    return;
                }

                IEnumerator <LatLong> iterator = this.latLongs.GetEnumerator();

                IPath   path    = this.graphicFactory.CreatePath();
                LatLong latLong = iterator.Current;
                long    mapSize = MercatorProjection.GetMapSize(zoomLevel, displayModel.TileSize);
                float   x       = (float)(MercatorProjection.LongitudeToPixelX(latLong.Longitude, mapSize) - topLeftPoint.X);
                float   y       = (float)(MercatorProjection.LatitudeToPixelY(latLong.Latitude, mapSize) - topLeftPoint.Y);
                path.MoveTo(x, y);

                while (iterator.MoveNext())
                {
                    latLong = iterator.Current;
                    x       = (float)(MercatorProjection.LongitudeToPixelX(latLong.Longitude, mapSize) - topLeftPoint.X);
                    y       = (float)(MercatorProjection.LatitudeToPixelY(latLong.Latitude, mapSize) - topLeftPoint.Y);
                    path.LineTo(x, y);
                }

                if (this.paintStroke != null)
                {
                    if (this.keepAligned)
                    {
                        this.paintStroke.SetBitmapShaderShift = topLeftPoint;
                    }
                    canvas.DrawPath(path, this.paintStroke);
                }

                if (this.paintFill != null)
                {
                    if (this.keepAligned)
                    {
                        this.paintFill.SetBitmapShaderShift = topLeftPoint;
                    }

                    canvas.DrawPath(path, this.paintFill);
                }
            }
        }
        private static void AssertLatLongsEquals(LatLong[][] latLongs1, LatLong[][] latLongs2)
        {
            Assert.AreEqual(latLongs1.Length, latLongs2.Length);

            for (int i = 0; i < latLongs1.Length; ++i)
            {
                Assert.AreEqual(latLongs1[i].Length, latLongs2[i].Length);

                for (int j = 0; j < latLongs1[i].Length; ++j)
                {
                    LatLong latLong1 = latLongs1[i][j];
                    LatLong latLong2 = latLongs2[i][j];

                    Assert.AreEqual(latLong1.Latitude, latLong2.Latitude, 0.000001);
                    Assert.AreEqual(latLong1.Longitude, latLong2.Longitude, 0.000001);
                }
            }
        }
        private static void CheckWay(Way way)
        {
            Assert.AreEqual(4, way.Layer);
            Assert.Null(way.LabelPosition);

            LatLong latLong1 = new LatLong(0.00, 0.00, true);
            LatLong latLong2 = new LatLong(0.04, 0.08, true);
            LatLong latLong3 = new LatLong(0.08, 0.00, true);

            LatLong[][] latLongsExpected = new LatLong[][]
            {
                new LatLong[] { latLong1, latLong2, latLong3 }
            };

            AssertLatLongsEquals(latLongsExpected, way.LatLongs);
            Assert.AreEqual(3, way.Tags.Count);
            Assert.True(way.Tags.Contains(new Tag("highway=motorway")));
            Assert.True(way.Tags.Contains(new Tag("name=ÄÖÜ")));
            Assert.True(way.Tags.Contains(new Tag("ref=äöü")));
        }
Exemplo n.º 10
0
        public void OnChange()
        {
            Dimension mapViewDimension = this.model.mapViewDimension.Dimension;

            if (mapViewDimension == null)
            {
                // at this point map view not visible
                return;
            }

            double overdrawFactor = this.model.frameBufferModel.OverdrawFactor;

            if (DimensionChangeNeeded(mapViewDimension, overdrawFactor))
            {
                Dimension newDimension = CalculateFrameBufferDimension(mapViewDimension, overdrawFactor);
                if (!useSquareFrameBuffer || frameBuffer.Dimension == null || newDimension.Width > frameBuffer.Dimension.Width || newDimension.Height > frameBuffer.Dimension.Height)
                {
                    // new dimensions if we either always reallocate on config change or if new dimension
                    // is larger than the old
                    this.frameBuffer.Dimension = newDimension;
                }
                this.lastMapViewDimension = mapViewDimension;
                this.lastOverdrawFactor   = overdrawFactor;
            }

            lock (this.model.mapViewPosition)
            {
                lock (this.frameBuffer)
                {
                    // we need resource ordering here to avoid deadlock
                    MapPosition mapPositionFrameBuffer = this.model.frameBufferModel.MapPosition;
                    if (mapPositionFrameBuffer != null)
                    {
                        double  scaleFactor = this.model.mapViewPosition.ScaleFactor;
                        LatLong pivot       = this.model.mapViewPosition.Pivot;
                        AdjustFrameBufferMatrix(mapPositionFrameBuffer, mapViewDimension, scaleFactor, pivot);
                    }
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Computes the geographic coordinates of a screen point.
        /// </summary>
        /// <returns> the coordinates of the x/y point </returns>
        public virtual LatLong FromPixels(double x, double y)
        {
            if (this.mapView.Width <= 0 || this.mapView.Height <= 0)
            {
                return(null);
            }

            // this uses the framebuffer position, the mapview position can be out of sync with
            // what the user sees on the screen if an animation is in progress
            MapPosition mapPosition = this.mapView.Model.frameBufferModel.MapPosition;

            // this means somehow the mapview is not yet properly set up, see issue #308.
            if (mapPosition == null)
            {
                return(null);
            }

            // calculate the pixel coordinates of the top left corner
            LatLong latLong = mapPosition.LatLong;
            long    mapSize = MercatorProjection.GetMapSize(mapPosition.ZoomLevel, this.mapView.Model.displayModel.TileSize);
            double  pixelX  = MercatorProjection.LongitudeToPixelX(latLong.Longitude, mapSize);
            double  pixelY  = MercatorProjection.LatitudeToPixelY(latLong.Latitude, mapSize);

            pixelX -= this.mapView.Width >> 1;
            pixelY -= this.mapView.Height >> 1;

            // catch outer map limits
            try
            {
                // convert the pixel coordinates to a LatLong and return it
                return(new LatLong(MercatorProjection.PixelYToLatitude(pixelY + y, mapSize), MercatorProjection.PixelXToLongitude(pixelX + x, mapSize)));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Start animating the map towards the given point.
        /// </summary>
        public virtual void AnimateTo(LatLong pos)
        {
            new Task(async() =>
            {
                int totalSteps = 25;           // Define the Step Number
                int signX      = 1;            // Define the Sign for Horizontal Movement
                int signY      = 1;            // Define the Sign for Vertical Movement
                long mapSize   = MercatorProjection.GetMapSize(ZoomLevel, displayModel.TileSize);

                double targetPixelX = MercatorProjection.LongitudeToPixelX(pos.Longitude, mapSize);
                double targetPixelY = MercatorProjection.LatitudeToPixelY(pos.Latitude, mapSize);

                double currentPixelX = MercatorProjection.LongitudeToPixelX(longitude, mapSize);
                double currentPixelY = MercatorProjection.LatitudeToPixelY(latitude, mapSize);

                double stepSizeX = Math.Abs(targetPixelX - currentPixelX) / totalSteps;
                double stepSizeY = Math.Abs(targetPixelY - currentPixelY) / totalSteps;

                /* Check the Signs */
                if (currentPixelX < targetPixelX)
                {
                    signX = -1;
                }

                if (currentPixelY < targetPixelY)
                {
                    signY = -1;
                }

                /* Compute Scroll */
                for (int i = 0; i < totalSteps; i++)
                {
                    MoveCenter(stepSizeX * signX, stepSizeY * signY);
                    await Task.Delay(10);
                }
            }).Start();
        }
Exemplo n.º 13
0
 /// <summary>
 /// Handles a long press event. A long press event is only triggered if the map was not moved. A return value of true
 /// indicates that the long press event has been handled by this overlay and stops its propagation to other overlays.
 /// <para>
 /// The default implementation of this method does nothing and returns false.
 ///
 /// </para>
 /// </summary>
 /// <param name="tapLatLong">
 ///            the geographic position of the long press. </param>
 /// <param name="layerXY">
 ///            the xy position of the layer element (if available) </param>
 /// <param name="tapXY">
 ///            the xy position of the tap </param>
 /// <returns> true if the long press event was handled, false otherwise. </returns>
 public virtual bool OnLongPress(LatLong tapLatLong, Point layerXY, Point tapXY)
 {
     return(false);
 }
Exemplo n.º 14
0
        private void AdjustFrameBufferMatrix(MapPosition mapPositionFrameBuffer, Dimension mapViewDimension, double scaleFactor, LatLong pivot)
        {
            MapPosition mapViewPosition = this.model.mapViewPosition.MapPosition;

            long mapSize = MercatorProjection.GetMapSize(mapPositionFrameBuffer.ZoomLevel, model.displayModel.TileSize);

            Point pointFrameBuffer = MercatorProjection.GetPixel(mapPositionFrameBuffer.LatLong, mapSize);
            Point pointMapPosition = MercatorProjection.GetPixel(mapViewPosition.LatLong, mapSize);

            double diffX = pointFrameBuffer.X - pointMapPosition.X;
            double diffY = pointFrameBuffer.Y - pointMapPosition.Y;
            // we need to compute the pivot distance from the map center
            // as we will need to find the pivot point for the
            // frame buffer (which generally has not the same size as the
            // map view).
            double pivotDistanceX = 0d;
            double pivotDistanceY = 0d;

            if (pivot != null)
            {
                Point pivotXY = MercatorProjection.GetPixel(pivot, mapSize);
                pivotDistanceX = pivotXY.X - pointFrameBuffer.X;
                pivotDistanceY = pivotXY.Y - pointFrameBuffer.Y;
            }

            float currentScaleFactor = (float)(scaleFactor / Math.Pow(2, mapPositionFrameBuffer.ZoomLevel));

            this.frameBuffer.AdjustMatrix((float)diffX, (float)diffY, currentScaleFactor, mapViewDimension, (float)pivotDistanceX, (float)pivotDistanceY);
        }
Exemplo n.º 15
0
 /// <param name="latLong">
 ///            the initial center point of this circle (may be null). </param>
 /// <param name="radius">
 ///            the initial non-negative radius of this circle in meters. </param>
 /// <param name="paintFill">
 ///            the initial {@code Paint} used to fill this circle (may be null). </param>
 /// <param name="paintStroke">
 ///            the initial {@code Paint} used to stroke this circle (may be null). </param>
 /// <exception cref="IllegalArgumentException">
 ///             if the given {@code radius} is negative or <seealso cref="Float#NaN"/>. </exception>
 public Circle(LatLong latLong, float radius, IPaint paintFill, IPaint paintStroke) : this(latLong, radius, paintFill, paintStroke, false)
 {
 }
Exemplo n.º 16
0
 /// <param name="latLong">
 ///            the initial center point of this circle (may be null). </param>
 /// <param name="radius">
 ///            the initial non-negative radius of this circle in pixels. </param>
 /// <param name="paintFill">
 ///            the initial {@code Paint} used to fill this circle (may be null). </param>
 /// <param name="paintStroke">
 ///            the initial {@code Paint} used to stroke this circle (may be null). </param>
 /// <param name="keepAligned"> if set to true it will keep the bitmap aligned with the map, to avoid
 ///                    a moving effect of a bitmap shader. </param>
 /// <exception cref="IllegalArgumentException">
 ///             if the given {@code radius} is negative or <seealso cref="Float#NaN"/>. </exception>
 public FixedPixelCircle(LatLong latLong, float radius, IPaint paintFill, IPaint paintStroke, bool keepAligned) : base(latLong, radius, paintFill, paintStroke, keepAligned)
 {
 }