Example #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);
        }
        public override void Draw(BoundingBox boundingBox, sbyte zoomLevel, ICanvas canvas, Point topLeftPoint)
        {
            long tileLeft   = MercatorProjection.LongitudeToTileX(boundingBox.MinLongitude, zoomLevel);
            long tileTop    = MercatorProjection.LatitudeToTileY(boundingBox.MaxLatitude, zoomLevel);
            long tileRight  = MercatorProjection.LongitudeToTileX(boundingBox.MaxLongitude, zoomLevel);
            long tileBottom = MercatorProjection.LatitudeToTileY(boundingBox.MinLatitude, zoomLevel);

            int tileSize = this.displayModel.TileSize;
            int pixelX1  = (int)(MercatorProjection.TileToPixel(tileLeft, tileSize) - topLeftPoint.X);
            int pixelY1  = (int)(MercatorProjection.TileToPixel(tileTop, tileSize) - topLeftPoint.Y);
            int pixelX2  = (int)(MercatorProjection.TileToPixel(tileRight, tileSize) - topLeftPoint.X + tileSize);
            int pixelY2  = (int)(MercatorProjection.TileToPixel(tileBottom, tileSize) - topLeftPoint.Y + tileSize);

            for (int lineX = pixelX1; lineX <= pixelX2 + 1; lineX += tileSize)
            {
                canvas.DrawLine(lineX, pixelY1, lineX, pixelY2, this.paintBack);
            }

            for (int lineY = pixelY1; lineY <= pixelY2 + 1; lineY += tileSize)
            {
                canvas.DrawLine(pixelX1, lineY, pixelX2, lineY, this.paintBack);
            }

            for (int lineX = pixelX1; lineX <= pixelX2 + 1; lineX += tileSize)
            {
                canvas.DrawLine(lineX, pixelY1, lineX, pixelY2, this.paintFront);
            }

            for (int lineY = pixelY1; lineY <= pixelY2 + 1; lineY += tileSize)
            {
                canvas.DrawLine(pixelX1, lineY, pixelX2, lineY, this.paintFront);
            }
        }
        public virtual void ExecuteQueryTest()
        {
            MapFile mapFile = new MapFile(MAP_FILE);

            MapFileInfo mapFileInfo = mapFile.MapFileInfo;

            Assert.True(mapFileInfo.DebugFile);

            for (sbyte zoomLevel = ZOOM_LEVEL_MIN; zoomLevel <= ZOOM_LEVEL_MAX; ++zoomLevel)
            {
                int  tileX = MercatorProjection.LongitudeToTileX(0.04, zoomLevel);
                int  tileY = MercatorProjection.LatitudeToTileY(0.04, zoomLevel);
                Tile tile  = new Tile(tileX, tileY, zoomLevel, 256);

                MapReadResult mapReadResult = mapFile.ReadMapData(tile);

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

                CheckPointOfInterest(mapReadResult.PointOfInterests[0]);
                CheckWay(mapReadResult.Ways[0]);
            }

            mapFile.Close();
        }
Example #4
0
        public static ISet <Tile> GetTiles(BoundingBox boundingBox, sbyte zoomLevel, int tileSize)
        {
            int tileLeft   = MercatorProjection.LongitudeToTileX(boundingBox.MinLongitude, zoomLevel);
            int tileTop    = MercatorProjection.LatitudeToTileY(boundingBox.MaxLatitude, zoomLevel);
            int tileRight  = MercatorProjection.LongitudeToTileX(boundingBox.MaxLongitude, zoomLevel);
            int tileBottom = MercatorProjection.LatitudeToTileY(boundingBox.MinLatitude, zoomLevel);

            ISet <Tile> tiles = new HashSet <Tile>();

            for (int tileY = tileTop; tileY <= tileBottom; ++tileY)
            {
                for (int tileX = tileLeft; tileX <= tileRight; ++tileX)
                {
                    tiles.Add(new Tile(tileX, tileY, zoomLevel, tileSize));
                }
            }
            return(tiles);
        }
Example #5
0
        public virtual void ExecuteQueryTest()
        {
            MapFile mapFile = new MapFile(MAP_FILE);

            for (sbyte zoomLevel = 0; zoomLevel <= ZOOM_LEVEL_MAX; ++zoomLevel)
            {
                int  tileX = MercatorProjection.LongitudeToTileX(1, zoomLevel);
                int  tileY = MercatorProjection.LatitudeToTileY(1, zoomLevel);
                Tile tile  = new Tile(tileX, tileY, zoomLevel, 256);

                MapReadResult mapReadResult = mapFile.ReadMapData(tile);

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

            mapFile.Close();
        }
Example #6
0
        public static IList <TilePosition> GetTilePositions(BoundingBox boundingBox, sbyte zoomLevel, Point topLeftPoint, int tileSize)
        {
            int tileLeft   = MercatorProjection.LongitudeToTileX(boundingBox.MinLongitude, zoomLevel);
            int tileTop    = MercatorProjection.LatitudeToTileY(boundingBox.MaxLatitude, zoomLevel);
            int tileRight  = MercatorProjection.LongitudeToTileX(boundingBox.MaxLongitude, zoomLevel);
            int tileBottom = MercatorProjection.LatitudeToTileY(boundingBox.MinLatitude, zoomLevel);

            int initialCapacity = (tileRight - tileLeft + 1) * (tileBottom - tileTop + 1);
            IList <TilePosition> tilePositions = new List <TilePosition>(initialCapacity);

            for (int tileY = tileTop; tileY <= tileBottom; ++tileY)
            {
                for (int tileX = tileLeft; tileX <= tileRight; ++tileX)
                {
                    double pixelX = MercatorProjection.TileToPixel(tileX, tileSize) - topLeftPoint.X;
                    double pixelY = MercatorProjection.TileToPixel(tileY, tileSize) - topLeftPoint.Y;

                    tilePositions.Add(new TilePosition(new Tile(tileX, tileY, zoomLevel, tileSize), new Point(pixelX, pixelY)));
                }
            }

            return(tilePositions);
        }