Class TileDownloadLayer

    • Constructor Detail

      • TileDownloadLayer

        public TileDownloadLayer​(TileCache tileCache,
                                 IMapViewPosition mapViewPosition,
                                 TileSource tileSource,
                                 org.mapsforge.core.graphics.GraphicFactory graphicFactory)
    • Method Detail

      • draw

        public void draw​(org.mapsforge.core.model.BoundingBox boundingBox,
                         byte zoomLevel,
                         org.mapsforge.core.graphics.Canvas canvas,
                         org.mapsforge.core.model.Point topLeftPoint)
        Description copied from class: Layer
        Draws this Layer on the given canvas.
        Overrides:
        draw in class TileLayer<DownloadJob>
        Parameters:
        boundingBox - the geographical area which should be drawn.
        zoomLevel - the zoom level at which this Layer should draw itself.
        canvas - the canvas on which this Layer should draw itself.
        topLeftPoint - the top-left pixel position of the canvas relative to the top-left map position.
      • getCacheTimeToLive

        public long getCacheTimeToLive()
        Returns the time-to-live (TTL) for tiles in the cache, or 0 if not set.

        Refer to isTileStale(Tile, TileBitmap) for information on how the TTL is enforced.

      • onDestroy

        public void onDestroy()
        Overrides:
        onDestroy in class Layer
      • onPause

        public void onPause()
      • onResume

        public void onResume()
      • setCacheTimeToLive

        public void setCacheTimeToLive​(long ttl)
        Sets the time-to-live (TTL) for tiles in the cache.

        The initial TTL is obtained by calling the TileSource's TileSource.getDefaultTimeToLive() ()} method. Refer to isTileStale(Tile, TileBitmap) for information on how the TTL is enforced.

        Parameters:
        ttl - The TTL. If set to 0, no TTL will be enforced.
      • setDisplayModel

        public void setDisplayModel​(DisplayModel displayModel)
        Description copied from class: Layer
        The DisplayModel comes from a MapView, so is generally not known when the layer itself is created. Maybe a better way would be to have a MapView as a parameter when creating a layer.
        Overrides:
        setDisplayModel in class TileLayer<DownloadJob>
        Parameters:
        displayModel - the displayModel to use.
      • start

        public void start()
      • isTileStale

        protected boolean isTileStale​(org.mapsforge.core.model.Tile tile,
                                      org.mapsforge.core.graphics.TileBitmap bitmap)
        Whether the tile is stale and should be refreshed.

        This method is called from draw(BoundingBox, byte, Canvas, Point) to determine whether the tile needs to be refreshed.

        A tile is considered stale if one or more of the following two conditions apply:

        • The bitmap's TileBitmap.isExpired() method returns True.
        • The layer has a time-to-live (TTL) set (getCacheTimeToLive() returns a nonzero value) and the sum of the bitmap's TileBitmap.getTimestamp() and TTL is less than current time (as returned by System.currentTimeMillis()).

        When a tile has become stale, the layer will first display the tile referenced by bitmap and attempt to obtain a fresh copy in the background. When a fresh copy becomes available, the layer will replace it and update the cache. If a fresh copy cannot be obtained (e.g. because the tile is obtained from an online source which cannot be reached), the stale tile will continue to be used until another #draw(BoundingBox, byte, Canvas, Point) operation requests it again.

        Specified by:
        isTileStale in class TileLayer<DownloadJob>
        Parameters:
        tile - A tile. This parameter is not used for a TileDownloadLayer and can be null.
        bitmap - The bitmap for tile currently held in the layer's cache.
      • onAdd

        protected void onAdd()
        Description copied from class: Layer
        Called each time this Layer is added to a Layers list.
        Overrides:
        onAdd in class Layer
      • onRemove

        protected void onRemove()
        Description copied from class: Layer
        Called each time this Layer is removed from a Layers list.
        Overrides:
        onRemove in class Layer
      • onChange

        public void onChange()
        Description copied from interface: Observer
        Called whenever the observed object has been changed.

        Time-consuming operations should be performed in a separate thread.

        Specified by:
        onChange in interface Observer