org.openstreetmap.josm.gui.layer
Class WMSLayer

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.WMSLayer
All Implemented Interfaces:
java.awt.image.ImageObserver, java.io.Externalizable, java.io.Serializable, Preferences.PreferenceChangedListener, ProjectionChangeListener, MapViewPaintable, Destroyable

public class WMSLayer
extends ImageryLayer
implements java.awt.image.ImageObserver, Preferences.PreferenceChangedListener, java.io.Externalizable

This is a layer that grabs the current screen from an WMS server. The data fetched this way is tiled and managed to the disc to reduce server load.

See Also:
Serialized Form

Nested Class Summary
 class WMSLayer.BookmarkWmsAction
          This action will add a WMS layer menu entry with the current WMS layer URL and name extended by the current resolution.
static class WMSLayer.ChangeResolutionAction
           
 class WMSLayer.DownloadAction
           
static class WMSLayer.PrecacheTask
           
 class WMSLayer.ReloadErrorTilesAction
           
private  class WMSLayer.StartStopAction
           
 class WMSLayer.ToggleAlphaAction
           
private  class WMSLayer.ZoomToNativeResolution
           
 
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 autoDownloadEnabled
           
private  int bmaxx
           
private  int bmaxy
           
private  int bminx
           
private  int bminy
           
private  int bottomEdge
           
 WmsCache cache
           
private  boolean canceled
           
protected  int daStep
           
protected  int dax
           
protected  int day
           
private  java.util.List<WMSRequest> finishedRequests
           
private  java.util.List<Grabber> grabbers
           
private  java.util.List<java.lang.Thread> grabberThreads
           
protected  GeorefImage[][] images
           
protected  int imageSize
           
protected  ImageryInfo info
           
private  boolean isInvalidUrlConfirmed
          set to true if the user confirmed to use an potentially invalid WMS base url
private  int leftEdge
           
 int messageNum
           
protected  int minZoom
           
private static ObjectFactory OBJECT_FACTORY
           
private  java.util.List<WMSRequest> processingRequests
          List of request currently being processed by download threads
static BooleanProperty PROP_ALPHA_CHANNEL
           
static IntegerProperty PROP_IMAGE_SIZE
           
static BooleanProperty PROP_OVERLAP
           
static IntegerProperty PROP_OVERLAP_EAST
           
static IntegerProperty PROP_OVERLAP_NORTH
           
static IntegerProperty PROP_SIMULTANEOUS_CONNECTIONS
           
private  java.util.concurrent.locks.Condition queueEmpty
           
private  java.util.List<WMSRequest> requestQueue
           
private  java.util.concurrent.locks.Lock requestQueueLock
           
protected  java.lang.String resolution
           
protected  int serializeFormatVersion
           
protected  boolean settingsChanged
           
private  int threadCount
           
private  boolean usesInvalidUrl
          set to true if this layer uses an invalid base url
private  int workingThreadCount
           
 
Fields inherited from class org.openstreetmap.josm.gui.layer.ImageryLayer
dx, dy, icon, 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
WMSLayer()
           
WMSLayer(ImageryInfo info)
           
 
Method Summary
 void addRequest(WMSRequest request)
           
private  void cancelGrabberThreads(boolean wait)
           
 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.
 void destroy()
          Called, when the layer is removed from the mapview and is going to be destroyed.
 void doSetName(java.lang.String name)
           
protected  void downloadAndPaintVisible(java.awt.Graphics g, MapView mv, boolean real)
           
 void downloadAreaToCache(WMSLayer.PrecacheTask precacheTask, java.util.List<LatLon> points, double bufferX, double bufferY)
           
 GeorefImage findImage(EastNorth eastNorth)
           
 void finishRequest(WMSRequest request)
           
private  void gatherFinishedRequests()
           
 int getBaseImageHeight()
           
 int getBaseImageWidth()
           
 ProjectionBounds getBounds(WMSRequest request)
           
 EastNorth getEastNorth(int xIndex, int yIndex)
           
protected  Grabber getGrabber(boolean localOnly)
           
 int getImageHeight(int yIndex)
           
 int getImageSize()
           
 int getImageWidth(int xIndex)
           
 int getImageX(int imageIndex)
           
 int getImageXIndex(double coord)
           
 int getImageY(int imageIndex)
           
 int getImageYIndex(double coord)
           
 ImageryInfo getInfo()
           
 javax.swing.Action[] getMenuEntries()
          Returns list of actions.
 WMSRequest getRequest(boolean localOnly)
           
