Skip to content

Commit b92f8ff

Browse files
committed
MapillaryLayer: Avoid allocations of Instant during painting
Signed-off-by: Taylor Smock <tsmock@meta.com>
1 parent 7a78e98 commit b92f8ff

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/layer/MapillaryLayer.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,13 @@ public final class MapillaryLayer extends MVTLayer implements ActiveLayerChangeL
135135
/** The color scale used when drawing using velocity */
136136
private final ColorScale velocityScale = ColorScale.createHSBScale(256);
137137
/** The color scale used when drawing using date */
138-
private final ColorScale dateScale = ColorScale.createFixedScale(new Color[] { ColorHelper.html2color("e17155"), // Really
139-
// old
140-
// color
141-
ColorHelper.html2color("fbc01b"), // Old color
142-
MapillaryColorScheme.SEQ_UNSELECTED // New color
138+
private final ColorScale dateScale = ColorScale.createFixedScale(
139+
// Really old color
140+
new Color[] { ColorHelper.html2color("e17155"),
141+
// Old color
142+
ColorHelper.html2color("fbc01b"),
143+
// New color
144+
MapillaryColorScheme.SEQ_UNSELECTED
143145
}).addTitle(tr("Time"));
144146

145147
/** The color scale used when drawing using direction */
@@ -189,8 +191,8 @@ private MapillaryLayer() {
189191
private void setupColorScales() {
190192
this.dateScale.setNoDataColor(MapillaryColorScheme.SEQ_UNSELECTED);
191193
// ChronoUnit.YEARS isn't supported since a year can be either 365 or 366.
192-
this.dateScale.setRange(Instant.now().minus(4 * 365L, ChronoUnit.DAYS).toEpochMilli(),
193-
Instant.now().toEpochMilli());
194+
this.dateScale.setRange(Instant.now().minus(4 * 365L, ChronoUnit.DAYS).getEpochSecond(),
195+
Instant.now().getEpochSecond());
194196
this.directionScale.setNoDataColor(MapillaryColorScheme.SEQ_UNSELECTED);
195197
this.velocityScale.setNoDataColor(MapillaryColorScheme.SEQ_UNSELECTED);
196198
}
@@ -414,7 +416,10 @@ private void drawSequence(final Graphics2D g, final MapView mv, final IWay<?> se
414416
private Color getColor(final INode node) {
415417
switch (this.drawType) {
416418
case DATE:
417-
return this.dateScale.getColor(MapillaryImageUtils.getDate(node).toEpochMilli());
419+
if (node.isTimestampEmpty()) {
420+
MapillaryImageUtils.getDate(node);
421+
}
422+
return this.dateScale.getColor(node.getRawTimestamp());
418423
case VELOCITY_FOOT:
419424
case VELOCITY_BIKE:
420425
case VELOCITY_CAR:

0 commit comments

Comments
 (0)