Example #1
0
        private void DrawTileCoordinates(TilePosition tilePosition, ICanvas canvas)
        {
            int  x    = (int)(tilePosition.Point.X + 8 * displayModel.ScaleFactor);
            int  y    = (int)(tilePosition.Point.Y + 24 * displayModel.ScaleFactor);
            Tile tile = tilePosition.Tile;

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("X: ");
            stringBuilder.Append(tile.TileX);
            string text = stringBuilder.ToString();

            canvas.DrawText(text, x, y, this.paintBack);
            canvas.DrawText(text, x, y, this.paintFront);

            stringBuilder.Length = 0;
            stringBuilder.Append("Y: ");
            stringBuilder.Append(tile.TileY);
            text = stringBuilder.ToString();
            canvas.DrawText(text, x, (int)(y + 24 * displayModel.ScaleFactor), this.paintBack);
            canvas.DrawText(text, x, (int)(y + 24 * displayModel.ScaleFactor), this.paintFront);

            stringBuilder.Length = 0;
            stringBuilder.Append("Z: ");
            stringBuilder.Append(tile.ZoomLevel);
            text = stringBuilder.ToString();
            canvas.DrawText(text, x, (int)(y + 48 * displayModel.ScaleFactor), this.paintBack);
            canvas.DrawText(text, x, (int)(y + 48 * displayModel.ScaleFactor), this.paintFront);
        }
Example #2
0
        public override void Draw(BoundingBox boundingBox, sbyte zoomLevel, ICanvas canvas, Point topLeftPoint)
        {
            if (spacingConfig.ContainsKey(zoomLevel))
            {
                double spacing = spacingConfig[zoomLevel].Value;

                double minLongitude = spacing * (Math.Floor(boundingBox.MinLongitude / spacing));
                double maxLongitude = spacing * (Math.Ceiling(boundingBox.MaxLongitude / spacing));
                double minLatitude  = spacing * (Math.Floor(boundingBox.MinLatitude / spacing));
                double maxLatitude  = spacing * (Math.Ceiling(boundingBox.MaxLatitude / spacing));

                long mapSize = MercatorProjection.GetMapSize(zoomLevel, this.displayModel.TileSize);

                int bottom = (int)(MercatorProjection.LatitudeToPixelY(minLatitude, mapSize) - topLeftPoint.Y);
                int top    = (int)(MercatorProjection.LatitudeToPixelY(maxLatitude, mapSize) - topLeftPoint.Y);
                int left   = (int)(MercatorProjection.LongitudeToPixelX(minLongitude, mapSize) - topLeftPoint.X);
                int right  = (int)(MercatorProjection.LongitudeToPixelX(maxLongitude, mapSize) - topLeftPoint.X);

                for (double latitude = minLatitude; latitude <= maxLatitude; latitude += spacing)
                {
                    int pixelY = (int)(MercatorProjection.LatitudeToPixelY(latitude, mapSize) - topLeftPoint.Y);
                    canvas.DrawLine(left, pixelY, right, pixelY, this.lineBack);
                }

                for (double longitude = minLongitude; longitude <= maxLongitude; longitude += spacing)
                {
                    int pixelX = (int)(MercatorProjection.LongitudeToPixelX(longitude, mapSize) - topLeftPoint.X);
                    canvas.DrawLine(pixelX, bottom, pixelX, top, this.lineBack);
                }

                for (double latitude = minLatitude; latitude <= maxLatitude; latitude += spacing)
                {
                    int pixelY = (int)(MercatorProjection.LatitudeToPixelY(latitude, mapSize) - topLeftPoint.Y);
                    canvas.DrawLine(left, pixelY, right, pixelY, this.lineFront);
                }

                for (double longitude = minLongitude; longitude <= maxLongitude; longitude += spacing)
                {
                    int pixelX = (int)(MercatorProjection.LongitudeToPixelX(longitude, mapSize) - topLeftPoint.X);
                    canvas.DrawLine(pixelX, bottom, pixelX, top, this.lineFront);
                }

                for (double latitude = minLatitude; latitude <= maxLatitude; latitude += spacing)
                {
                    string text   = ConvertCoordinate(latitude);
                    int    pixelX = (canvas.Width - this.textFront.GetTextWidth(text)) / 2;
                    int    pixelY = (int)(MercatorProjection.LatitudeToPixelY(latitude, mapSize) - topLeftPoint.Y) + this.textFront.GetTextHeight(text) / 2;
                    canvas.DrawText(text, pixelX, pixelY, this.textBack);
                    canvas.DrawText(text, pixelX, pixelY, this.textFront);
                }

                for (double longitude = minLongitude; longitude <= maxLongitude; longitude += spacing)
                {
                    string text   = ConvertCoordinate(longitude);
                    int    pixelX = (int)(MercatorProjection.LongitudeToPixelX(longitude, mapSize) - topLeftPoint.X) - this.textFront.GetTextWidth(text) / 2;
                    int    pixelY = (canvas.Height + this.textFront.GetTextHeight(text)) / 2;
                    canvas.DrawText(text, pixelX, pixelY, this.textBack);
                    canvas.DrawText(text, pixelX, pixelY, this.textFront);
                }
            }
        }