private  int getRequestPriority(WMSRequest request)
           
 java.lang.String getToolTipText()
           
 boolean hasAutoDownload()
           
 void hookUpMapView()
          Initialization code, that depends on Main.map.mapView.
 boolean imageUpdate(java.awt.Image img, int infoflags, int x, int y, int width, int height)
           
 void initializeImages()
           
 boolean isChanged()
          Check changed status of layer
 boolean isOverlapEnabled()
           
 boolean isProjectionSupported(Projection proj)
          allows to check whether a projection is supported or not
 boolean isSavable()
          Replies the savable state of this layer (i.e if it can be saved through a "File->Save" dialog).
private  int modulo(int a, int b)
           
 java.lang.String nameSupportedProjections()
          Specify user information about projections
 java.awt.image.BufferedImage normalizeImage(java.awt.image.BufferedImage img)
           
 void onPostLoadFromFile()
          Initializes the layer after a successful load of data from a file
 void paint(java.awt.Graphics2D g, MapView mv, Bounds b)
          Paint the dataset using the engine set.
 void preferenceChanged(Preferences.PreferenceChangeEvent event)
           
 void readExternal(java.io.ObjectInput in)
           
 boolean requestIsVisible(WMSRequest request)
           
 void setOffset(double dx, double dy)
           
private  void sortRequests(boolean localOnly)
           
private  void startGrabberThreads()
           
 void visitBoundingBox(BoundingXYVisitor v)
           
 void writeExternal(java.io.ObjectOutput out)
           
private  boolean zoomIsTooBig()
           
 
Methods inherited from class org.openstreetmap.josm.gui.layer.ImageryLayer
create, createoffsetServerThread, displace, drawErrorTile, enableOffsetServer, getDx, getDy, getFadeColor, getFadeColorWithAlpha, getIcon, getInfoComponent, getOffsetMenuItem, getOffsetMenuItem, getPPD, isMergable, mergeFrom, sharpenImage
 
Methods inherited from class org.openstreetmap.josm.gui.layer.Layer
addPropertyChangeListener, checkSaveConditions, fireOpacityChanged, fireVisibleChanged, getAssociatedFile, getColor, getName, getOpacity, isBackgroundLayer, isVisible, 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

OBJECT_FACTORY

private static final ObjectFactory OBJECT_FACTORY

PROP_ALPHA_CHANNEL

public static final BooleanProperty PROP_ALPHA_CHANNEL

PROP_SIMULTANEOUS_CONNECTIONS

public static final IntegerProperty PROP_SIMULTANEOUS_CONNECTIONS

PROP_OVERLAP

public static final BooleanProperty PROP_OVERLAP

PROP_OVERLAP_EAST

public static final IntegerProperty PROP_OVERLAP_EAST

PROP_OVERLAP_NORTH

public static final IntegerProperty PROP_OVERLAP_NORTH

PROP_IMAGE_SIZE

public static final IntegerProperty PROP_IMAGE_SIZE

messageNum

public int messageNum

resolution

protected java.lang.String resolution

imageSize

protected int imageSize

dax

protected int dax

day

protected int day

daStep

protected int daStep

minZoom

protected int minZoom

images

protected GeorefImage[][] images

serializeFormatVersion

protected final int serializeFormatVersion
See Also:
Constant Field Values

autoDownloadEnabled

protected boolean autoDownloadEnabled

settingsChanged

protected boolean settingsChanged

info

protected ImageryInfo info

cache

public WmsCache cache

attribution

private AttributionSupport attribution

bminx

private volatile int bminx

bminy

private volatile int bminy

bmaxx

private volatile int bmaxx

bmaxy

private volatile int bmaxy

leftEdge

private volatile int leftEdge

bottomEdge

private volatile int bottomEdge

requestQueue

private final java.util.List<WMSRequest> requestQueue

finishedRequests

private final java.util.List<WMSRequest> finishedRequests

processingRequests

private final java.util.List<WMSRequest> processingRequests
List of request currently being processed by download threads


requestQueueLock

private final java.util.concurrent.locks.Lock requestQueueLock

queueEmpty

private final java.util.concurrent.locks.Condition queueEmpty

grabbers

private final java.util.List<Grabber> grabbers

grabberThreads

private final java.util.List<java.lang.Thread> grabberThreads

threadCount

private int threadCount

