org.openstreetmap.josm.gui.layer
Class TMSLayer

java.lang.Object
  extended by org.openstreetmap.josm.gui.layer.Layer
      extended by org.openstreetmap.josm.gui.layer.ImageryLayer
          extended by org.openstreetmap.josm.gui.layer.TMSLayer
All Implemented Interfaces:
java.awt.image.ImageObserver, TileLoaderListener, ProjectionChangeListener, MapViewPaintable, Destroyable

public class TMSLayer
extends ImageryLayer
implements java.awt.image.ImageObserver, TileLoaderListener

Class that displays a slippy map layer.


Nested Class Summary
private static class TMSLayer.CachedAttributionBingAerialTileSource
           
private  class TMSLayer.DeepTileSet
           
private  class TMSLayer.TileSet
           
private static class TMSLayer.TileSetInfo
           
private  class TMSLayer.TmsTileClearController
           
 
Nested classes/interfaces inherited from class org.openstreetmap.josm.gui.layer.ImageryLayer
ImageryLayer.ApplyOffsetAction, ImageryLayer.OffsetAction, ImageryLayer.OffsetServerThread
 
Nested classes/interfaces inherited from class org.openstreetmap.josm.gui.layer.Layer
Layer.LayerAction, Layer.LayerGpxExportAction, Layer.LayerSaveAction, Layer.LayerSaveAsAction, Layer.MultiLayerAction, Layer.SeparatorLayerAction
 
Field Summary
private  AttributionSupport attribution
           
protected  boolean autoLoad
           
(package private)  javax.swing.JCheckBoxMenuItem autoLoadPopup
           
protected  boolean autoZoom
           
(package private)  javax.swing.JCheckBoxMenuItem autoZoomPopup
           
private  Tile clickedTile
           
 int currentZoomLevel
          Zoomlevel at which tiles is currently downloaded.
static int DEFAULT_MAX_ZOOM
           
static int DEFAULT_MIN_ZOOM
           
private static java.awt.Font InfoFont
           
(package private)  java.awt.Image lastScaledImage
           
static int MAX_ZOOM
           
static int MIN_ZOOM
           
private  boolean needRedraw
           
private  TMSLayer.TileSet nullTileSet
           
static java.lang.String PREFERENCE_PREFIX
           
static BooleanProperty PROP_ADD_TO_SLIPPYMAP_CHOOSER
           
static BooleanProperty PROP_DEFAULT_AUTOLOAD
           
static BooleanProperty PROP_DEFAULT_AUTOZOOM
           
static BooleanProperty PROP_DEFAULT_SHOWERRORS
           
static IntegerProperty PROP_MAX_ZOOM_LVL
           
static IntegerProperty PROP_MIN_ZOOM_LVL
           
static StringProperty PROP_TILECACHE_DIR
           
static IntegerProperty PROP_TMS_JOBS
           
protected  boolean showErrors
           
(package private)  javax.swing.JCheckBoxMenuItem showErrorsPopup
           
(package private)  Tile showMetadataTile
           
protected  MemoryTileCache tileCache
           
protected  OsmTileLoader tileLoader
           
private  javax.swing.JPopupMenu tileOptionMenu
           
(package private)  java.util.HashSet<Tile> tileRequestsOutstanding
           
protected  TileSource tileSource
           
 
Fields inherited from class org.openstreetmap.josm.gui.layer.ImageryLayer
dx, dy, icon, info, offsetServerSupported, offsetServerThread, offsetServerUsed, PROP_FADE_AMOUNT, PROP_FADE_COLOR, PROP_SHARPEN_LEVEL, sharpenLevel
 
Fields inherited from class org.openstreetmap.josm.gui.layer.Layer
ICON_SIZE, NAME_PROP, OPACITY_PROP, propertyChangeSupport, VISIBLE_PROP
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
TMSLayer(ImageryInfo info)
           
 
Method Summary
(package private) static int checkMaxZoomLvl(int maxZoomLvl, TileSource ts)
           
(package private) static int checkMinZoomLvl(int minZoomLvl, TileSource ts)
           
static void checkUrl(java.lang.String url)
           
(package private)  void clearTileCache(ProgressMonitor monitor)
          Clears the tile cache.
 boolean decreaseZoomLevel()
          Zoom out from map.
(package private)  void drawImageInside(java.awt.Graphics g, java.awt.Image sourceImg, java.awt.Rectangle source, java.awt.Rectangle border)
           
private  int getBestZoom()
           
(package private)  java.awt.Image getLoadedTileImage(Tile tile)
          Returns the image for the given tile if both tile and image are loaded.
(package private)  int getMaxZoomLvl()
           
