One more WWA change to go with the previous performance change

- text location needs to be recalulated with different zoom levels
This commit is contained in:
srcarter3 2023-03-28 16:52:32 -07:00
parent fe81f4ba69
commit 7e7ff7e1e6

View file

@ -230,6 +230,7 @@ public abstract class AbstractWWAResource extends
private TimeRange currentFramePeriod = null; private TimeRange currentFramePeriod = null;
private boolean currentLastFrame = false; private boolean currentLastFrame = false;
private HashMap<String, WarningEntry> currentCandidates = new HashMap<>(); private HashMap<String, WarningEntry> currentCandidates = new HashMap<>();
private float currentZoom = Float.MIN_VALUE;
/** The dialog used to change display properties */ /** The dialog used to change display properties */
private DrawingPropertiesDialog drawingDialog; private DrawingPropertiesDialog drawingDialog;
@ -584,19 +585,7 @@ public abstract class AbstractWWAResource extends
if (record != null && record.getGeometry() != null) { if (record != null && record.getGeometry() != null) {
//only calculate the drawable strings the first time through //only calculate the drawable strings the first time through
if(entry.paramsDS == null || (entry.emergencyDS == null && EmergencyType.isEmergency(record.getRawmessage()))){ if(entry.paramsDS == null || (entry.emergencyDS == null && EmergencyType.isEmergency(record.getRawmessage()))){
// Calculate the upper left portion of the polygon
Coordinate upperLeft = new Coordinate(180, -90);
for (Coordinate c : record.getGeometry().getCoordinates()) {
if (c.y - c.x > upperLeft.y - upperLeft.x) {
upperLeft = c;
}
}
double[] d = descriptor.worldToPixel(new double[] {
upperLeft.x, upperLeft.y });
d[0] -= paintProps.getZoomLevel() * 100;
double mapWidth = descriptor.getMapWidth() double mapWidth = descriptor.getMapWidth()
* paintProps.getZoomLevel() / 1000; * paintProps.getZoomLevel() / 1000;
String[] fullText = getText(record, mapWidth); String[] fullText = getText(record, mapWidth);
@ -608,8 +597,7 @@ public abstract class AbstractWWAResource extends
if(drawTime){ if(drawTime){
textToPrint[1] = fullText[1]; textToPrint[1] = fullText[1];
} }
if (warningsFont == null) { if (warningsFont == null) {
warningsFont = target.initializeFont(target warningsFont = target.initializeFont(target
.getDefaultFont().getFontName(), 9, .getDefaultFont().getFontName(), 9,
@ -620,7 +608,6 @@ public abstract class AbstractWWAResource extends
DrawableString params = new DrawableString(textToPrint, entry.color); DrawableString params = new DrawableString(textToPrint, entry.color);
params.font = warningsFont; params.font = warningsFont;
params.setCoordinates(d[0], d[1]);
params.horizontalAlignment = HorizontalAlignment.RIGHT; params.horizontalAlignment = HorizontalAlignment.RIGHT;
params.verticallAlignment = VerticalAlignment.BOTTOM; params.verticallAlignment = VerticalAlignment.BOTTOM;
params.magnification = getCapability( params.magnification = getCapability(
@ -636,8 +623,7 @@ public abstract class AbstractWWAResource extends
DrawableString emergencyString = new DrawableString( DrawableString emergencyString = new DrawableString(
params); params);
emergencyString.setCoordinates(d[0],
d[1] + (paintProps.getZoomLevel()) * 90);
emergencyString.font = emergencyFont; emergencyString.font = emergencyFont;
emergencyString.setText(new String[] { "", "", emergencyString.setText(new String[] { "", "",
" " + EmergencyType.EMER, "" }, entry.color); " " + EmergencyType.EMER, "" }, entry.color);
@ -647,6 +633,11 @@ public abstract class AbstractWWAResource extends
entry.textStr = fullText[0]; entry.textStr = fullText[0];
entry.timeStr = fullText[1]; entry.timeStr = fullText[1];
} }
//if zoom has changed, recalucate text positions
if(currentZoom != paintProps.getZoomLevel()) {
calculateTextPosition(entry, paintProps);
}
if (EmergencyType.isEmergency(record.getRawmessage())) { if (EmergencyType.isEmergency(record.getRawmessage())) {
target.drawStrings(entry.emergencyDS); target.drawStrings(entry.emergencyDS);
} }
@ -667,6 +658,32 @@ public abstract class AbstractWWAResource extends
} }
} }
} }
private void calculateTextPosition(WarningEntry entry, PaintProperties paintProps) {
AbstractWarningRecord record = entry.record;
// Calculate the upper left portion of the polygon
Coordinate upperLeft = new Coordinate(180, -90);
for (Coordinate c : record.getGeometry().getCoordinates()) {
if (c.y - c.x > upperLeft.y - upperLeft.x) {
upperLeft = c;
}
}
double[] d = descriptor.worldToPixel(new double[] {
upperLeft.x, upperLeft.y });
d[0] -= paintProps.getZoomLevel() * 100;
//update the drawable strings
if(entry.emergencyDS != null) {
entry.emergencyDS.setCoordinates(d[0], d[1] + (paintProps.getZoomLevel()) * 90);
}
if(entry.paramsDS != null) {
entry.paramsDS.setCoordinates(d[0], d[1]);
}
}
abstract protected String getEventKey(WarningEntry entry); abstract protected String getEventKey(WarningEntry entry);