コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: LayerUtil.cs プロジェクト: tilemapjp/MapsforgeSharp
        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);
        }