static int getMaxZoomLvl(TileSource ts)
           
 javax.swing.Action[] getMenuEntries()
          Returns list of actions.
(package private)  int getMinZoomLvl()
           
static int getMinZoomLvl(TileSource ts)
           
(package private)  Tile getOrCreateTile(int x, int y, int zoom)
           
private  double getScaleFactor(int zoom)
          Returns average number of screen pixels per tile pixel for current mapview
private  Coordinate getShiftedCoord(EastNorth en)
           
private  LatLon getShiftedLatLon(EastNorth en)
           
(package private)  Tile getTile(int x, int y, int zoom)
           
 TileCache getTileCache()
          Return the TileCache class containing Tile data for requested and loaded tiles
(package private)  Tile getTileForPixelpos(int px, int py)
          This isn't very efficient, but it is only used when the user right-clicks on the map.
private static TMSLayer.TileSetInfo getTileSetInfo(TMSLayer.TileSet ts)
           
static TileSource getTileSource(ImageryInfo info)
          Creates and returns a new TileSource instance depending on the ImageryInfo.ImageryType of the passed ImageryInfo object.
 java.lang.String getToolTipText()
           
 void hookUpMapView()
          Adds a context menu to the mapView.
(package private)  boolean imageLoaded(java.awt.Image i)
           
 boolean imageUpdate(java.awt.Image img, int infoflags, int x, int y, int width, int height)
           
 boolean increaseZoomLevel()
           
private  void initTileSource(TileSource tileSource)
           
 boolean isChanged()
          Check changed status of layer
 boolean isProjectionSupported(Projection proj)
          allows to check whether a projection is supported or not
(package private)  void loadAllErrorTiles(boolean force)
           
(package private)  void loadAllTiles(boolean force)
           
(package private)  boolean loadTile(Tile tile, boolean force)
           
(package private)  void myDrawString(java.awt.Graphics g, java.lang.String text, int x, int y)
           
 java.lang.String nameSupportedProjections()
          Specify user information about projections
 void paint(java.awt.Graphics2D g, MapView mv, Bounds bounds)
          Paint the dataset using the engine set.
(package private)  java.util.List<Tile> paintTileImages(java.awt.Graphics g, TMSLayer.TileSet ts, int zoom, Tile border)
           
(package private)  void paintTileText(TMSLayer.TileSet ts, Tile tile, java.awt.Graphics g, MapView mv, int zoom, Tile t)
           
private  java.awt.Point pixelPos(LatLon ll)
           
private  java.awt.Point pixelPos(Tile t)
           
(package private)  void redraw()
          Initiates a repaint of Main.map
static void setMaxWorkers()
          Function to set the maximum number of workers for tile loading to the value defined in preferences.
static void setMaxZoomLvl(int maxZoomLvl)
           
static void setMinZoomLvl(int minZoomLvl)
           
 void setOffset(double dx, double dy)
           
 boolean setZoomLevel(int zoom)
           
(package private)  Tile tempCornerTile(Tile t)
           
(package private)  LatLon tileLatLon(Tile t)
           
 void tileLoadingFinished(Tile tile, boolean success)
          Will be called if a new Tile has been loaded successfully.
(package private)  java.awt.Rectangle tileToRect(Tile t1)
           
 void visitBoundingBox(BoundingXYVisitor v)
           
(package private)  void zoomChanged()
           
 boolean zoomDecreaseAllowed()
          Check if zooming out is allowed
 boolean zoomIncreaseAllowed()
          Zoom in, go closer to map.
 
Methods inherited from class org.openstreetmap.josm.gui.layer.ImageryLayer
create, createoffsetServerThread, destroy, displace, drawErrorTile, enableOffsetServer, getDx, getDy, getFadeColor, getFadeColorWithAlpha, getIcon, getInfo, getInfoComponent, getOffsetMenuItem, getOffsetMenuItem, getPPD, isMergable, mergeFrom, sharpenImage
 
Methods inherited from class org.openstreetmap.josm.gui.layer.Layer
addPropertyChangeListener, checkSaveConditions, createAndOpenSaveFileChooser, fireOpacityChanged, fireVisibleChanged, getAssociatedFile, getColor, getName, getOpacity, isBackgroundLayer, isSavable, isVisible, onPostLoadFromFile, projectionChanged, removePropertyChangeListener, setAssociatedFile, setBackgroundLayer, setName, setOpacity, setVisible, toggleVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PREFERENCE_PREFIX

public static final java.lang.String PREFERENCE_PREFIX
See Also:
Constant Field Values

MAX_ZOOM

public static final int MAX_ZOOM
See Also:
Constant Field Values

MIN_ZOOM

