T
- Tile Source class used for this layerpublic abstract class AbstractTileSourceLayer<T extends AbstractTMSTileSource> extends ImageryLayer implements java.awt.image.ImageObserver, TileLoaderListener, NavigatableComponent.ZoomChangeListener
ImageryLayer.ApplyOffsetAction, ImageryLayer.GammaImageProcessor, ImageryLayer.OffsetAction
Layer.LayerAction, Layer.LayerGpxExportAction, Layer.LayerSaveAction, Layer.LayerSaveAsAction, Layer.MultiLayerAction, Layer.SeparatorLayerAction
Modifier and Type | Field and Description |
---|---|
private AttributionSupport |
attribution |
boolean |
autoLoad
if layer automatically loads new tiles
|
boolean |
autoZoom
if layers changes automatically, when user zooms in
|
private AbstractTileSourceLayer.TileHolder |
clickedTileHolder |
int |
currentZoomLevel
Zoomlevel at which tiles is currently downloaded.
|
private static java.awt.Font |
InfoFont |
static int |
MAX_ZOOM
maximum zoom level supported
|
static int |
MIN_ZOOM
minium zoom level supported
|
private boolean |
needRedraw |
private AbstractTileSourceLayer.TileSet |
nullTileSet |
private static java.lang.String |
PREFERENCE_PREFIX |
static BooleanProperty |
PROP_DEFAULT_AUTOLOAD
do set autoload when creating a new layer
|
static BooleanProperty |
PROP_DEFAULT_AUTOZOOM
do set autozoom when creating a new layer
|
static BooleanProperty |
PROP_DEFAULT_SHOWERRORS
do show errors per default
|
static IntegerProperty |
PROP_MAX_ZOOM_LVL
maximum zoom level to show to user
|
static IntegerProperty |
PROP_MIN_ZOOM_LVL
minimum zoom level to show to user
|
boolean |
showErrors
if layer should show errors on tiles
|
protected TileCache |
tileCache |
protected TileLoader |
tileLoader |
protected T |
tileSource |
static IntegerProperty |
ZOOM_OFFSET
Offset between calculated zoom level and zoom level used to download and show tiles.
|
dx, dy, gammaImageProcessor, icon, info, PROP_FADE_AMOUNT, PROP_FADE_COLOR, PROP_SHARPEN_LEVEL
FILTER_STATE_PROP, NAME_PROP, OPACITY_PROP, propertyChangeSupport, VISIBLE_PROP
Constructor and Description |
---|
AbstractTileSourceLayer(ImageryInfo info)
Creates Tile Source based Imagery Layer based on Imagery Info
|
Modifier and Type | Method and Description |
---|---|
private static boolean |
actionSupportLayers(java.util.List<Layer> layers) |
static int |
checkMaxZoomLvl(int maxZoomLvl,
TileSource ts)
Checks zoom level against settings
|
static int |
checkMinZoomLvl(int minZoomLvl,
TileSource ts)
Checks zoom level against settings
|
void |
clearTileCache(ProgressMonitor monitor)
Clears the tile cache.
|
java.io.File |
createAndOpenSaveFileChooser()
Creates a new "Save" dialog for this layer and makes it visible.
When the user has chosen a file, checks the file extension, and confirms overwrite if needed. |
boolean |
decreaseZoomLevel()
Zoom out from map.
|
AbstractTileSourceLayer.PrecacheTask |
downloadAreaToCache(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.
|
private void |
drawImageInside(java.awt.Graphics g,
java.awt.Image sourceImg,
java.awt.Rectangle source,
java.awt.Rectangle border) |
protected long |
estimateMemoryUsage() |
protected int |
estimateTileCacheSize() |
protected int |
getBestZoom() |
javax.swing.Action[] |
getCommonEntries()
Returns the common menu entries.
|
protected java.util.Map<java.lang.String,java.lang.String> |
getHeaders(T tileSource) |
javax.swing.Action[] |
getLayerListEntries() |
private java.awt.Image |
getLoadedTileImage(Tile tile)
Returns the image for the given tile if both tile and image are loaded.
|
protected int |
getMaxZoomLvl() |
static int |
getMaxZoomLvl(TileSource ts) |
javax.swing.Action[] |
getMenuEntries()
Returns list of actions.
|
protected int |
getMinZoomLvl() |
static int |
getMinZoomLvl(TileSource ts) |
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 ICoordinate |
getShiftedCoord(EastNorth en) |
private LatLon |
getShiftedLatLon(EastNorth en) |
private Tile |
getTile(int x,
int y,
int zoom)
Returns tile at given position.
|
private Tile |
getTileForPixelpos(int px,
int py)
Returns tile for a pixel position.
|
protected abstract TileLoaderFactory |
getTileLoaderFactory() |
private static <S extends AbstractTMSTileSource> |
getTileSetInfo(AbstractTileSourceLayer.TileSet ts) |
protected abstract T |
getTileSource(ImageryInfo info) |
java.lang.String |
getToolTipText() |
private AbstractTileSourceLayer.TileSet |
getVisibleTileSet() |
void |
hookUpMapView()
Creates popup menu items and binds to mouse actions
|
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()
Zoom in, go closer to map.
|
protected void |
initTileSource(T tileSource) |
boolean |
isChanged()
Check changed status of layer
|
boolean |
isSavable()
Replies the savable state of this layer (i.e if it can be saved through a "File->Save" dialog).
|
protected void |
loadAllErrorTiles(boolean force) |
protected void |
loadAllTiles(boolean force) |
private boolean |
loadTile(Tile tile,
boolean force) |
private void |
myDrawString(java.awt.Graphics g,
java.lang.String text,
int x,
int y) |
void |
paint(java.awt.Graphics2D g,
MapView mv,
Bounds bounds)
Paint the dataset using the engine set.
|
private java.util.List<Tile> |
paintTileImages(java.awt.Graphics g,
AbstractTileSourceLayer.TileSet ts,
int zoom,
Tile border) |
private void |
paintTileText(AbstractTileSourceLayer.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) |
protected void |
redraw()
Initiates a repaint of Main.map
|
void |
setGamma(double gamma)
Sets a new gamma value,
1 stands for no correction. |
static void |
setMaxZoomLvl(int maxZoomLvl)
Sets maximum zoom level, that layer will attempt show
|
static void |
setMinZoomLvl(int minZoomLvl)
Sets minimum zoom level, that layer will attempt show
|
void |
setOffset(double dx,
double dy)
Marks layer as needing redraw on offset change
|
boolean |
setZoomLevel(int zoom)
Sets the zoom level of the layer
|
private Tile |
tempCornerTile(Tile t) |
void |
tileLoadingFinished(Tile tile,
boolean success)
Will be called if a new
Tile has been loaded successfully. |
private java.awt.Rectangle |
tileToRect(Tile t1) |
void |
visitBoundingBox(BoundingXYVisitor v) |
void |
zoomChanged()
This fires every time the user changes the zoom, but also (due to ZoomChangeListener) - on all
changes to visible map (panning/zooming)
|
boolean |
zoomDecreaseAllowed()
Check if zooming out is allowed
|
boolean |
zoomIncreaseAllowed() |
addImageProcessor, applyImageProcessors, create, createImageProcessor, createSharpener, destroy, displace, drawErrorTile, getDx, getDy, getFadeColor, getFadeColorWithAlpha, getGamma, getIcon, getImageProcessors, getInfo, getInfoComponent, getOffsetMenuItem, getOffsetMenuItem, getPPD, isMergable, mergeFrom, removeImageProcessor
addPropertyChangeListener, checkSaveConditions, fireFilterStateChanged, fireOpacityChanged, fireVisibleChanged, getAssociatedFile, getColor, getName, getOpacity, isBackgroundLayer, isInfoResizable, isProjectionSupported, isRenamed, isVisible, nameSupportedProjections, onPostLoadFromFile, projectionChanged, removePropertyChangeListener, rename, setAssociatedFile, setBackgroundLayer, setFilterStateChanged, setName, setOpacity, setVisible, toggleVisible
private static final java.lang.String PREFERENCE_PREFIX
public static final int MAX_ZOOM
public static final int MIN_ZOOM
private static final java.awt.Font InfoFont
public static final BooleanProperty PROP_DEFAULT_AUTOZOOM
public static final BooleanProperty PROP_DEFAULT_AUTOLOAD
public static final BooleanProperty PROP_DEFAULT_SHOWERRORS
public static final IntegerProperty PROP_MIN_ZOOM_LVL
public static final IntegerProperty PROP_MAX_ZOOM_LVL
public int currentZoomLevel
private boolean needRedraw
private final AttributionSupport attribution
private final AbstractTileSourceLayer.TileHolder clickedTileHolder
public boolean autoZoom
public boolean autoLoad
public boolean showErrors
public static final IntegerProperty ZOOM_OFFSET
protected T extends AbstractTMSTileSource tileSource
protected TileLoader tileLoader
private final AbstractTileSourceLayer.TileSet nullTileSet
public AbstractTileSourceLayer(ImageryInfo info)
info
- imagery infoprotected abstract TileLoaderFactory getTileLoaderFactory()
protected abstract T getTileSource(ImageryInfo info)
info
- imagery infojava.lang.IllegalArgumentException
- when Imagery is not supported by layerprotected java.util.Map<java.lang.String,java.lang.String> getHeaders(T tileSource)
protected void initTileSource(T tileSource)
public void tileLoadingFinished(Tile tile, boolean success)
TileLoaderListener
Tile
has been loaded successfully.
Loaded can mean downloaded or loaded from file cache.tileLoadingFinished
in interface TileLoaderListener
tile
- The tilesuccess
- true
if the tile has been loaded successfully, false
otherwisepublic void clearTileCache(ProgressMonitor monitor)
monitor
- not used in this implementation - as cache clear is instaneusprotected void redraw()
Main.map
,
Component.repaint()
public void setGamma(double gamma)
ImageryLayer
1
stands for no correction.setGamma
in class ImageryLayer
gamma
- new gamma valuepublic void setOffset(double dx, double dy)
setOffset
in class ImageryLayer
private double getScaleFactor(int zoom)
zoom
- zoom levelprotected int getBestZoom()
private static boolean actionSupportLayers(java.util.List<Layer> layers)
public void hookUpMapView()
hookUpMapView
in class Layer
protected long estimateMemoryUsage()
estimateMemoryUsage
in class Layer
protected int estimateTileCacheSize()
public static int checkMaxZoomLvl(int maxZoomLvl, TileSource ts)
maxZoomLvl
- zoom level to checkts
- tile source to crosscheck withpublic static int checkMinZoomLvl(int minZoomLvl, TileSource ts)
minZoomLvl
- zoom level to checkts
- tile source to crosscheck withpublic static int getMaxZoomLvl(TileSource ts)
ts
- TileSource for which we want to know maximum zoom levelpublic static int getMinZoomLvl(TileSource ts)
ts
- TileSource for which we want to know minimum zoom levelpublic static void setMaxZoomLvl(int maxZoomLvl)
maxZoomLvl
- maximum zoom levelpublic static void setMinZoomLvl(int minZoomLvl)
minZoomLvl
- minimum zoom levelpublic void zoomChanged()
zoomChanged
in interface NavigatableComponent.ZoomChangeListener
protected int getMaxZoomLvl()
protected int getMinZoomLvl()
public boolean zoomIncreaseAllowed()
public boolean increaseZoomLevel()
public boolean setZoomLevel(int zoom)
zoom
- zoom levelpublic boolean zoomDecreaseAllowed()
public boolean decreaseZoomLevel()
private Tile tempCornerTile(Tile t)
private Tile getOrCreateTile(int x, int y, int zoom)
private Tile getTile(int x, int y, int zoom)
x
- tile number on the x axis of the tile to be retrievedy
- tile number on the y axis of the tile to be retrievedzoom
- zoom level of the tile to be retrievedprivate AbstractTileSourceLayer.TileSet getVisibleTileSet()
protected void loadAllTiles(boolean force)
protected void loadAllErrorTiles(boolean force)
public boolean imageUpdate(java.awt.Image img, int infoflags, int x, int y, int width, int height)
imageUpdate
in interface java.awt.image.ImageObserver
private boolean imageLoaded(java.awt.Image i)
private java.awt.Image getLoadedTileImage(Tile tile)
tile
- the Tile for which the image should be returnedprivate java.awt.Rectangle tileToRect(Tile t1)
private void drawImageInside(java.awt.Graphics g, java.awt.Image sourceImg, java.awt.Rectangle source, java.awt.Rectangle border)
private java.util.List<Tile> paintTileImages(java.awt.Graphics g, AbstractTileSourceLayer.TileSet ts, int zoom, Tile border)
private void myDrawString(java.awt.Graphics g, java.lang.String text, int x, int y)
private void paintTileText(AbstractTileSourceLayer.TileSet ts, Tile tile, java.awt.Graphics g, MapView mv, int zoom, Tile t)
private LatLon getShiftedLatLon(EastNorth en)
private ICoordinate getShiftedCoord(EastNorth en)
private static <S extends AbstractTMSTileSource> AbstractTileSourceLayer.TileSetInfo getTileSetInfo(AbstractTileSourceLayer.TileSet ts)
public void paint(java.awt.Graphics2D g, MapView mv, Bounds bounds)
Layer
paint
in interface MapViewPaintable
paint
in class Layer
g
- Graphicsmv
- The object that can translate GeoPoints to screen coordinates.bounds
- Bounding boxprivate Tile getTileForPixelpos(int px, int py)
This isn't very efficient, but it is only used when the user right-clicks on the map.
px
- pixel X coordinatepy
- pixel Y coordinatepublic javax.swing.Action[] getMenuEntries()
Layer
Layer.SeparatorLayerAction.INSTANCE
instead of new JSeparatorgetMenuEntries
in class Layer
public javax.swing.Action[] getLayerListEntries()
public javax.swing.Action[] getCommonEntries()
public java.lang.String getToolTipText()
getToolTipText
in class Layer
public void visitBoundingBox(BoundingXYVisitor v)
visitBoundingBox
in class Layer
public boolean isChanged()
Layer
public AbstractTileSourceLayer.PrecacheTask downloadAreaToCache(ProgressMonitor progressMonitor, java.util.List<LatLon> points, double bufferX, double bufferY)
progressMonitor
- progress monitor for download taskpoints
- lat/lon coordinates to downloadbufferX
- how many units in current Coordinate Reference System to cover in X axis in both sidesbufferY
- how many units in current Coordinate Reference System to cover in Y axis in both sidespublic boolean isSavable()
Layer
public java.io.File createAndOpenSaveFileChooser()
Layer
createAndOpenSaveFileChooser
in class Layer
File
SaveActionBase.createAndOpenSaveFileChooser(java.lang.String, org.openstreetmap.josm.actions.ExtensionFileFilter)