Example #3
0
        private void DrawScaleText(ICanvas canvas, string scaleText1, string scaleText2, IPaint paint, float scale)
        {
            switch (scaleBarPosition)
            {
            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.BOTTOM_CENTER:
                if (scaleText2.Length == 0)
                {
                    canvas.DrawText(scaleText1, (int)Math.Round((canvas.Width - this.paintScaleTextStroke.GetTextWidth(scaleText1)) * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                }
                else
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                    canvas.DrawText(scaleText2, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText2)), paint);
                }
                break;

            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.BOTTOM_LEFT:
                if (scaleText2.Length == 0)
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                }
                else
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                    canvas.DrawText(scaleText2, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText2)), paint);
                }
                break;

            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.BOTTOM_RIGHT:
                if (scaleText2.Length == 0)
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.GetTextWidth(scaleText1)), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                }
                else
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.GetTextWidth(scaleText1)), (int)Math.Round(canvas.Height * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                    canvas.DrawText(scaleText2, (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.GetTextWidth(scaleText2)), (int)Math.Round(canvas.Height * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText2)), paint);
                }
                break;

            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.TOP_CENTER:
                if (scaleText2.Length == 0)
                {
                    canvas.DrawText(scaleText1, (int)Math.Round((canvas.Width - this.paintScaleTextStroke.GetTextWidth(scaleText1)) * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText1)), paint);
                }
                else
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                    canvas.DrawText(scaleText2, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText2)), paint);
                }
                break;

            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.TOP_LEFT:
                if (scaleText2.Length == 0)
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText1)), paint);
                }
                else
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                    canvas.DrawText(scaleText2, (int)Math.Round(STROKE_EXTERNAL * scale + TEXT_MARGIN * scale), (int)Math.Round(canvas.Height * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText2)), paint);
                }
                break;

            case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.TOP_RIGHT:
                if (scaleText2.Length == 0)
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.GetTextWidth(scaleText1)), (int)Math.Round(SCALE_BAR_MARGIN * scale + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText1)), paint);
                }
                else
                {
                    canvas.DrawText(scaleText1, (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.GetTextWidth(scaleText1)), (int)Math.Round(canvas.Height * 0.5f - STROKE_EXTERNAL * scale * 0.5f - TEXT_MARGIN * scale), paint);
                    canvas.DrawText(scaleText2, (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale - TEXT_MARGIN * scale - this.paintScaleTextStroke.GetTextWidth(scaleText2)), (int)Math.Round(canvas.Height * 0.5f + STROKE_EXTERNAL * scale * 0.5f + TEXT_MARGIN * scale + this.paintScaleTextStroke.GetTextHeight(scaleText2)), paint);
                }
                break;
            }
        }