public static final int MIN_ZOOM
See Also:
Constant Field Values

DEFAULT_MAX_ZOOM

public static final int DEFAULT_MAX_ZOOM
See Also:
Constant Field Values

DEFAULT_MIN_ZOOM

public static final int DEFAULT_MIN_ZOOM
See Also:
Constant Field Values

PROP_DEFAULT_AUTOZOOM

public static final BooleanProperty PROP_DEFAULT_AUTOZOOM

PROP_DEFAULT_AUTOLOAD

public static final BooleanProperty PROP_DEFAULT_AUTOLOAD

PROP_DEFAULT_SHOWERRORS

public static final BooleanProperty PROP_DEFAULT_SHOWERRORS

PROP_MIN_ZOOM_LVL

public static final IntegerProperty PROP_MIN_ZOOM_LVL

PROP_MAX_ZOOM_LVL

public static final IntegerProperty PROP_MAX_ZOOM_LVL

PROP_ADD_TO_SLIPPYMAP_CHOOSER

public static final BooleanProperty PROP_ADD_TO_SLIPPYMAP_CHOOSER

PROP_TMS_JOBS

public static final IntegerProperty PROP_TMS_JOBS

PROP_TILECACHE_DIR

public static final StringProperty PROP_TILECACHE_DIR

tileCache

protected MemoryTileCache tileCache

tileSource

protected TileSource tileSource

tileLoader

protected OsmTileLoader tileLoader

tileRequestsOutstanding

java.util.HashSet<Tile> tileRequestsOutstanding

currentZoomLevel

public int currentZoomLevel
Zoomlevel at which tiles is currently downloaded. Initial zoom lvl is set to bestZoom


clickedTile

private Tile clickedTile

needRedraw

private boolean needRedraw

tileOptionMenu

private javax.swing.JPopupMenu tileOptionMenu

autoZoomPopup

javax.swing.JCheckBoxMenuItem autoZoomPopup

autoLoadPopup

javax.swing.JCheckBoxMenuItem autoLoadPopup

showErrorsPopup

javax.swing.JCheckBoxMenuItem showErrorsPopup

showMetadataTile

Tile showMetadataTile

attribution

private AttributionSupport attribution

InfoFont

private static final java.awt.Font InfoFont

autoZoom

protected boolean autoZoom

autoLoad

protected boolean autoLoad

showErrors

protected boolean showErrors

lastScaledImage

java.awt.Image lastScaledImage

nullTileSet

private final TMSLayer.TileSet nullTileSet
Constructor Detail

TMSLayer

public TMSLayer(ImageryInfo info)
Method Detail

tileLoadingFinished

public void tileLoadingFinished(Tile tile,
                                boolean success)
Description copied from interface: TileLoaderListener
Will be called if a new Tile has been loaded successfully. Loaded can mean downloaded or loaded from file cache.

Specified by:
tileLoadingFinished in interface TileLoaderListener

getTileCache

public TileCache getTileCache()
Description copied from interface: TileLoaderListener
Return the TileCache class containing Tile data for requested and loaded tiles

Specified by:
getTileCache in interface TileLoaderListener
Returns:
tile information caching class

clearTileCache

void clearTileCache(ProgressMonitor monitor)
Clears the tile cache. If the current tileLoader is an instance of OsmTileLoader, a new TmsTileClearController is created and passed to the according clearCache method.

Parameters:
monitor -
See Also:
MemoryTileCache.clear(), OsmFileCacheTileLoader.clearCache(org.openstreetmap.gui.jmapviewer.interfaces.TileSource, org.openstreetmap.gui.jmapviewer.OsmFileCacheTileLoader.TileClearController)

redraw

void redraw()
Initiates a repaint of Main.map

See Also:
Main.map, Component.repaint()

checkMaxZoomLvl

static int checkMaxZoomLvl(int maxZoomLvl,
                           TileSource ts)

getMaxZoomLvl

public static int getMaxZoomLvl(TileSource ts)

setMaxZoomLvl

public static void setMaxZoomLvl(int maxZoomLvl)

checkMinZoomLvl

static int checkMinZoomLvl(int minZoomLvl,
                           TileSource ts)

getMinZoomLvl

public static int getMinZoomLvl(TileSource ts)

setMinZoomLvl

public static void setMinZoomLvl(int minZoomLvl)

getTileSource

public static TileSource getTileSource(ImageryInfo info)
                                throws java.lang.IllegalArgumentException
Creates and returns a new TileSource instance depending on the ImageryInfo.ImageryType of the passed ImageryInfo object. If no appropriate TileSource is found, null is returned. Currently supported ImageryType are ImageryInfo.ImageryType.TMS, ImageryInfo.ImageryType.BING, ImageryInfo.ImageryType.SCANEX.

