Competitor selection overlay on map improved

This commit is contained in:
Stsiapan_Tsybulski committed 2016-09-28 12:47:45 +03:00
1 parent a5f5114371
commit af37a3f034
2 files changed
+46 -8

No files matched your search

@@ -29,7 +29,10 @@ public class CompetitorInfoOverlay extends CanvasOverlayV3 {
private int canvasWidth;
private int canvasHeight;
private int infoBoxHeight = 20;
private int infoBoxHeight;
private int defaultInfoBoxHeight = 20;
private int xTextCoordinate = 8;
private int yTextCoordinate = 14;
private Color competitorColor;
@@ -52,10 +55,11 @@ public class CompetitorInfoOverlay extends CanvasOverlayV3 {
CssColor grayTransparentColor = CssColor.make("rgba(255,255,255,0.75)");
ctx.setFont("12px bold Verdana sans-serif");
TextMetrics measureText = ctx.measureText(infoText);
double textWidth = measureText.getWidth();
canvasWidth = (int) textWidth + 10 + infoBoxHeight;
String[] textLines = infoText.split("\n");
TextMetrics measureText = ctx.measureText(findLargestLine(textLines));
double largestLineWidth = measureText.getWidth();
infoBoxHeight = defaultInfoBoxHeight + textLines.length * 11;
canvasWidth = (int)largestLineWidth + 10 + infoBoxHeight;
setCanvasSize(canvasWidth, canvasHeight);
ctx.save();
@@ -95,7 +99,7 @@ public class CompetitorInfoOverlay extends CanvasOverlayV3 {
ctx.beginPath();
ctx.setFillStyle("black");
ctx.fillText(infoText, 8, 14);
drawText(textLines, ctx);
ctx.stroke();
ctx.restore();
@@ -121,4 +125,22 @@ public class CompetitorInfoOverlay extends CanvasOverlayV3 {
public void setInfoText(String infoText) {
this.infoText = infoText;
}
private void drawText(String[] lines, Context2d ctx) {
for (int i = 0; i < lines.length; i++) {
ctx.fillText(lines[i], xTextCoordinate, yTextCoordinate + i * 15);
}
}
private String findLargestLine(String[] lines) {
int index = 0;
int maxLength = lines[0].length();
for (int i = 0; i < lines.length; i++) {
if (maxLength < lines[i].length()) {
index = i;
maxLength = lines[i].length();
}
}
return lines[index];
}
}
@@ -1216,9 +1216,11 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe
if (competitorInfoOverlay == null) {
competitorInfoOverlay = createCompetitorInfoOverlay(RaceMapOverlaysZIndexes.INFO_OVERLAY_ZINDEX, competitorDTO);
competitorInfoOverlays.put(competitorDTO, competitorInfoOverlay);
competitorInfoOverlay.setInfoText(createInfoText(competitorDTO, lastBoatFix));
competitorInfoOverlay.setPosition(lastBoatFix.position, timeForPositionTransitionMillis);
competitorInfoOverlay.addToMap();
} else {
competitorInfoOverlay.setInfoText(createInfoText(competitorDTO, lastBoatFix));
competitorInfoOverlay.setPosition(lastBoatFix.position, timeForPositionTransitionMillis);
competitorInfoOverlay.draw();
}
@@ -1938,8 +1940,22 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe
}
private CompetitorInfoOverlay createCompetitorInfoOverlay(int zIndex, final CompetitorDTO competitorDTO) {
String infoText = competitorDTO.getSailID() == null || competitorDTO.getSailID().isEmpty() ? competitorDTO.getName() : competitorDTO.getSailID();
return new CompetitorInfoOverlay(map, zIndex, competitorSelection.getColor(competitorDTO, raceIdentifier), infoText, coordinateSystem);
GPSFixDTOWithSpeedWindTackAndLegType gpsFixDTO = getBoatFix(competitorDTO, timer.getTime());
return new CompetitorInfoOverlay(map, zIndex, competitorSelection.getColor(competitorDTO, raceIdentifier), createInfoText(competitorDTO, gpsFixDTO), coordinateSystem);
}
private String createInfoText(CompetitorDTO competitorDTO, GPSFixDTOWithSpeedWindTackAndLegType gpsFixDTO) {
StringBuilder infoText = new StringBuilder();
infoText.append(stringMessages.id()).append(" : ").append(competitorDTO.getSailID()).append("\n");
infoText.append(stringMessages.name()).append(" : ").append(competitorDTO.getName()).append("\n");
infoText.append(stringMessages.speed()).append(" : ")
.append(NumberFormatterFactory.getDecimalFormat(1).format(gpsFixDTO.speedWithBearing.speedInKnots))
.append(" ").append(stringMessages.knotsUnit()).append("\n");
QuickRankDTO quickRankDTO = quickRanks.get(competitorDTO);
if (quickRankDTO != null) {
infoText.append(stringMessages.rank()).append(" : ").append(quickRanks.get(competitorDTO).rank);
}
return infoText.toString();
}
private BoatOverlay createBoatOverlay(int zIndex, final CompetitorDTO competitorDTO, boolean highlighted) {