Class AbstractTileSourceLayer<T extends org.openstreetmap.gui.jmapviewer.tilesources.AbstractTMSTileSource>

    • Constructor Detail

      • AbstractTileSourceLayer

        protected AbstractTileSourceLayer​(ImageryInfo info)
        Creates Tile Source based Imagery Layer based on Imagery Info
        Parameters:
        info - imagery info
    • Method Detail

      • getNativeProjections

        public abstract java.util.Collection<java.lang.String> getNativeProjections()
        Get projections this imagery layer supports natively.

        For example projection of tiles that are downloaded from a server. Layer may support even more projections (by reprojecting the tiles), but with a certain loss in image quality and performance.

        Returns:
        projections this imagery layer supports natively; null if layer is projection agnostic.
      • getTileSource

        protected abstract T getTileSource()
        Creates and returns a new TileSource instance depending on ImageryLayer.info specified in the constructor.
        Returns:
        TileSource for specified ImageryInfo
        Throws:
        java.lang.IllegalArgumentException - when Imagery is not supported by layer
      • getHeaders

        protected java.util.Map<java.lang.String,​java.lang.String> getHeaders​(T tileSource)
      • tileLoadingFinished

        public void tileLoadingFinished​(org.openstreetmap.gui.jmapviewer.Tile tile,
                                        boolean success)
        Specified by:
        tileLoadingFinished in interface org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener
      • clearTileCache

        public void clearTileCache()
        Clears the tile cache.
      • getInfoComponent

        public java.lang.Object getInfoComponent()
        Description copied from class: Layer
        Gets the layer information to display to the user. This is used if the user requests information about this layer. It should display a description of the layer content.
        Overrides:
        getInfoComponent in class ImageryLayer
        Returns:
        Either a String or a Component describing the layer.
      • getScaleFactor

        public double getScaleFactor​(int zoom)
        Returns average number of screen pixels per tile pixel for current mapview
        Parameters:
        zoom - zoom level
        Returns:
        average number of screen pixels per tile pixel
      • getBestZoom

        public int getBestZoom()
        Returns best zoom level.
        Returns:
        best zoom level
      • sendOsmTileRequest

        private static void sendOsmTileRequest​(org.openstreetmap.gui.jmapviewer.Tile tile,
                                               java.lang.String request)
      • calculateRealTiles

        private static int calculateRealTiles​(int visibleTiles,
                                              int maxXtiles,
                                              int maxYtiles)
        Take into account ZOOM_OFFSET to calculate real number of tiles and multiply by 7, to cover all tiles, that might be accessed when looking for tiles outside current zoom level.

        Currently we use otherZooms = {1, 2, -1, -2, -3, -4, -5}

        The value should be sum(2^x for x in (-5 to 2)) - 1 -1 to exclude current zoom level

        Add +2 to maxYtiles / maxXtiles to add space in cache for extra tiles in current zoom level that are download by overloadTiles(). This is not added in computation of visibleTiles as this unnecessarily grow the cache size

        Check call to tryLoadFromDifferentZoom

        See Also:
        tryLoadFromDifferentZoom(Graphics2D, int, List, int), drawInViewArea(Graphics2D, MapView, ProjectionBounds), AbstractTileSourceLayer.TileSet.overloadTiles()
      • checkMaxZoomLvl

        public static int checkMaxZoomLvl​(int maxZoomLvl,
                                          org.openstreetmap.gui.jmapviewer.interfaces.TileSource ts)
        Checks zoom level against settings
        Parameters:
        maxZoomLvl - zoom level to check
        ts - tile source to crosscheck with
        Returns:
        maximum zoom level, not higher than supported by tilesource nor set by the user
      • checkMinZoomLvl

        public static int checkMinZoomLvl​(int minZoomLvl,
                                          org.openstreetmap.gui.jmapviewer.interfaces.TileSource ts)
        Checks zoom level against settings
        Parameters:
        minZoomLvl - zoom level to check
        ts - tile source to crosscheck with
        Returns:
        minimum zoom level, not higher than supported by tilesource nor set by the user
      • getMaxZoomLvl

        public static int getMaxZoomLvl​(org.openstreetmap.gui.jmapviewer.interfaces.TileSource ts)
        Returns maximum max zoom level, that will be shown on layer.
        Parameters:
        ts - TileSource for which we want to know maximum zoom level
        Returns:
        maximum max zoom level, that will be shown on layer
      • getMinZoomLvl

        public static int getMinZoomLvl​(org.openstreetmap.gui.jmapviewer.interfaces.TileSource ts)
        Returns minimum zoom level, that will be shown on layer.
        Parameters:
        ts - TileSource for which we want to know minimum zoom level
        Returns:
        minimum zoom level, that will be shown on layer
      • setMaxZoomLvl

        public static void setMaxZoomLvl​(int maxZoomLvl)
        Sets maximum zoom level, that layer will attempt show
        Parameters:
        maxZoomLvl - maximum zoom level
      • setMinZoomLvl

        public static void setMinZoomLvl​(int minZoomLvl)
        Sets minimum zoom level, that layer will attempt show
        Parameters:
        minZoomLvl - minimum zoom level
      • zoomChanged

        private void zoomChanged​(boolean invalidate)
      • zoomIncreaseAllowed

        public boolean zoomIncreaseAllowed()
        Determines if it is allowed to zoom in.
        Returns:
        if it is allowed to zoom in
      • increaseZoomLevel

        public boolean increaseZoomLevel()
        Zoom in, go closer to map.
        Returns:
        true, if zoom increasing was successful, false otherwise
      • getZoomLevel

        public int getZoomLevel()
        Get the current zoom level of the layer
        Returns:
        the current zoom level
        Since:
        12603
      • setZoomLevel

        public boolean setZoomLevel​(int zoom)
        Sets the zoom level of the layer
        Parameters:
        zoom - zoom level
        Returns:
        true, when zoom has changed to desired value, false if it was outside supported zoom levels
      • setZoomLevel

        private boolean setZoomLevel​(int zoom,
                                     boolean invalidate)
      • zoomDecreaseAllowed

        public boolean zoomDecreaseAllowed()
        Check if zooming out is allowed
        Returns:
        true, if zooming out is allowed (currentZoomLevel > minZoomLevel)
      • decreaseZoomLevel

        public boolean decreaseZoomLevel()
        Zoom out from map.
        Returns:
        true, if zoom increasing was successful, false otherwise
      • getOrCreateTile

        private org.openstreetmap.gui.jmapviewer.Tile getOrCreateTile​(int x,
                                                                      int y,
                                                                      int zoom)
      • getTile

        private org.openstreetmap.gui.jmapviewer.Tile getTile​(TilePosition tilePosition)
      • getTile

        private org.openstreetmap.gui.jmapviewer.Tile getTile​(int x,
                                                              int y,
                                                              int zoom)
        Returns tile at given position. This can and will return null for tiles that are not already in the cache.
        Parameters:
        x - tile number on the x axis of the tile to be retrieved
        y - tile number on the y axis of the tile to be retrieved
        zoom - zoom level of the tile to be retrieved
        Returns:
        tile at given position
      • loadTile

        private boolean loadTile​(org.openstreetmap.gui.jmapviewer.Tile tile,
                                 boolean force)
      • loadAllTiles

        public void loadAllTiles​(boolean force)
        Load all visible tiles.
        Parameters:
        force - true to force loading if auto-load is disabled
        Since:
        11950
      • loadAllErrorTiles

        public void loadAllErrorTiles​(boolean force)
        Load all visible tiles in error.
        Parameters:
        force - true to force loading if auto-load is disabled
        Since:
        11950
      • clearErrorTiles

        public void clearErrorTiles()
        Remove all cached error tiles
        Since:
        19192
      • imageUpdate

        public boolean imageUpdate​(java.awt.Image img,
                                   int infoflags,
                                   int x,
                                   int y,
                                   int width,
                                   int height)
        Specified by:
        imageUpdate in interface java.awt.image.ImageObserver
      • invalidateLater

        private void invalidateLater()
        Invalidate the layer at a time in the future so that the user still sees the interface responsive.
      • imageLoaded

        private boolean imageLoaded​(java.awt.Image i)
      • getLoadedTileImage

        private java.awt.image.BufferedImage getLoadedTileImage​(org.openstreetmap.gui.jmapviewer.Tile tile)
        Returns the image for the given tile image is loaded. Otherwise returns null.
        Parameters:
        tile - the Tile for which the image should be returned
        Returns:
        the image of the tile or null.
      • drawImageInside

        private void drawImageInside​(java.awt.Graphics2D g,
                                     java.awt.image.BufferedImage toDrawImg,
                                     TileAnchor anchorImage,
                                     TileAnchor anchorScreen,
                                     java.awt.Shape clip)
        Draw a tile image on screen.
        Parameters:
        g - the Graphics2D
        toDrawImg - tile image
        anchorImage - tile anchor in image coordinates
        anchorScreen - tile anchor in screen coordinates
        clip - clipping region in screen coordinates (can be null)
      • getAnchor

        private static TileAnchor getAnchor​(org.openstreetmap.gui.jmapviewer.Tile tile,
                                            java.awt.image.BufferedImage image)
      • myDrawString

        private void myDrawString​(java.awt.Graphics g,
                                  java.lang.String text,
                                  int x,
                                  int y)
      • paintTileText

        private void paintTileText​(org.openstreetmap.gui.jmapviewer.Tile tile,
                                   java.awt.Graphics2D g)
      • paint

        public void paint​(java.awt.Graphics2D g,
                          MapView mv,
                          Bounds bounds)
        Description copied from interface: MapViewPaintable
        Paint the dataset using the engine set.
        Specified by:
        paint in interface MapViewPaintable
        Parameters:
        g - Graphics
        mv - The object that can translate GeoPoints to screen coordinates.
        bounds - Bounding box
      • tryLoadFromDifferentZoom

        private java.util.List<org.openstreetmap.gui.jmapviewer.Tile> tryLoadFromDifferentZoom​(java.awt.Graphics2D g,
                                                                                               int displayZoomLevel,
                                                                                               java.util.List<org.openstreetmap.gui.jmapviewer.Tile> missedTiles,
                                                                                               int zoomOffset)
      • getTileForPixelpos

        private org.openstreetmap.gui.jmapviewer.Tile getTileForPixelpos​(int px,
                                                                         int py)
        Returns tile for a pixel position.

        This isn't very efficient, but it is only used when the user right-clicks on the map.

        Parameters:
        px - pixel X coordinate
        py - pixel Y coordinate
        Returns:
        Tile at pixel position
      • registerMenuAddition

        public static void registerMenuAddition​(javax.swing.Action addition)
        Register an additional layer context menu entry.
        Parameters:
        addition - additional menu action
        Since:
        11197
      • registerMenuAddition

        public static void registerMenuAddition​(javax.swing.Action addition,
                                                java.lang.Class<? extends AbstractTileSourceLayer<?>> clazz)
        Register an additional layer context menu entry for a imagery layer class. The menu entry is valid for the specified class and subclasses thereof only.

        Example:

         TMSLayer.registerMenuAddition(new TMSSpecificAction(), TMSLayer.class);
         
        Parameters:
        addition - additional menu action
        clazz - class the menu action is registered for
        Since:
        11197
      • getMenuAdditions

        private java.util.List<javax.swing.Action> getMenuAdditions()
        Prepare list of additional layer context menu entries. The list is empty if there are no additional menu entries.
        Returns:
        list of additional layer context menu entries
      • getMenuEntries

        public javax.swing.Action[] getMenuEntries()
        Description copied from class: Layer
        Returns list of actions. Action can implement LayerAction interface when it needs to be represented by other menu component than JMenuItem or when it supports multiple layers. Actions that support multiple layers should also have correct equals implementation.

        Use Layer.SeparatorLayerAction.INSTANCE instead of new JSeparator

        Specified by:
        getMenuEntries in class Layer
        Returns:
        menu actions for this layer
      • getLayerListEntries

        public javax.swing.Action[] getLayerListEntries()
        Returns the contextual menu entries in layer list dialog.
        Returns:
        the contextual menu entries in layer list dialog
      • getCommonEntries

        public javax.swing.Action[] getCommonEntries()
        Returns the common menu entries.
        Returns:
        the common menu entries
      • getToolTipText

        public java.lang.String getToolTipText()
        Description copied from class: Layer
        Returns a small tooltip hint about some statistics for this layer.
        Specified by:
        getToolTipText in class Layer
        Returns:
        A small tooltip hint about some statistics for this layer.
      • visitBoundingBox

        public void visitBoundingBox​(BoundingXYVisitor v)
        Description copied from class: Layer
        Visits the content bounds of this layer. The behavior of this method depends on the layer, but each implementation should attempt to cover the relevant content of the layer in this method.
        Specified by:
        visitBoundingBox in class Layer
        Parameters:
        v - The visitor that gets notified about the contents of this layer.
      • getDownloadAreaToCacheTask

        public AbstractTileSourceLayer.PrecacheTask getDownloadAreaToCacheTask​(ProgressMonitor progressMonitor,
                                                                               java.util.List<LatLon> points,
                                                                               double bufferX,
                                                                               double bufferY)
        Calculates tiles, that needs to be downloaded to cache, gets a current tile loader and creates a task to download all of the tiles. Buffer contains at least one tile.

        To prevent accidental clear of the queue, new download executor is created with separate queue

        Parameters:
        progressMonitor - progress monitor for download task
        points - lat/lon coordinates to download
        bufferX - how many units in current Coordinate Reference System to cover in X axis in both sides
        bufferY - how many units in current Coordinate Reference System to cover in Y axis in both sides
        Returns:
        precache task representing download task
      • isSavable

        public boolean isSavable()
        Description copied from class: Layer
        Replies the savable state of this layer (i.e., if it can be saved through a "File → Save" dialog).
        Overrides:
        isSavable in class Layer
        Returns:
        true if this layer can be saved to a file
      • createTile

        public org.openstreetmap.gui.jmapviewer.Tile createTile​(T source,
                                                                int x,
                                                                int y,
                                                                int zoom)
        Create a new tile. Added to allow use of custom Tile objects.
        Parameters:
        source - Tile source
        x - X coordinate
        y - Y coordinate
        zoom - Zoom level
        Returns:
        The new Tile
        Since:
        17862
      • destroy

        public void destroy()
        Description copied from class: Layer
        Called, when the layer is removed from the mapview and is going to be destroyed.

        This is because the Layer constructor cannot add itself safely as a listener to the layerlist dialog, because there may be no such dialog yet (loaded via command line parameter).

        Specified by:
        destroy in interface Destroyable
        Overrides:
        destroy in class Layer