Parameters:
info -
Returns:
a new TileSource instance or null if no TileSource for the ImageryInfo/ImageryType could be found.
Throws:
java.lang.IllegalArgumentException

checkUrl

public static void checkUrl(java.lang.String url)
                     throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

initTileSource

private void initTileSource(TileSource tileSource)

setOffset

public void setOffset(double dx,
                      double dy)
Overrides:
setOffset in class ImageryLayer

getScaleFactor

private double getScaleFactor(int zoom)
Returns average number of screen pixels per tile pixel for current mapview


getBestZoom

private int getBestZoom()

setMaxWorkers

public static void setMaxWorkers()
Function to set the maximum number of workers for tile loading to the value defined in preferences.


hookUpMapView

public void hookUpMapView()
Adds a context menu to the mapView.

Overrides:
hookUpMapView in class Layer

zoomChanged

void zoomChanged()

getMaxZoomLvl

int getMaxZoomLvl()

getMinZoomLvl

int getMinZoomLvl()

zoomIncreaseAllowed

public boolean zoomIncreaseAllowed()
Zoom in, go closer to map.

Returns:
true, if zoom increasing was successfull, false othervise

increaseZoomLevel

public boolean increaseZoomLevel()

setZoomLevel

public boolean setZoomLevel(int zoom)

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 successfull, false othervise

tempCornerTile

Tile tempCornerTile(Tile t)

getOrCreateTile

Tile getOrCreateTile(int x,
                     int y,
                     int zoom)

getTile

Tile getTile(int x,
             int y,
             int zoom)

loadTile

boolean loadTile(Tile tile,
                 boolean force)

loadAllTiles

void loadAllTiles(boolean force)

loadAllErrorTiles

void loadAllErrorTiles(boolean force)

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

imageLoaded

boolean imageLoaded(java.awt.Image i)

getLoadedTileImage

java.awt.Image getLoadedTileImage(Tile tile)
Returns the image for the given tile if both tile and image are loaded. Otherwise returns null.

Parameters:
tile - the Tile for which the image should be returned
Returns:
the image of the tile or null.

tileLatLon

LatLon tileLatLon(Tile t)

tileToRect

java.awt.Rectangle tileToRect(Tile t1)

drawImageInside

void drawImageInside(java.awt.Graphics g,
                     java.awt.Image sourceImg,
                     java.awt.Rectangle source,
                     java.awt.Rectangle border)

paintTileImages

java.util.List<Tile> paintTileImages(java.awt.Graphics g,
                                     TMSLayer.TileSet ts,
                                     int zoom,
                                     Tile border)

myDrawString

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

paintTileText

void paintTileText(TMSLayer.TileSet ts,
                   Tile tile,
                   java.awt.Graphics g,
                   MapView mv,
                   int zoom,
                   Tile t)

pixelPos

private java.awt.Point pixelPos(LatLon ll)

pixelPos

private java.awt.Point pixelPos(Tile t)

getShiftedLatLon

private LatLon getShiftedLatLon(EastNorth en)

getShiftedCoord

private Coordinate getShiftedCoord(EastNorth en)

getTileSetInfo

private static TMSLayer.TileSetInfo getTileSetInfo(TMSLayer.TileSet ts)

paint

public void paint(java.awt.Graphics2D g,
                  MapView mv,
                  Bounds bounds)
Description copied from class: Layer
Paint the dataset using the engine set.

Specified by:
paint in interface MapViewPaintable
Specified by:
paint in class Layer
mv - The object that can translate GeoPoints to screen coordinates.

getTileForPixelpos

Tile getTileForPixelpos(int px,
                        int py)
This isn't very efficient, but it is only used when the user right-clicks on the map.


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 SeparatorLayerAction.INSTANCE instead of new JSeparator

Specified by:
getMenuEntries in class Layer

getToolTipText

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

visitBoundingBox

public void visitBoundingBox(BoundingXYVisitor v)
Specified by:
visitBoundingBox in class Layer

isChanged

public boolean isChanged()
Description copied from class: Layer
Check changed status of layer

Overrides:
isChanged in class Layer
Returns:
True if layer was changed since last paint

isProjectionSupported

public boolean isProjectionSupported(Projection proj)
Description copied from class: Layer
allows to check whether a projection is supported or not

Overrides:
isProjectionSupported in class Layer
Returns:
True if projection is supported for this layer

nameSupportedProjections

public java.lang.String nameSupportedProjections()
Description copied from class: Layer
Specify user information about projections

Overrides:
nameSupportedProjections in class Layer
Returns:
User readable text telling about supported projections


JOSM