us.zuercher.gpx2map.source
Class AbstractTiledUrlMapSource

java.lang.Object
  extended by us.zuercher.gpx2map.source.AbstractCachedMapSource
      extended by us.zuercher.gpx2map.source.AbstractTiledUrlMapSource
All Implemented Interfaces:
MapSource
Direct Known Subclasses:
DummyMapSource, TerraserverUsaMapSource

public abstract class AbstractTiledUrlMapSource
extends AbstractCachedMapSource
implements MapSource

AbstractTilesUrlMapSource extends AbstractCachedMapSource to provide a MapSource base class that provides map tile downloading and stitching facilities.

For the purposes of stitchTiles(File, ProgressMeter), map tiles are assumed to be gzipped PPM files. Individual tiles file names are retrieve from the cache via the abstract method getTile(int, int). The column and row information passed in that method are derived from the return values of the abstract methods getColumnCount() and getRowCount().

Author:
Stephan Zuercher

Constructor Summary
AbstractTiledUrlMapSource()
           
 
Method Summary
protected  void download(URL url, File target)
          Downloads, converts and compresses an image from the given source URL to the given target file.
protected  void download(URL url, File target, boolean convertAndCompress)
          Downloads, converts and compresses an image from the given source URL to the given target file.
protected abstract  int getColumnCount()
          Returns the number of tile columns for the current map.
protected  String getCompressedCacheFileExtension()
          Returns the extension that should be used for downloaded files.
protected abstract  int getRowCount()
          Returns the number of tile rows for the current map.
protected abstract  File getTile(int column, int row)
          Returns the File object for the tile at the given coordinates.
 void stitchTiles(File outputFile, ProgressMeter meter)
          Stitches together tiles files obtained from the concrete base class.
 
Methods inherited from class us.zuercher.gpx2map.source.AbstractCachedMapSource
getCacheDir, setCacheDir
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface us.zuercher.gpx2map.source.MapSource
downloadTiles, getImageSize, getMapScale, getProperties, mapLocationToPixel, setBoundingBox, setCacheDir, setProperty
 

Constructor Detail

AbstractTiledUrlMapSource

public AbstractTiledUrlMapSource()
Method Detail

stitchTiles

public void stitchTiles(File outputFile,
                        ProgressMeter meter)
                 throws IOException
Stitches together tiles files obtained from the concrete base class. Tiles files are obtained from getTile(int, int), getColumnCount(), and getRowCount().

Specified by:
stitchTiles in interface MapSource
Parameters:
outputFile - the output file, a gzipped PPM file
meter - a progress meter
Throws:
IOException - if there's an error reading the input files, or writing to the output file.
See Also:
MapSource.stitchTiles(File, ProgressMeter)

getColumnCount

protected abstract int getColumnCount()
Returns the number of tile columns for the current map.

Returns:
number of tile columns.

getRowCount

protected abstract int getRowCount()
Returns the number of tile rows for the current map.

Returns:
number of tile rows.

getTile

protected abstract File getTile(int column,
                                int row)
Returns the File object for the tile at the given coordinates.

Parameters:
column - 0-based column index
row - 0-based row index
Returns:
File for the given tile.

download

protected void download(URL url,
                        File target,
                        boolean convertAndCompress)
                 throws IOException
Downloads, converts and compresses an image from the given source URL to the given target file.

Parameters:
url - image source URL
target - image target file.
convertAndCompress - if true, attempts to convert the file to PPM format and apply gzip compression.
Throws:
IOException - if there's an error downloading the file
See Also:
MapSource.downloadTiles(ProgressMeter), JavaDownloader, JavaConverter

download

protected void download(URL url,
                        File target)
                 throws IOException
Downloads, converts and compresses an image from the given source URL to the given target file. Equivalent to calling download(url, target, true).

Parameters:
url - image source URL
target - image target file.
Throws:
IOException - if there's an error downloading the file
See Also:
MapSource.downloadTiles(ProgressMeter), JavaDownloader, JavaConverter

getCompressedCacheFileExtension

protected String getCompressedCacheFileExtension()
Returns the extension that should be used for downloaded files.

Returns:
the extension that should be used for downloaded files.
See Also:
JavaConverter