mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-28 00:16:46 +00:00
formatting; improved encapsulation
This commit is contained in:
+21
-23
@@ -14,40 +14,38 @@ public class BoatCanvasOverlay extends CanvasOverlay {
|
||||
private final RaceMapImageManager raceMapImageManager;
|
||||
|
||||
private GPSFixDTO boatFix;
|
||||
|
||||
|
||||
public BoatCanvasOverlay(CompetitorDTO competitorDTO, RaceMapImageManager raceMapImageManager) {
|
||||
super();
|
||||
this.competitorDTO = competitorDTO;
|
||||
this.raceMapImageManager = raceMapImageManager;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Overlay copy() {
|
||||
return new BoatCanvasOverlay(competitorDTO, raceMapImageManager);
|
||||
return new BoatCanvasOverlay(competitorDTO, raceMapImageManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void redraw(boolean force) {
|
||||
if (boatFix != null) {
|
||||
ImageTransformer boatImageTransformer = raceMapImageManager.getBoatImageTransformer(boatFix, isSelected);
|
||||
double realBoatSizeScaleFactor = raceMapImageManager.getRealBoatSizeScaleFactor(boatImageTransformer.getImageSize());
|
||||
ImageData imageData = boatImageTransformer.getTransformedImageData(boatFix.speedWithBearing.bearingInDegrees, realBoatSizeScaleFactor);
|
||||
|
||||
int imageWidth = imageData.getWidth();
|
||||
int imageHeigth = imageData.getHeight();
|
||||
canvas.setWidth(String.valueOf(imageWidth));
|
||||
canvas.setHeight(String.valueOf(imageHeigth));
|
||||
canvas.setCoordinateSpaceWidth(imageWidth);
|
||||
canvas.setCoordinateSpaceHeight(imageHeigth);
|
||||
|
||||
LatLng latLngPosition = LatLng.newInstance(boatFix.position.latDeg, boatFix.position.lngDeg);
|
||||
|
||||
Point boatPositionInPx = map.convertLatLngToDivPixel(latLngPosition);
|
||||
|
||||
pane.setWidgetPosition(canvas, boatPositionInPx.getX() - imageWidth / 2, boatPositionInPx.getY() - imageHeigth / 2);
|
||||
|
||||
canvas.getContext2d().putImageData(imageData, 0, 0);
|
||||
}
|
||||
if (boatFix != null) {
|
||||
ImageTransformer boatImageTransformer = raceMapImageManager.getBoatImageTransformer(boatFix, isSelected());
|
||||
double realBoatSizeScaleFactor = raceMapImageManager.getRealBoatSizeScaleFactor(boatImageTransformer
|
||||
.getImageSize());
|
||||
ImageData imageData = boatImageTransformer.getTransformedImageData(
|
||||
boatFix.speedWithBearing.bearingInDegrees, realBoatSizeScaleFactor);
|
||||
int imageWidth = imageData.getWidth();
|
||||
int imageHeigth = imageData.getHeight();
|
||||
getCanvas().setWidth(String.valueOf(imageWidth));
|
||||
getCanvas().setHeight(String.valueOf(imageHeigth));
|
||||
getCanvas().setCoordinateSpaceWidth(imageWidth);
|
||||
getCanvas().setCoordinateSpaceHeight(imageHeigth);
|
||||
LatLng latLngPosition = LatLng.newInstance(boatFix.position.latDeg, boatFix.position.lngDeg);
|
||||
Point boatPositionInPx = getMap().convertLatLngToDivPixel(latLngPosition);
|
||||
getPane().setWidgetPosition(getCanvas(), boatPositionInPx.getX() - imageWidth / 2, boatPositionInPx.getY()
|
||||
- imageHeigth / 2);
|
||||
getCanvas().getContext2d().putImageData(imageData, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public GPSFixDTO getBoatFix() {
|
||||
|
||||
+30
-19
@@ -9,30 +9,30 @@ import com.google.gwt.maps.client.overlay.Overlay;
|
||||
|
||||
public abstract class CanvasOverlay extends Overlay {
|
||||
|
||||
protected final Canvas canvas;
|
||||
private final Canvas canvas;
|
||||
|
||||
protected boolean isSelected;
|
||||
private boolean isSelected;
|
||||
|
||||
protected MapWidget map;
|
||||
|
||||
protected MapPane pane;
|
||||
private MapWidget map;
|
||||
|
||||
private MapPane pane;
|
||||
|
||||
private LatLng latLngPosition;
|
||||
|
||||
protected LatLng latLngPosition;
|
||||
|
||||
public CanvasOverlay() {
|
||||
canvas = Canvas.createIfSupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
protected void initialize(MapWidget map) {
|
||||
this.map = map;
|
||||
pane = map.getPane(MapPaneType.MAP_PANE);
|
||||
pane.add(canvas);
|
||||
this.map = map;
|
||||
this.pane = map.getPane(MapPaneType.MAP_PANE);
|
||||
getPane().add(getCanvas());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void remove() {
|
||||
canvas.removeFromParent();
|
||||
getCanvas().removeFromParent();
|
||||
}
|
||||
|
||||
public Canvas getCanvas() {
|
||||
@@ -40,15 +40,13 @@ public abstract class CanvasOverlay extends Overlay {
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
if(canvas == null)
|
||||
return false;
|
||||
|
||||
return canvas.isVisible();
|
||||
return getCanvas() != null && getCanvas().isVisible();
|
||||
}
|
||||
|
||||
public void setVisible(boolean isVisible) {
|
||||
if(canvas != null)
|
||||
canvas.setVisible(isVisible);
|
||||
if (getCanvas() != null) {
|
||||
getCanvas().setVisible(isVisible);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
@@ -62,4 +60,17 @@ public abstract class CanvasOverlay extends Overlay {
|
||||
public LatLng getLatLngPosition() {
|
||||
return latLngPosition;
|
||||
}
|
||||
|
||||
protected void setLatLngPosition(LatLng latLngPosition) {
|
||||
this.latLngPosition = latLngPosition;
|
||||
}
|
||||
|
||||
protected MapWidget getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
protected MapPane getPane() {
|
||||
return pane;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-1
@@ -694,7 +694,6 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe
|
||||
final BoatCanvasOverlay boatCanvas = new BoatCanvasOverlay(competitorDTO, raceMapImageManager);
|
||||
boatCanvas.setSelected(highlighted);
|
||||
boatCanvas.getCanvas().setTitle(competitorDTO.name);
|
||||
|
||||
boatCanvas.getCanvas().addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
+15
-22
@@ -32,11 +32,11 @@ public class WindSensorOverlay extends CanvasOverlay {
|
||||
canvasWidth = 28;
|
||||
canvasHeight = 28;
|
||||
|
||||
if(canvas != null) {
|
||||
canvas.setWidth(String.valueOf(canvasWidth));
|
||||
canvas.setHeight(String.valueOf(canvasHeight));
|
||||
canvas.setCoordinateSpaceWidth(canvasWidth);
|
||||
canvas.setCoordinateSpaceHeight(canvasHeight);
|
||||
if(getCanvas() != null) {
|
||||
getCanvas().setWidth(String.valueOf(canvasWidth));
|
||||
getCanvas().setHeight(String.valueOf(canvasHeight));
|
||||
getCanvas().setCoordinateSpaceWidth(canvasWidth);
|
||||
getCanvas().setCoordinateSpaceHeight(canvasHeight);
|
||||
}
|
||||
transformer = raceMapImageManager.getExpeditionWindIconTransformer();
|
||||
}
|
||||
@@ -49,35 +49,28 @@ public class WindSensorOverlay extends CanvasOverlay {
|
||||
@Override
|
||||
protected void redraw(boolean force) {
|
||||
boolean hasValidWind = false;
|
||||
if(windTrackInfoDTO != null && windTrackInfoDTO.windFixes.size() > 0) {
|
||||
if (windTrackInfoDTO != null && windTrackInfoDTO.windFixes.size() > 0) {
|
||||
WindDTO windDTO = windTrackInfoDTO.windFixes.get(0);
|
||||
PositionDTO position = windDTO.position;
|
||||
// Attention: sometimes there is no valid position for the wind source available -> ignore the wind in this case
|
||||
if(position != null) {
|
||||
if (position != null) {
|
||||
double rotationDegOfWindSymbol = windDTO.dampenedTrueWindBearingDeg;
|
||||
|
||||
ImageData imageData = transformer.getTransformedImageData(rotationDegOfWindSymbol, 1.0);
|
||||
latLngPosition = LatLng.newInstance(windDTO.position.latDeg, windDTO.position.lngDeg);
|
||||
|
||||
Point sensorPositionInPx = map.convertLatLngToDivPixel(latLngPosition);
|
||||
|
||||
pane.setWidgetPosition(canvas, sensorPositionInPx.getX() - canvasWidth / 2, sensorPositionInPx.getY() - canvasHeight / 2);
|
||||
|
||||
setLatLngPosition(LatLng.newInstance(windDTO.position.latDeg, windDTO.position.lngDeg));
|
||||
Point sensorPositionInPx = getMap().convertLatLngToDivPixel(getLatLngPosition());
|
||||
getPane().setWidgetPosition(getCanvas(), sensorPositionInPx.getX() - canvasWidth / 2, sensorPositionInPx.getY() - canvasHeight / 2);
|
||||
String title = stringMessages.wind() + " "
|
||||
+ Math.round(windDTO.dampenedTrueWindFromDeg) + " " + stringMessages.degreesShort()+ " ("
|
||||
+ WindSourceTypeFormatter.format(windSource, stringMessages) + ")";
|
||||
canvas.setTitle(title);
|
||||
|
||||
canvas.getContext2d().putImageData(imageData, 0, 0);
|
||||
getCanvas().setTitle(title);
|
||||
getCanvas().getContext2d().putImageData(imageData, 0, 0);
|
||||
hasValidWind = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!hasValidWind) {
|
||||
latLngPosition = null;
|
||||
if (!hasValidWind) {
|
||||
setLatLngPosition(null);
|
||||
}
|
||||
|
||||
canvas.setVisible(hasValidWind);
|
||||
getCanvas().setVisible(hasValidWind);
|
||||
}
|
||||
|
||||
public WindTrackInfoDTO getWindTrackInfoDTO() {
|
||||
|
||||
Reference in New Issue
Block a user