workingThreadCount

private int workingThreadCount

canceled

private boolean canceled

usesInvalidUrl

private boolean usesInvalidUrl
set to true if this layer uses an invalid base url


isInvalidUrlConfirmed

private boolean isInvalidUrlConfirmed
set to true if the user confirmed to use an potentially invalid WMS base url

Constructor Detail

WMSLayer

public WMSLayer()

WMSLayer

public WMSLayer(ImageryInfo info)
Method Detail

hookUpMapView

public void hookUpMapView()
Description copied from class: Layer
Initialization code, that depends on Main.map.mapView. It is always called in the event dispatching thread. Note that Main.map is null as long as no layer has been added, so do not execute code in the constructor, that assumes Main.map.mapView is not null. Instead override this method.

Overrides:
hookUpMapView in class Layer

doSetName

public void doSetName(java.lang.String name)

hasAutoDownload

public boolean hasAutoDownload()

downloadAreaToCache

public void downloadAreaToCache(WMSLayer.PrecacheTask precacheTask,
                                java.util.List<LatLon> points,
                                double bufferX,
                                double bufferY)

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 can not add itself safely as 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 ImageryLayer

initializeImages

public void initializeImages()

getInfo

public ImageryInfo getInfo()
Overrides:
getInfo in class ImageryLayer

getToolTipText

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

modulo

private int modulo(int a,
                   int b)

zoomIsTooBig

private boolean zoomIsTooBig()

paint

public void paint(java.awt.Graphics2D g,
                  MapView mv,
                  Bounds b)
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.

setOffset

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

getImageXIndex

public int getImageXIndex(double coord)

getImageYIndex

public int getImageYIndex(double coord)

getImageX

public int getImageX(int imageIndex)

getImageY

public int getImageY(int imageIndex)

getImageWidth

public int getImageWidth(int xIndex)

getImageHeight

public int getImageHeight(int yIndex)

getBaseImageWidth

public int getBaseImageWidth()
Returns:
Size of image in original zoom

getBaseImageHeight

public int getBaseImageHeight()
Returns:
Size of image in original zoom

getImageSize

public int getImageSize()

isOverlapEnabled

public boolean isOverlapEnabled()

normalizeImage

public java.awt.image.BufferedImage normalizeImage(java.awt.image.BufferedImage img)
Returns:
When overlapping is enabled, return visible part of tile. Otherwise return original image

getEastNorth

public EastNorth getEastNorth(int xIndex,
                              int yIndex)
Parameters:
xIndex -
yIndex -
Returns:
Real EastNorth of given tile. dx/dy is not counted in

downloadAndPaintVisible

protected void downloadAndPaintVisible(java.awt.Graphics g,
                                       MapView mv,
                                       boolean real)

visitBoundingBox

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

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

findImage

public GeorefImage findImage(EastNorth eastNorth)

getRequestPriority

private int getRequestPriority(WMSRequest request)
Parameters:
request -
Returns:
-1 if request is no longer needed, otherwise priority of request (lower number <=> more important request)

sortRequests

private void sortRequests(boolean localOnly)

getRequest

public WMSRequest getRequest(boolean localOnly)

finishRequest

public void finishRequest(WMSRequest request)

addRequest

public void addRequest(WMSRequest request)

requestIsVisible

public boolean requestIsVisible(WMSRequest request)

gatherFinishedRequests

private void gatherFinishedRequests()

cancelGrabberThreads

private void cancelGrabberThreads(boolean wait)

startGrabberThreads

private void startGrabberThreads()

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

preferenceChanged

public void preferenceChanged(Preferences.PreferenceChangeEvent event)
Specified by:
preferenceChanged in interface Preferences.PreferenceChangedListener

getGrabber

protected Grabber getGrabber(boolean localOnly)

getBounds

public ProjectionBounds getBounds(WMSRequest request)

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

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

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

onPostLoadFromFile

public void onPostLoadFromFile()
Description copied from class: Layer
Initializes the layer after a successful load of data from a file

Overrides:
onPostLoadFromFile in class Layer

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

createAndOpenSaveFileChooser

public java.io.File createAndOpenSaveFileChooser()
Description copied from class: Layer
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.

Overrides:
createAndOpenSaveFileChooser in class Layer
Returns:
The output File
See Also:
SaveActionBase.createAndOpenSaveFileChooser(java.lang.String, org.openstreetmap.josm.actions.ExtensionFileFilter)


JOSM