Class MapFile

java.lang.Object
org.mapsforge.map.datastore.MapDataStore
org.mapsforge.map.reader.MapFile

public class MapFile extends org.mapsforge.map.datastore.MapDataStore
A class for reading binary map files.

The readMapData method is now thread safe, but care should be taken that not too much data is read at the same time (keep simultaneous requests to minimum)

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final MapFile
     
    static int
     
    static boolean
    Way filtering reduces the number of ways returned to only those that are relevant for the tile requested, leading to performance gains, but can cause line clipping artifacts (particularly at higher zoom levels).

    Fields inherited from class org.mapsforge.map.datastore.MapDataStore

    preferredLanguage
  • Constructor Summary

    Constructors
    Constructor
    Description
    MapFile(File mapFile)
    Opens the given map file, reads its header data and validates them.
    MapFile(FileInputStream mapFileInputStream)
    Opens the given map file input stream, reads its header data and validates them.
    MapFile(FileInputStream mapFileInputStream, long lastModified, String language)
    Opens the given map file input stream, reads its header data and validates them.
    MapFile(FileInputStream mapFileInputStream, String language)
    Opens the given map file input stream, reads its header data and validates them.
    MapFile(File mapFile, String language)
    Opens the given map file, reads its header data and validates them.
    MapFile(String mapPath)
    Opens the given map file, reads its header data and validates them.
    MapFile(String mapPath, String language)
    Opens the given map file, reads its header data and validates them.
    MapFile(FileChannel mapFileChannel)
    Opens the given map file channel, reads its header data and validates them.
    MapFile(FileChannel mapFileChannel, long lastModified, String language)
    Opens the given map file channel, reads its header data and validates them.
    MapFile(FileChannel mapFileChannel, String language)
    Opens the given map file channel, reads its header data and validates them.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.mapsforge.core.model.BoundingBox
     
    void
     
    long
    getDataTimestamp(org.mapsforge.core.model.Tile tile)
    Returns the creation timestamp of the map file.
     
     
     
    org.mapsforge.map.datastore.MapReadResult
    readLabels(org.mapsforge.core.model.Tile tile)
    Reads only labels for tile.
    org.mapsforge.map.datastore.MapReadResult
    readLabels(org.mapsforge.core.model.Tile upperLeft, org.mapsforge.core.model.Tile lowerRight)
    Reads data for an area defined by the tile in the upper left and the tile in the lower right corner.
    org.mapsforge.map.datastore.MapReadResult
    readMapData(org.mapsforge.core.model.Tile tile)
    Reads all map data for the area covered by the given tile at the tile zoom level.
    org.mapsforge.map.datastore.MapReadResult
    readMapData(org.mapsforge.core.model.Tile upperLeft, org.mapsforge.core.model.Tile lowerRight)
    Reads data for an area defined by the tile in the upper left and the tile in the lower right corner.
    org.mapsforge.map.datastore.MapReadResult
    readPoiData(org.mapsforge.core.model.Tile tile)
    Reads only POI data for tile.
    org.mapsforge.map.datastore.MapReadResult
    readPoiData(org.mapsforge.core.model.Tile upperLeft, org.mapsforge.core.model.Tile lowerRight)
    Reads POI data for an area defined by the tile in the upper left and the tile in the lower right corner.
    void
    restrictToZoomRange(byte minZoom, byte maxZoom)
    Restricts returns of data to zoom level range specified.
    org.mapsforge.core.model.LatLong
     
     
    boolean
    supportsTile(org.mapsforge.core.model.Tile tile)
     

    Methods inherited from class org.mapsforge.map.datastore.MapDataStore

    extract, extractLocalized, wayAsLabelTagFilter

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TEST_MAP_FILE

      public static final MapFile TEST_MAP_FILE
    • wayFilterEnabled

      public static boolean wayFilterEnabled
      Way filtering reduces the number of ways returned to only those that are relevant for the tile requested, leading to performance gains, but can cause line clipping artifacts (particularly at higher zoom levels). The risk of clipping can be reduced by either turning way filtering off or by increasing the wayFilterDistance which governs how large an area surrounding the requested tile will be returned. For most use cases the standard settings should be sufficient.
    • wayFilterDistance

      public static int wayFilterDistance
  • Constructor Details

    • MapFile

      public MapFile(File mapFile)
      Opens the given map file, reads its header data and validates them. Uses default language.
      Parameters:
      mapFile - the map file.
      Throws:
      MapFileException - if the given map file is null or invalid.
    • MapFile

      public MapFile(File mapFile, String language)
      Opens the given map file, reads its header data and validates them.
      Parameters:
      mapFile - the map file.
      language - the language to use (may be null).
      Throws:
      MapFileException - if the given map file is null or invalid.
    • MapFile

      public MapFile(FileInputStream mapFileInputStream)
      Opens the given map file input stream, reads its header data and validates them.
      Parameters:
      mapFileInputStream - the map file input stream.
      Throws:
      MapFileException - if the given map file is null or invalid.
    • MapFile

      public MapFile(FileInputStream mapFileInputStream, String language)
      Opens the given map file input stream, reads its header data and validates them.
      Parameters:
      mapFileInputStream - the map file input stream.
      language - the language to use (may be null).
      Throws:
      MapFileException - if the given map file is null or invalid.
    • MapFile

      public MapFile(FileInputStream mapFileInputStream, long lastModified, String language)
      Opens the given map file input stream, reads its header data and validates them.
      Parameters:
      mapFileInputStream - the map file input stream.
      language - the language to use (may be null).
      Throws:
      MapFileException - if the given map file is null or invalid.
    • MapFile

      public MapFile(FileChannel mapFileChannel)
      Opens the given map file channel, reads its header data and validates them.
      Parameters:
      mapFileChannel - the map file channel.
      Throws:
      MapFileException - if the given map file channel is null or invalid.
    • MapFile

      public MapFile(FileChannel mapFileChannel, String language)
      Opens the given map file channel, reads its header data and validates them.
      Parameters:
      mapFileChannel - the map file channel.
      language - the language to use (may be null).
      Throws:
      MapFileException - if the given map file channel is null or invalid.
    • MapFile

      public MapFile(FileChannel mapFileChannel, long lastModified, String language)
      Opens the given map file channel, reads its header data and validates them.
      Parameters:
      mapFileChannel - the map file channel.
      language - the language to use (may be null).
      Throws:
      MapFileException - if the given map file channel is null or invalid.
    • MapFile

      public MapFile(String mapPath)
      Opens the given map file, reads its header data and validates them. Uses default language.
      Parameters:
      mapPath - the path of the map file.
      Throws:
      MapFileException - if the given map file is null or invalid.
    • MapFile

      public MapFile(String mapPath, String language)
      Opens the given map file, reads its header data and validates them.
      Parameters:
      mapPath - the path of the map file.
      language - the language to use (may be null).
      Throws:
      MapFileException - if the given map file is null or invalid or IOException if the file cannot be opened.
  • Method Details

    • boundingBox

      public org.mapsforge.core.model.BoundingBox boundingBox()
      Specified by:
      boundingBox in class org.mapsforge.map.datastore.MapDataStore
    • close

      public void close()
      Specified by:
      close in class org.mapsforge.map.datastore.MapDataStore
    • getDataTimestamp

      public long getDataTimestamp(org.mapsforge.core.model.Tile tile)
      Returns the creation timestamp of the map file.
      Specified by:
      getDataTimestamp in class org.mapsforge.map.datastore.MapDataStore
      Parameters:
      tile - not used, as all tiles will shared the same creation date.
      Returns:
      the creation timestamp inside the map file.
    • getMapFileHeader

      public MapFileHeader getMapFileHeader()
      Returns:
      the header data for the current map file.
    • getMapFileInfo

      public MapFileInfo getMapFileInfo()
      Returns:
      the metadata for the current map file.
    • getMapLanguages

      public String[] getMapLanguages()
      Returns:
      the map file supported languages (may be null).
    • readLabels

      public org.mapsforge.map.datastore.MapReadResult readLabels(org.mapsforge.core.model.Tile tile)
      Reads only labels for tile.
      Overrides:
      readLabels in class org.mapsforge.map.datastore.MapDataStore
      Parameters:
      tile - tile for which data is requested.
      Returns:
      label data for the tile.
    • readLabels

      public org.mapsforge.map.datastore.MapReadResult readLabels(org.mapsforge.core.model.Tile upperLeft, org.mapsforge.core.model.Tile lowerRight)
      Reads data for an area defined by the tile in the upper left and the tile in the lower right corner. Precondition: upperLeft.tileX <= lowerRight.tileX && upperLeft.tileY <= lowerRight.tileY
      Overrides:
      readLabels in class org.mapsforge.map.datastore.MapDataStore
      Parameters:
      upperLeft - tile that defines the upper left corner of the requested area.
      lowerRight - tile that defines the lower right corner of the requested area.
      Returns:
      map data for the tile.
    • readMapData

      public org.mapsforge.map.datastore.MapReadResult readMapData(org.mapsforge.core.model.Tile tile)
      Reads all map data for the area covered by the given tile at the tile zoom level.
      Specified by:
      readMapData in class org.mapsforge.map.datastore.MapDataStore
      Parameters:
      tile - defines area and zoom level of read map data.
      Returns:
      the read map data.
    • readMapData

      public org.mapsforge.map.datastore.MapReadResult readMapData(org.mapsforge.core.model.Tile upperLeft, org.mapsforge.core.model.Tile lowerRight)
      Reads data for an area defined by the tile in the upper left and the tile in the lower right corner. Precondition: upperLeft.tileX <= lowerRight.tileX && upperLeft.tileY <= lowerRight.tileY
      Overrides:
      readMapData in class org.mapsforge.map.datastore.MapDataStore
      Parameters:
      upperLeft - tile that defines the upper left corner of the requested area.
      lowerRight - tile that defines the lower right corner of the requested area.
      Returns:
      map data for the tile.
    • readPoiData

      public org.mapsforge.map.datastore.MapReadResult readPoiData(org.mapsforge.core.model.Tile tile)
      Reads only POI data for tile.
      Specified by:
      readPoiData in class org.mapsforge.map.datastore.MapDataStore
      Parameters:
      tile - tile for which data is requested.
      Returns:
      POI data for the tile.
    • readPoiData

      public org.mapsforge.map.datastore.MapReadResult readPoiData(org.mapsforge.core.model.Tile upperLeft, org.mapsforge.core.model.Tile lowerRight)
      Reads POI data for an area defined by the tile in the upper left and the tile in the lower right corner. This implementation takes the data storage of a MapFile into account for greater efficiency.
      Overrides:
      readPoiData in class org.mapsforge.map.datastore.MapDataStore
      Parameters:
      upperLeft - tile that defines the upper left corner of the requested area.
      lowerRight - tile that defines the lower right corner of the requested area.
      Returns:
      map data for the tile.
    • restrictToZoomRange

      public void restrictToZoomRange(byte minZoom, byte maxZoom)
      Restricts returns of data to zoom level range specified. This can be used to restrict the use of this map data base when used in MultiMapDatabase settings.
      Parameters:
      minZoom - minimum zoom level supported
      maxZoom - maximum zoom level supported
    • startPosition

      public org.mapsforge.core.model.LatLong startPosition()
      Specified by:
      startPosition in class org.mapsforge.map.datastore.MapDataStore
    • startZoomLevel

      public Byte startZoomLevel()
      Specified by:
      startZoomLevel in class org.mapsforge.map.datastore.MapDataStore
    • supportsTile

      public boolean supportsTile(org.mapsforge.core.model.Tile tile)
      Specified by:
      supportsTile in class org.mapsforge.map.datastore.MapDataStore