From c327260fecef075360482753e961695b5fef8275 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Thu, 16 Jul 2015 12:52:08 +0200 Subject: [PATCH] multi-line SmallTransparentTextOverlay that scales font size with map size --- .../SailingGWT sdm.launch | 154 +++++++++--------- java/com.sap.sailing.gwt.ui/SailingGWT.launch | 152 ++++++++--------- .../racemap/SmallTransparentInfoOverlay.java | 36 +++- 3 files changed, 182 insertions(+), 160 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/SailingGWT sdm.launch b/java/com.sap.sailing.gwt.ui/SailingGWT sdm.launch index e9c02e8b626..9b40edf5a0f 100644 --- a/java/com.sap.sailing.gwt.ui/SailingGWT sdm.launch +++ b/java/com.sap.sailing.gwt.ui/SailingGWT sdm.launch @@ -1,77 +1,77 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/com.sap.sailing.gwt.ui/SailingGWT.launch b/java/com.sap.sailing.gwt.ui/SailingGWT.launch index 1690e01f416..07ca62c8e6b 100755 --- a/java/com.sap.sailing.gwt.ui/SailingGWT.launch +++ b/java/com.sap.sailing.gwt.ui/SailingGWT.launch @@ -1,76 +1,76 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/SmallTransparentInfoOverlay.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/SmallTransparentInfoOverlay.java index 9369fb24265..7846cd7f2b8 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/SmallTransparentInfoOverlay.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/SmallTransparentInfoOverlay.java @@ -52,19 +52,35 @@ public class SmallTransparentInfoOverlay extends CanvasOverlayV3 { @Override protected void draw() { + final int LINE_SPACING = 3; + final int BOTTOM_MARGIN = 8; + final int LEFT_MARGIN = 8; + final int RIGHT_MARGIN = 9; + final int POLE_LENGTH = 25; if (mapProjection != null && position != null) { LatLng latLngPosition = coordinateSystem.toLatLng(position); Context2d context2d = getCanvas().getContext2d(); CssColor grayTransparentColor = CssColor.make("rgba(255,255,255,0.75)"); - - context2d.setFont("12px bold Verdana sans-serif"); - TextMetrics measureText = context2d.measureText(infoText); - double textWidth = measureText.getWidth(); - - canvasWidth = (int) textWidth + 17; + final int fontSizeInPx = 12+2*Math.max(0, map.getZoom()-15); + final int LINE_HEIGHT = fontSizeInPx+LINE_SPACING; + context2d.setFont(""+fontSizeInPx+"px Roboto, Arial, sans-serif"); +// context2d.setFont(""+fontSizeInPx+"px bold Verdana sans-serif"); + double textWidth = 0; + infoBoxHeight = BOTTOM_MARGIN; + for (final String line : infoText.split("\n")) { + TextMetrics measureText = context2d.measureText(line); + if (measureText.getWidth() > textWidth) { + textWidth = measureText.getWidth(); + } + infoBoxHeight += LINE_HEIGHT; + } + canvasWidth = (int) textWidth + LEFT_MARGIN + RIGHT_MARGIN; infoBoxWidth = canvasWidth; + canvasHeight = infoBoxHeight + POLE_LENGTH; getCanvas().setWidth(String.valueOf(canvasWidth)); getCanvas().setCoordinateSpaceWidth(canvasWidth); + getCanvas().setHeight(String.valueOf(canvasHeight)); + getCanvas().setCoordinateSpaceHeight(canvasHeight); // Change origin and dimensions to match true size (a stroke makes the shape a bit larger) context2d.setFillStyle(grayTransparentColor); @@ -83,7 +99,13 @@ public class SmallTransparentInfoOverlay extends CanvasOverlayV3 { context2d.beginPath(); context2d.setFillStyle("black"); - context2d.fillText(infoText, 8, 14); +// context2d.setFont(""+fontSizeInPx+"px bold Verdana sans-serif"); + context2d.setFont(""+fontSizeInPx+"px Roboto, Arial, sans-serif"); + int y = LINE_HEIGHT; + for (final String line : infoText.split("\n")) { + context2d.fillText(line, LEFT_MARGIN, y); + y += LINE_HEIGHT; + } context2d.stroke(); Point objectPositionInPx = mapProjection.fromLatLngToDivPixel(latLngPosition);