|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectus.zuercher.gpx2map.Gpx2Map
public class Gpx2Map
Gpx2Map provides an API for generating maps with GPX data plotted on them. It is intended to be interface-agnostic while simultaneously providing progress information as it proceeds.
Gpx2Map should never refer to System.out
or
System.err
. Instead, use the private field out
to produce informational messages and the
ProgressMeterFactory
parameter to
execute(MessageSink, ProgressMeterFactory)
to provide
progress information.
Field Summary | |
---|---|
private boolean |
boundByCoords
Indicates that the map boundaries should be set by user-specified values. |
private boolean |
boundByRoutes
Indicates that the map boundaries should include all route-points. |
private boolean |
boundByTracks
Indicates that the map boundaries should include all track-points. |
private boolean |
boundByWayPoints
Indicates that the map boundaries should include all way-points. |
private File |
cacheDir
Map tile cache directory. |
static String |
DEFAULT_CACHE_DIR
Default cache directory name. |
static String |
DEFAULT_CACHE_DIR_SYS_PROP
System property used to override the DEFAULT_CACHE_DIR . |
private String |
fontName
Name of the font to use for labelling way-points, tracks and routes. |
private float |
fontSize
Size of the font, in points, to use for labelling way-points, tracks and routes. |
private List<File> |
gpxFiles
List of GPX files to parse. |
private boolean |
ignoreRoutes
Ignore routes from the GPX file(s). |
private boolean |
ignoreTracks
Ignore tracks from the GPX file(s). |
private boolean |
ignoreWayPoints
Ignore way-points from the GPX file(s). |
private boolean |
joinTrackSegments
Controls whether a track's segments are joined or not. |
private boolean |
labelRoutes
Controls whether routes are labelled or not. |
private boolean |
labelTracks
Controls whether tracks are labelled or not. |
private MapSource |
mapSource
Map source instance. |
private String |
mapSourceName
Configured name of the map source. |
private Map<String,String> |
mapSourceProperties
Map of map source property names to values. |
private Number |
margin
Margin size. |
private MarginUnits |
marginUnits
Margin units. |
private LatLon |
nwBounds
Northwest corner of map boundary. |
private MessageSink |
out
Informational output. |
private File |
output
Output Netpbm file. |
private Color |
routeColor
Color used to plot route-points, route lines and route labels. |
private MarkerStyle |
routePointStyle
Marker style used for route-points. |
private int |
routePointStyleRadius
Size of marker style used for route-points. |
private List<Route> |
routes
List of routes loaded from GPX files. |
private LatLon |
seBounds
Southeast corner of map boundary. |
private Color |
trackColor
Color used to plot track-points, track lines and track labels. |
private MarkerStyle |
trackPointStyle
Marker style used for track-points. |
private int |
trackPointStyleRadius
Size of marker style used for track-points. |
private List<Track> |
tracks
List of tracks loaded from GPX files. |
private Color |
wayPointColor
Color used to plot way-points their labels. |
private List<WayPoint> |
wayPoints
List of way-points loaded from GPX files. |
private MarkerStyle |
wayPointStyle
Marker style used for way-points. |
private int |
wayPointStyleRadius
Size of marker style used for way-points. |
Constructor Summary | |
---|---|
Gpx2Map()
Constructs a new Gpx2Map instance. |
Method Summary | |
---|---|
void |
addGpxFile(File gpxFile)
Add a GPX file to the parse list. |
private void |
describeColorAndStyle(String id,
Color color,
MarkerStyle style,
int radius,
boolean labelled,
String fontName,
float fontSize)
Describes the given color and style of an arbitrary entity. |
private void |
describeColorsAndStyles()
Describes the colors and styles configured for tracks, way-points, and routes. |
void |
execute(MessageSink messageSink,
ProgressMeterFactory progressMeterFactory)
Using the configured settings, download map tiles, stitch them together into a map and plot way-points, tracks, and/or routes on it. |
static File |
getDefaultCacheDir()
Obtains the default cache directory location. |
static String |
getDefaultCacheDirName()
Obtain the default cache directory name. |
boolean |
isConfigured()
Tests if this class has been configured. |
private void |
loadGpsData()
Load GPS data for all GPX files. |
private void |
noteOutput()
Note the output file to the MessageSink. |
void |
setBounding(boolean boundByTracks,
boolean boundByWayPoints,
boolean boundByRoutes,
LatLon nwBounds,
LatLon seBounds)
Configure the bounds of the output map. |
private void |
setBoundingBox()
Configures map boundaries based on values provided by calls to setBounding(boolean, boolean, boolean, LatLon, LatLon)
and setMargin(Number, MarginUnits) . |
private void |
setCacheDir()
Configure the mapSource with the cacheDir and note
the cache directory on the MessageSink. |
void |
setCacheDir(File cacheDir)
Set the location of the cache directory. |
void |
setFontName(String fontName)
Configure the font used for labelling way-points, tracks, and/or routes. |
void |
setFontSize(float size)
Configure the font size, in points, used for labelling way-points, tracks, and/or routes. |
void |
setIgnoreRoutes()
Configure Gpx2Map to ignore routes in the GPX files. |
void |
setIgnoreTracks()
Configure Gpx2Map to ignore tracks in the GPX files. |
void |
setIgnoreWaypoints()
Configure Gpx2Map to ignore way-points in the GPX files. |
void |
setJoinTrackSegments(boolean join)
Configure whether track segments are joined with a line or not. |
void |
setLabelRoutes(boolean label)
Configure route labelling. |
void |
setLabelTracks(boolean label)
Configure track labelling. |
private void |
setMapProperties()
Apply the configured map properties to mapSource . |
private void |
setMapSource()
Internally set the MapSource using mapSourceName . |
void |
setMapSource(String mapSourceName)
Set the map source name. |
void |
setMapSourceProperty(String mapSourceProperty,
String value)
Set a map source property. |
void |
setMargin(Number margin,
MarginUnits units)
Set map margin in the specific units. |
private void |
setMessageSink(MessageSink messageSink)
Internally set the MessageSink. |
void |
setOutput(File output)
Set the location of the output PPM file. |
void |
setRouteColor(Color color)
Set the color for route-points, route lines and route labels. |
void |
setRoutePointStyle(MarkerStyle style)
Configure the style for route-point markers. |
void |
setRoutePointStyleRadius(int radius)
Configure the radius (size) for route-point markers. |
void |
setTrackColor(Color color)
Set the color for track-points, track lines and track labels. |
void |
setTrackPointStyle(MarkerStyle style)
Configure the style for track-point markers. |
void |
setTrackPointStyleRadius(int radius)
Configure the radius (size) for track-point markers. |
void |
setWayPointColor(Color color)
Set the color for way-points and labels. |
void |
setWayPointStyle(MarkerStyle style)
Configure the style for way-point markers. |
void |
setWayPointStyleRadius(int radius)
Configure the radius (size) for way-point markers. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_CACHE_DIR
public static final String DEFAULT_CACHE_DIR_SYS_PROP
DEFAULT_CACHE_DIR
.
private MessageSink out
private String mapSourceName
private Map<String,String> mapSourceProperties
private MapSource mapSource
mapSourceName
.
private List<File> gpxFiles
private boolean ignoreTracks
ignoreWayPoints
, or ignoreRoutes
must always
be false. To put it another way, we can't ignore everything.
private boolean ignoreWayPoints
ignoreTracks
, or ignoreRoutes
must always
be false. To put it another way, we can't ignore everything.
private boolean ignoreRoutes
ignoreWayPoints
, or ignoreTracks
must always
be false. To put it another way, we can't ignore everything.
private List<Track> tracks
private List<WayPoint> wayPoints
private List<Route> routes
private Color trackColor
private Color wayPointColor
private Color routeColor
private MarkerStyle trackPointStyle
private int trackPointStyleRadius
private MarkerStyle wayPointStyle
private int wayPointStyleRadius
private MarkerStyle routePointStyle
private int routePointStyleRadius
private boolean labelTracks
private boolean labelRoutes
private File output
private File cacheDir
private String fontName
private float fontSize
private boolean joinTrackSegments
private boolean boundByTracks
boundByWayPoints
and/or
boundByRoutes
. Mutually exclusive with boundByCoords
.
private boolean boundByWayPoints
boundByTracks
and/or
boundByRoutes
. Mutually exclusive with boundByCoords
.
private boolean boundByRoutes
boundByWayPoints
and/or
boundByTracks
. Mutually exclusive with boundByCoords
.
private boolean boundByCoords
boundByTracks
,
boundByWayPoints
and boundByRoutes
.
private LatLon nwBounds
setBoundingBox()
.
private LatLon seBounds
setBoundingBox()
.
private Number margin
private MarginUnits marginUnits
Constructor Detail |
---|
public Gpx2Map()
Method Detail |
---|
public boolean isConfigured()
public void setMapSource(String mapSourceName)
mapSourceName
- the map source namepublic void setMapSourceProperty(String mapSourceProperty, String value)
execute(MessageSink, ProgressMeterFactory)
is called.
mapSourceProperty
- map source property name, must
correspond to a value returned by
MapSource.getProperties()
.value
- property valuepublic void addGpxFile(File gpxFile)
gpxFile
- location of a GPX filepublic void setOutput(File output)
output
- location of the output PPM file.public void setCacheDir(File cacheDir)
getDefaultCacheDirName()
.
cacheDir
- location of the cache directory.public void setIgnoreTracks()
public void setIgnoreWaypoints()
public void setIgnoreRoutes()
public void setBounding(boolean boundByTracks, boolean boundByWayPoints, boolean boundByRoutes, LatLon nwBounds, LatLon seBounds)
boundByTracks
- use tracksboundByWayPoints
- use way-pointsboundByRoutes
- use routesnwBounds
- use this location as the northwest corner of the mapseBounds
- use this location as the southeast corner of the map
IllegalArgumentException
- if the parameters do not configure
any bounds, if only one of the LatLon
values is non-null, or if the LatLon
values are not NW and SE cornerspublic void setMargin(Number margin, MarginUnits units)
margin
- the number of margin unitsunits
- the margin unitspublic void setTrackColor(Color color)
color
- color for track-points, track lines and track labels.public void setLabelTracks(boolean label)
label
- enable/disable track labelling.public void setTrackPointStyle(MarkerStyle style)
style
- the style for track-point markers.public void setTrackPointStyleRadius(int radius)
radius
- the radius (size) for track-point markers.public void setJoinTrackSegments(boolean join)
join
- enable/disable track segment joining.public void setWayPointColor(Color color)
color
- color for way-points and labels.public void setWayPointStyle(MarkerStyle style)
style
- the style for way-point markers.public void setWayPointStyleRadius(int radius)
radius
- the radius (size) for way-point markers.public void setRouteColor(Color color)
color
- color for route-points, route lines and route labels.public void setLabelRoutes(boolean label)
label
- enable/disable route labelling.public void setRoutePointStyle(MarkerStyle style)
style
- the style for route-point markers.public void setRoutePointStyleRadius(int radius)
radius
- the radius (size) for route-point markers.public void setFontName(String fontName)
fontName
- the name of the font to use (e.g. "Helvetica").public void setFontSize(float size)
size
- the size of the font, in pointspublic void execute(MessageSink messageSink, ProgressMeterFactory progressMeterFactory) throws UnknownMapSourceException, UnknownMapSourcePropertyException, MissingRequiredMapSourcePropertyException, GpxParsingException, BoundingException, IOException
messageSink
- sink for informational messagesprogressMeterFactory
- factory for ProgressMeter objects
used to indicate progress
UnknownMapSourceException
- if the configured map source name
is not known
UnknownMapSourcePropertyException
- if a configured map source
property is not known to the
map source
GpxParsingException
- if a GPX file cannot be parsed
BoundingException
- if bounds are set incompatibly with the loaded
GPX data (e.g., bound by tracks, but no tracks
are loaded).
IOException
- if there's an error downloading, converting, or
stitching map tiles; or if there's an error plotting
data on the map
MissingRequiredMapSourcePropertyException
- if a required map
source property was
not set.private void setMessageSink(MessageSink messageSink)
messageSink
- the MessageSink to use.private void setMapSource() throws UnknownMapSourceException
mapSourceName
.
UnknownMapSourceException
- if the mapSourceName
cannot be foundprivate void noteOutput() throws IOException
IOException
- if the output cannot be converted to canonical form.private void setCacheDir() throws IOException
mapSource
with the cacheDir
and note
the cache directory on the MessageSink.
IOException
- if the cache dir cannot be converted to
canonical form.public static String getDefaultCacheDirName()
DEFAULT_CACHE_DIR_SYS_PROP
exists. If so, its value is returned. Otherwise, returns
DEFAULT_CACHE_DIR
.
public static File getDefaultCacheDir()
getDefaultCacheDirName()
.
private void setMapProperties() throws UnknownMapSourcePropertyException, MissingRequiredMapSourcePropertyException
mapSource
.
UnknownMapSourcePropertyException
- if a map source
property name is not
known
MissingRequiredMapSourcePropertyException
- if a required map
source property was
not providedprivate void loadGpsData() throws GpxParsingException
GpxParsingException
- if any GPX file contains an error or cannot
be parsed.private void setBoundingBox() throws BoundingException
setBounding(boolean, boolean, boolean, LatLon, LatLon)
and setMargin(Number, MarginUnits)
. Upon return the
nwBounds
and seBounds
fields reflect the map
boundaries including margins. If the map is bounded by user-defined
coordinates (see boundByCoords
), the coordinates are adjusted
to reflect the margins. If the map is bounded by
tracks
, routes
, or
way-points
, the fields are set to the
appropriate values, including margins.
BoundingException
- if the configured bounds cannot be appliedprivate void describeColorsAndStyles()
private void describeColorAndStyle(String id, Color color, MarkerStyle style, int radius, boolean labelled, String fontName, float fontSize)
id
- the entity's namecolor
- the color to be appliedstyle
- the style to be appliedradius
- the size of the stylelabelled
- whether the entity is to be labelledfontName
- the font to be usedfontSize
- the size of the font
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |