Class TileService


  • public class TileService
    extends java.lang.Object
    The tile service reads the tile files and generates the map of tile id and shape ids. By default there is only one tile file named tiles.idx. If user generates extra tiles.idx files, the file can be added to the same folder where the tiles.idx is located and renamed as tiles1.idx or tiles2.idx etc. The tile data file is generated using offline script. The tiles info is generated at zoom level 8. We use Google mercader projection to calculate which tile a LatLng object belongs to or which tiles a bounding box contains.
    • Constructor Summary

      Constructors 
      Constructor Description
      TileService​(java.lang.String tileIndexFolder)
      Class Constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<java.lang.String> filterShapesInTiles​(LatLng southWest, LatLng northEast, int shapeType, java.util.List<java.lang.String> shapeIds)
      For a given bounding box and a given shape id array, find all the shapes that are in the shape id array and inside the given bounding box.
      protected static BoundingBox getBoundingBoxFromLatLngBounds​(LatLng southWest, LatLng northEast, int zoomLevel)
      Get the bounding box in pixel for the given south west and north east points in map at a given zoom level.
      protected static java.util.List<java.lang.Integer> getMapTiles​(LatLng southWest, LatLng northEast, int zoomLevel)
      The function returns a list of title ids at a given zoom level.
      java.util.List<java.lang.String> getShapesInTiles​(LatLng southWest, LatLng northEast, int shapeType)
      Retrieves all the shape ids in the bounding box for a given shape type.
      java.util.Map<java.lang.Integer,​java.util.List<java.lang.Integer>> getTilesMapForType​(java.lang.Integer shapeType)
      Get the hash map of the tile ids and shape id list for a given type.
      protected static java.util.Map<java.lang.Integer,​java.util.Map<java.lang.Integer,​java.util.List<java.lang.Integer>>> loadShapes​(java.lang.String path)
      Read the tile data from tile*.idx files and fetch the hash map data for a given shape type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TileService

        public TileService​(java.lang.String tileIndexFolder)
        Class Constructor
        Parameters:
        tileIndexFolder - The folder path where the tile.idx file is located
    • Method Detail

      • loadShapes

        protected static java.util.Map<java.lang.Integer,​java.util.Map<java.lang.Integer,​java.util.List<java.lang.Integer>>> loadShapes​(java.lang.String path)
        Read the tile data from tile*.idx files and fetch the hash map data for a given shape type.
        Parameters:
        path - The folder path to all tilex.idx files
        Returns:
        A hash map object contains the shapeType as the key as the key and tile data for that shape as the value.
      • getTilesMapForType

        public java.util.Map<java.lang.Integer,​java.util.List<java.lang.Integer>> getTilesMapForType​(java.lang.Integer shapeType)
        Get the hash map of the tile ids and shape id list for a given type. The hash map is cached. If the cache is missing, it will go through the file reading process to repopulate the data.
        Parameters:
        shapeType - The shape type.
        Returns:
        The hash map cached by our inner cache object.
      • getBoundingBoxFromLatLngBounds

        protected static BoundingBox getBoundingBoxFromLatLngBounds​(LatLng southWest,
                                                                    LatLng northEast,
                                                                    int zoomLevel)
        Get the bounding box in pixel for the given south west and north east points in map at a given zoom level.
        Parameters:
        southWest - The lat and lng of the south west point.
        northEast - The lat and lng of the north east point.
        zoomLevel - The current zoom level.
        Returns:
        The bounding box in pixel after google projection
      • getMapTiles

        protected static java.util.List<java.lang.Integer> getMapTiles​(LatLng southWest,
                                                                       LatLng northEast,
                                                                       int zoomLevel)
        The function returns a list of title ids at a given zoom level. The tiles are contains within the given bounding box.
        Parameters:
        southWest - The south west of the bounding box.
        northEast - The north east of the bounding box.
        zoomLevel - The zoom level the map is currently in.
        Returns:
        Array of integers that represent the tile ids
      • getShapesInTiles

        public java.util.List<java.lang.String> getShapesInTiles​(LatLng southWest,
                                                                 LatLng northEast,
                                                                 int shapeType)
        Retrieves all the shape ids in the bounding box for a given shape type.
        Parameters:
        southWest - Bounding box south west point.
        northEast - Bounding box north east point.
        shapeType - The shape type.
        Returns:
        An array of shape id strings
      • filterShapesInTiles

        public java.util.List<java.lang.String> filterShapesInTiles​(LatLng southWest,
                                                                    LatLng northEast,
                                                                    int shapeType,
                                                                    java.util.List<java.lang.String> shapeIds)
        For a given bounding box and a given shape id array, find all the shapes that are in the shape id array and inside the given bounding box.
        Parameters:
        southWest - The south west of the bounding box.
        northEast - The north east of the bounding box.
        shapeType - The shape type.
        shapeIds - The candidate shape ids.
        Returns:
        A filtered array of shape ids. The shapes are all inside the bounding box.