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 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); } } }
private void DrawScaleBar(ICanvas canvas, int scaleBarLength1, int scaleBarLength2, IPaint paint, float scale) { int maxScaleBarLength = Math.Max(scaleBarLength1, scaleBarLength2); switch (scaleBarPosition) { case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.BOTTOM_CENTER: if (scaleBarLength2 == 0) { canvas.DrawLine((int)Math.Round((canvas.Width - maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), (int)Math.Round((canvas.Width + maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); canvas.DrawLine((int)Math.Round((canvas.Width - maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round((canvas.Width - maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); canvas.DrawLine((int)Math.Round((canvas.Width + maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round((canvas.Width + maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); } else { canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(canvas.Height * 0.5f), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); } break; case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.BOTTOM_LEFT: if (scaleBarLength2 == 0) { canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); } else { canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(canvas.Height * 0.5f), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); } break; case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.BOTTOM_RIGHT: if (scaleBarLength2 == 0) { canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); } else { canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint); canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength1), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength1), (int)Math.Round(canvas.Height * 0.5f), paint); canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength2), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength2), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); } break; case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.TOP_CENTER: if (scaleBarLength2 == 0) { canvas.DrawLine((int)Math.Round((canvas.Width - maxScaleBarLength) * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round((canvas.Width + maxScaleBarLength) * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), paint); canvas.DrawLine((int)Math.Round((canvas.Width - maxScaleBarLength) * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round((canvas.Width - maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height * 0.5f), paint); canvas.DrawLine((int)Math.Round((canvas.Width + maxScaleBarLength) * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round((canvas.Width + maxScaleBarLength) * 0.5f), (int)Math.Round(canvas.Height * 0.5f), paint); } else { canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(canvas.Height * 0.5f), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); } break; case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.TOP_LEFT: if (scaleBarLength2 == 0) { canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(SCALE_BAR_MARGIN * scale), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint); } else { canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength1), (int)Math.Round(canvas.Height * 0.5f), paint); canvas.DrawLine((int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(STROKE_EXTERNAL * scale * 0.5f + scaleBarLength2), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); } break; case org.mapsforge.map.scalebar.MapScaleBar.ScaleBarPosition.TOP_RIGHT: if (scaleBarLength2 == 0) { canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), paint); canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), paint); canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint); } else { canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - maxScaleBarLength), (int)Math.Round(canvas.Height * 0.5f), paint); canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength1), (int)Math.Round(SCALE_BAR_MARGIN * scale), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength1), (int)Math.Round(canvas.Height * 0.5f), paint); canvas.DrawLine((int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength2), (int)Math.Round(canvas.Height * 0.5f), (int)Math.Round(canvas.Width - STROKE_EXTERNAL * scale * 0.5f - scaleBarLength2), (int)Math.Round(canvas.Height - SCALE_BAR_MARGIN * scale), paint); } break; } }