Class GpxDrawHelper
- java.lang.Object
-
- org.openstreetmap.josm.gui.layer.gpx.GpxDrawHelper
-
- All Implemented Interfaces:
GpxData.GpxDataChangeListener
,SystemOfMeasurement.SoMChangeListener
,MapViewPaintable.LayerPainter
,MapViewPaintable.PaintableInvalidationListener
public class GpxDrawHelper extends Object implements SystemOfMeasurement.SoMChangeListener, MapViewPaintable.LayerPainter, MapViewPaintable.PaintableInvalidationListener, GpxData.GpxDataChangeListener
Class that helps to draw large set of GPS tracks with different colors and options- Since:
- 7319
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GpxDrawHelper.ColorMode
Different color modes
-
Field Summary
Fields Modifier and Type Field Description private boolean
alphaLines
private boolean
arrows
private int
arrowsDelta
don't draw arrows nearer to each other than thisprivate boolean
arrowsFast
paint direction arrow with alternate math.private Color
colorCache
private Color
colorCacheTransparent
private GpxDrawHelper.ColorMode
colored
Mode of the line coloringprivate boolean
colorModeDynamic
private boolean
computeCacheColorDynamic
private GpxDrawHelper.ColorMode
computeCacheColored
private Color
computeCacheColorUsed
private int
computeCacheHeatMapDrawColorTableIdx
private int
computeCacheHeatMapDrawGain
private int
computeCacheHeatMapDrawLowerLimit
private boolean
computeCacheHeatMapDrawPointMode
private boolean
computeCacheInSync
private int
computeCacheMaxLineLengthUsed
private int
computeCacheVelocityTune
private GpxData
data
private ColorScale
dateScale
static NamedColorProperty
DEFAULT_COLOR_PROPERTY
The default color property that is used for drawing GPX points.private static int[][]
dir
private ColorScale
directionScale
private boolean
forceLines
private boolean
gpxLayerInvalidated
private int
hdopAlpha
Opacity for hdop pointsprivate boolean
hdopCircle
private int
hdoprange
maximum value of displayed HDOP, minimum is 0private ColorScale
hdopScale
Colors (without custom alpha channel, if given) for HDOP painting.(package private) int
heatMapCacheLineWith
(package private) Rectangle
heatMapCacheScreenBounds
private int
heatMapDrawColorTableIdx
private boolean
heatMapDrawExtraLine
heat map parametersprivate int
heatMapDrawGain
private int
heatMapDrawLowerLimit
private boolean
heatMapDrawPointMode
private Graphics2D
heatMapGraph2d
private BufferedImage
heatMapImgGray
private Color[]
heatMapLutColor
private static Color[]
heatMapLutColorJosmBrown2Green
private static Color[]
heatMapLutColorJosmInferno
private static Color[]
heatMapLutColorJosmRed2Blue
private static Color[]
heatMapLutColorJosmViridis
(package private) MapViewState
heatMapMapViewState
private List<Integer>
heatMapPolyX
private List<Integer>
heatMapPolyY
private boolean
large
paint large dots for pointsprivate int
largePointAlpha
private int
largesize
private GpxLayer
layer
private boolean
lines
private int
lineWidth
width of line for paintprivate static int
ll0
private int
maxLineLength
don't draw lines if longer than x metersprivate double
minTrackDurationForTimeColoring
private Color
neutralColor
private static double
PHI
private ColorScale
qualityScale
private static Color[]
rtkLibQualityColors
private static int
sl4
private static int
sl9
private ColorScale
velocityScale
private int
velocityTune
max speed for coloring - allows to tweak line coloring for different speed levels.
-
Constructor Summary
Constructors Constructor Description GpxDrawHelper(GpxLayer gpxLayer)
Constructs a newGpxDrawHelper
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
calculateColors()
Calculate colors of way segments based on latest configuration settingsprivate void
checkCache()
Check cache validity set necessary flagsprotected static Color[]
createColorFromResource(String str)
Creates a colormap by using a static color map with 1..n colors (RGB 0.0 ..1.0)protected static Color[]
createColorLut(int lowerLimit, Color... colors)
Creates a distributed colormap by linear blending between colorsprotected static BufferedImage
createImageGradientMap(int width, int height, Color... colors)
Generates a linear gradient map imageprotected static Color
darkerColor(Color in, float adjust)
Creates a darker colorvoid
detachFromMapView(MapViewPaintable.MapViewEvent event)
Called when the layer is removed from the map view and this painter is not used any more.void
drawAll(Graphics2D g, MapView mv, List<WayPoint> visibleSegments, Bounds clipBounds)
Draw all enabled GPX elements of layer.private void
drawArrows(Graphics2D g, MapView mv, List<WayPoint> visibleSegments)
Draw all GPX arraysvoid
drawColorBar(Graphics2D g, MapView mv)
Draw all GPX arraysprivate static void
drawHeatGrayDotMap(Graphics2D gB, MapView mv, List<WayPoint> listSegm, int drawSize)
Draw a dotted heat mapprivate void
drawHeatGrayLineMap(Graphics2D gB, MapView mv, List<WayPoint> listSegm, Composite foreComp, Stroke foreStroke, Composite backComp, Stroke backStroke)
Draw gray heat map with current Graphics2D settingprivate void
drawHeatMap(Graphics2D g, MapView mv, List<WayPoint> visibleSegments)
Collect and draw GPS segments and displays a heat-mapprivate void
drawHeatMapGrayMap(Graphics2D g, BufferedImage imgGray, int sampleRaster, int outlineWidth)
Map the gray map to heat map and draw them with current Graphics2D settingprivate static void
drawHeatSurfaceLine(Graphics2D g, Point fromPnt, Point toPnt, int drawSize, double rmsSizeX, double rmsSizeY, double dropRate)
Draw a dotted surface lineprivate void
drawLines(Graphics2D g, MapView mv, List<WayPoint> visibleSegments)
Draw all GPX ways segmentsprivate void
drawLinesAlpha(Graphics2D g, MapView mv, List<WayPoint> visibleSegments, float layerAlpha)
Draw GPX lines by using alpha blendingprivate void
drawPoints(Graphics2D g, MapView mv, List<WayPoint> visibleSegments)
Draw all GPX pointsprivate void
ensureTrackVisibilityLength()
ensures the trackVisibility array has the correct length without losing data.private void
fixColors(List<WayPoint> visibleSegments)
Apply default color configuration to way segmentsstatic ImageIcon
getColorMapImageIcon(Color userColor, int tableIdx, int size)
Generates a IconGpxDrawHelper.ColorMode
getColorMode()
Read coloring mode for specified layer from preferencesprotected Iterable<Line>
getLinesIterable(boolean[] trackVisibility)
void
gpxDataChanged(GpxData.GpxDataChangeEvent e)
callback when data is changed, invalidate cached configuration parametersprivate List<WayPoint>
listVisibleSegments(Bounds box)
private String
opt(String key)
private boolean
optBool(String key)
private int
optInt(String key)
void
paint(MapViewGraphics graphics)
Paints the given layer.void
paintableInvalidated(MapViewPaintable.PaintableInvalidationEvent event)
Called whenever aMapViewPaintable.PaintableInvalidationEvent
is fired.void
readPreferences()
Read all drawing-related settings from preferencesprotected static Color[]
selectColorMap(Color userColor, int tableIdx)
Returns the next user color mapprivate void
setupColors()
void
systemOfMeasurementChanged(String oldSoM, String newSoM)
The current SoM has changed.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.data.gpx.GpxData.GpxDataChangeListener
modifiedStateChanged
-
-
-
-
Field Detail
-
DEFAULT_COLOR_PROPERTY
public static final NamedColorProperty DEFAULT_COLOR_PROPERTY
The default color property that is used for drawing GPX points.- Since:
- 15496
-
forceLines
private boolean forceLines
-
alphaLines
private boolean alphaLines
-
arrows
private boolean arrows
-
lineWidth
private int lineWidth
width of line for paint
-
maxLineLength
private int maxLineLength
don't draw lines if longer than x meters
-
lines
private boolean lines
-
large
private boolean large
paint large dots for points
-
largesize
private int largesize
-
hdopCircle
private boolean hdopCircle
-
arrowsFast
private boolean arrowsFast
paint direction arrow with alternate math. may be faster
-
arrowsDelta
private int arrowsDelta
don't draw arrows nearer to each other than this
-
minTrackDurationForTimeColoring
private double minTrackDurationForTimeColoring
-
hdoprange
private int hdoprange
maximum value of displayed HDOP, minimum is 0
-
PHI
private static final double PHI
-
computeCacheInSync
private boolean computeCacheInSync
-
computeCacheMaxLineLengthUsed
private int computeCacheMaxLineLengthUsed
-
computeCacheColorUsed
private Color computeCacheColorUsed
-
computeCacheColorDynamic
private boolean computeCacheColorDynamic
-
computeCacheColored
private GpxDrawHelper.ColorMode computeCacheColored
-
computeCacheVelocityTune
private int computeCacheVelocityTune
-
computeCacheHeatMapDrawColorTableIdx
private int computeCacheHeatMapDrawColorTableIdx
-
computeCacheHeatMapDrawPointMode
private boolean computeCacheHeatMapDrawPointMode
-
computeCacheHeatMapDrawGain
private int computeCacheHeatMapDrawGain
-
computeCacheHeatMapDrawLowerLimit
private int computeCacheHeatMapDrawLowerLimit
-
colorCache
private Color colorCache
-
colorCacheTransparent
private Color colorCacheTransparent
-
colored
private GpxDrawHelper.ColorMode colored
Mode of the line coloring
-
velocityTune
private int velocityTune
max speed for coloring - allows to tweak line coloring for different speed levels.
-
colorModeDynamic
private boolean colorModeDynamic
-
neutralColor
private Color neutralColor
-
largePointAlpha
private int largePointAlpha
-
velocityScale
private ColorScale velocityScale
-
hdopScale
private ColorScale hdopScale
Colors (without custom alpha channel, if given) for HDOP painting.
-
qualityScale
private ColorScale qualityScale
-
dateScale
private ColorScale dateScale
-
directionScale
private ColorScale directionScale
-
hdopAlpha
private int hdopAlpha
Opacity for hdop points
-
ll0
private static final int ll0
- See Also:
- Constant Field Values
-
sl4
private static final int sl4
- See Also:
- Constant Field Values
-
sl9
private static final int sl9
- See Also:
- Constant Field Values
-
dir
private static final int[][] dir
-
heatMapDrawExtraLine
private boolean heatMapDrawExtraLine
heat map parameters
-
heatMapDrawColorTableIdx
private int heatMapDrawColorTableIdx
-
heatMapDrawPointMode
private boolean heatMapDrawPointMode
-
heatMapDrawGain
private int heatMapDrawGain
-
heatMapDrawLowerLimit
private int heatMapDrawLowerLimit
-
heatMapImgGray
private BufferedImage heatMapImgGray
-
heatMapGraph2d
private Graphics2D heatMapGraph2d
-
heatMapCacheScreenBounds
Rectangle heatMapCacheScreenBounds
-
heatMapMapViewState
MapViewState heatMapMapViewState
-
heatMapCacheLineWith
int heatMapCacheLineWith
-
heatMapPolyX
private final List<Integer> heatMapPolyX
-
heatMapPolyY
private final List<Integer> heatMapPolyY
-
heatMapLutColorJosmInferno
private static final Color[] heatMapLutColorJosmInferno
-
heatMapLutColorJosmViridis
private static final Color[] heatMapLutColorJosmViridis
-
heatMapLutColorJosmBrown2Green
private static final Color[] heatMapLutColorJosmBrown2Green
-
heatMapLutColorJosmRed2Blue
private static final Color[] heatMapLutColorJosmRed2Blue
-
rtkLibQualityColors
private static final Color[] rtkLibQualityColors
-
heatMapLutColor
private Color[] heatMapLutColor
-
gpxLayerInvalidated
private boolean gpxLayerInvalidated
-
-
Constructor Detail
-
GpxDrawHelper
public GpxDrawHelper(GpxLayer gpxLayer)
Constructs a newGpxDrawHelper
.- Parameters:
gpxLayer
- The layer to draw- Since:
- 12157
-
-
Method Detail
-
setupColors
private void setupColors()
-
systemOfMeasurementChanged
public void systemOfMeasurementChanged(String oldSoM, String newSoM)
Description copied from interface:SystemOfMeasurement.SoMChangeListener
The current SoM has changed.- Specified by:
systemOfMeasurementChanged
in interfaceSystemOfMeasurement.SoMChangeListener
- Parameters:
oldSoM
- The old system of measurementnewSoM
- The new (current) system of measurement
-
getColorMode
public GpxDrawHelper.ColorMode getColorMode()
Read coloring mode for specified layer from preferences- Returns:
- coloring mode
-
readPreferences
public void readPreferences()
Read all drawing-related settings from preferences
-
paint
public void paint(MapViewGraphics graphics)
Description copied from interface:MapViewPaintable.LayerPainter
Paints the given layer.This can be called in any thread at any time. You will not receive parallel calls for the same map view but you can receive parallel calls if you use the same
MapViewPaintable.LayerPainter
for different map views.- Specified by:
paint
in interfaceMapViewPaintable.LayerPainter
- Parameters:
graphics
- The graphics object of the map view you should use. It provides you with a content pane, the bounds and the view state.
-
listVisibleSegments
private List<WayPoint> listVisibleSegments(Bounds box)
-
getLinesIterable
protected Iterable<Line> getLinesIterable(boolean[] trackVisibility)
-
ensureTrackVisibilityLength
private void ensureTrackVisibilityLength()
ensures the trackVisibility array has the correct length without losing data. TODO: Make this nicer by syncing the trackVisibility automatically. additional entries are initialized to true;
-
drawAll
public void drawAll(Graphics2D g, MapView mv, List<WayPoint> visibleSegments, Bounds clipBounds)
Draw all enabled GPX elements of layer.- Parameters:
g
- the common draw object to usemv
- the meta data to current displayed areavisibleSegments
- segments visible in the current scope of mvclipBounds
- the clipping rectangle for the current view- Since:
- 14748 : new parameter clipBounds
-
calculateColors
public void calculateColors()
Calculate colors of way segments based on latest configuration settings
-
drawLines
private void drawLines(Graphics2D g, MapView mv, List<WayPoint> visibleSegments)
Draw all GPX ways segments- Parameters:
g
- the common draw object to usemv
- the meta data to current displayed areavisibleSegments
- segments visible in the current scope of mv
-
drawArrows
private void drawArrows(Graphics2D g, MapView mv, List<WayPoint> visibleSegments)
Draw all GPX arrays- Parameters:
g
- the common draw object to usemv
- the meta data to current displayed areavisibleSegments
- segments visible in the current scope of mv
-
drawPoints
private void drawPoints(Graphics2D g, MapView mv, List<WayPoint> visibleSegments)
Draw all GPX points- Parameters:
g
- the common draw object to usemv
- the meta data to current displayed areavisibleSegments
- segments visible in the current scope of mv
-
drawLinesAlpha
private void drawLinesAlpha(Graphics2D g, MapView mv, List<WayPoint> visibleSegments, float layerAlpha)
Draw GPX lines by using alpha blending- Parameters:
g
- the common draw object to usemv
- the meta data to current displayed areavisibleSegments
- segments visible in the current scope of mvlayerAlpha
- the color alpha value set for that operation
-
createImageGradientMap
protected static BufferedImage createImageGradientMap(int width, int height, Color... colors)
Generates a linear gradient map image- Parameters:
width
- image widthheight
- image heightcolors
- 1..n color descriptions- Returns:
- image object
-
createColorLut
protected static Color[] createColorLut(int lowerLimit, Color... colors)
Creates a distributed colormap by linear blending between colors- Parameters:
lowerLimit
- lower limit for first visible colorcolors
- 1..n colors- Returns:
- array of Color objects
-
darkerColor
protected static Color darkerColor(Color in, float adjust)
Creates a darker color- Parameters:
in
- Color objectadjust
- darker adjustment amount- Returns:
- new Color
-
createColorFromResource
protected static Color[] createColorFromResource(String str)
Creates a colormap by using a static color map with 1..n colors (RGB 0.0 ..1.0)- Parameters:
str
- the filename (without extension) to look for into data/gpx- Returns:
- the parsed colormap
-
selectColorMap
protected static Color[] selectColorMap(Color userColor, int tableIdx)
Returns the next user color map- Parameters:
userColor
- - default or fallback user colortableIdx
- - selected user color index- Returns:
- color array
-
getColorMapImageIcon
public static ImageIcon getColorMapImageIcon(Color userColor, int tableIdx, int size)
Generates a Icon- Parameters:
userColor
- selected user colortableIdx
- tabled indexsize
- size of the image- Returns:
- a image icon that shows the
-
drawHeatGrayLineMap
private void drawHeatGrayLineMap(Graphics2D gB, MapView mv, List<WayPoint> listSegm, Composite foreComp, Stroke foreStroke, Composite backComp, Stroke backStroke)
Draw gray heat map with current Graphics2D setting- Parameters:
gB
- the common draw object to usemv
- the meta data to current displayed arealistSegm
- segments visible in the current scope of mvforeComp
- composite use to draw foreground objectsforeStroke
- stroke use to draw foreground objectsbackComp
- composite use to draw background objectsbackStroke
- stroke use to draw background objects
-
drawHeatMapGrayMap
private void drawHeatMapGrayMap(Graphics2D g, BufferedImage imgGray, int sampleRaster, int outlineWidth)
Map the gray map to heat map and draw them with current Graphics2D setting- Parameters:
g
- the common draw object to useimgGray
- gray scale input imagesampleRaster
- the line with for drawingoutlineWidth
- line width for outlines
-
drawHeatMap
private void drawHeatMap(Graphics2D g, MapView mv, List<WayPoint> visibleSegments)
Collect and draw GPS segments and displays a heat-map- Parameters:
g
- the common draw object to usemv
- the meta data to current displayed areavisibleSegments
- segments visible in the current scope of mv
-
drawHeatGrayDotMap
private static void drawHeatGrayDotMap(Graphics2D gB, MapView mv, List<WayPoint> listSegm, int drawSize)
Draw a dotted heat map- Parameters:
gB
- the common draw object to usemv
- the meta data to current displayed arealistSegm
- segments visible in the current scope of mvdrawSize
- draw size of draw element
-
drawHeatSurfaceLine
private static void drawHeatSurfaceLine(Graphics2D g, Point fromPnt, Point toPnt, int drawSize, double rmsSizeX, double rmsSizeY, double dropRate)
Draw a dotted surface line- Parameters:
g
- the common draw object to usefromPnt
- start pointtoPnt
- end pointdrawSize
- size of draw elementsrmsSizeX
- RMS size of circle for X (width)rmsSizeY
- RMS size of circle for Y (height)dropRate
- Pixel render drop rate
-
fixColors
private void fixColors(List<WayPoint> visibleSegments)
Apply default color configuration to way segments- Parameters:
visibleSegments
- segments visible in the current scope of mv
-
checkCache
private void checkCache()
Check cache validity set necessary flags
-
gpxDataChanged
public void gpxDataChanged(GpxData.GpxDataChangeEvent e)
callback when data is changed, invalidate cached configuration parameters- Specified by:
gpxDataChanged
in interfaceGpxData.GpxDataChangeListener
- Parameters:
e
- The event
-
drawColorBar
public void drawColorBar(Graphics2D g, MapView mv)
Draw all GPX arrays- Parameters:
g
- the common draw object to usemv
- the meta data to current displayed area
-
paintableInvalidated
public void paintableInvalidated(MapViewPaintable.PaintableInvalidationEvent event)
Description copied from interface:MapViewPaintable.PaintableInvalidationListener
Called whenever aMapViewPaintable.PaintableInvalidationEvent
is fired. This might be called from any thread.- Specified by:
paintableInvalidated
in interfaceMapViewPaintable.PaintableInvalidationListener
- Parameters:
event
- The event
-
detachFromMapView
public void detachFromMapView(MapViewPaintable.MapViewEvent event)
Description copied from interface:MapViewPaintable.LayerPainter
Called when the layer is removed from the map view and this painter is not used any more.This method is called once on the painter returned by
AbstractMapViewPaintable.attachToMapView(org.openstreetmap.josm.gui.layer.MapViewPaintable.MapViewEvent)
- Specified by:
detachFromMapView
in interfaceMapViewPaintable.LayerPainter
- Parameters:
event
- The event.
-
-