Package uk.ac.rdg.resc.godiva.client
Class BaseWmsClient
- java.lang.Object
-
- uk.ac.rdg.resc.godiva.client.BaseWmsClient
-
- All Implemented Interfaces:
com.google.gwt.core.client.EntryPoint
,org.gwtopenmaps.openlayers.client.event.EventListener
,org.gwtopenmaps.openlayers.client.event.MapMoveListener
,org.gwtopenmaps.openlayers.client.event.MapZoomListener
,ElevationSelectionHandler
,GodivaActionsHandler
,LayerSelectionHandler
,PaletteSelectionHandler
,TimeDateSelectionHandler
,ErrorHandler
- Direct Known Subclasses:
Godiva
public abstract class BaseWmsClient extends Object implements com.google.gwt.core.client.EntryPoint, ErrorHandler, GodivaActionsHandler, LayerSelectionHandler, ElevationSelectionHandler, TimeDateSelectionHandler, PaletteSelectionHandler
A class to handle the common operations needed in an EDAL wms client. This is not dependent on there being only a single WMS layer viewable at a time - i.e. each WMS layer can have associated with it an entire set of widgets, in the form of aGodivaStateInfo
object. For a subclass which uses this to implement a single WMS layer client, seeGodiva
- Author:
- Guy Griffiths
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
dateTimeDetailsLoaded
protected String
docHref
protected boolean
layerDetailsLoaded
protected MapArea
mapArea
protected int
mapHeight
protected int
mapWidth
protected boolean
minMaxDetailsLoaded
protected String
nearestTime
protected String
proxyUrl
-
Constructor Summary
Constructors Constructor Description BaseWmsClient()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
autoAdjustPalette(String layerId)
Called when a user wants to automatically adjust the palette rangeprotected abstract void
availableTimesLoaded(String layerId, List<String> availableTimes, String nearestTime)
This is called once a list of available times has been loadedvoid
dateSelected(String layerId, String selectedDate)
Called when a date is selectedvoid
datetimeSelected(String layerId, String selectedTime)
Called when a time is selectedvoid
elevationSelected(String layerId, String elevation)
Called by theElevationSelector
when an elevation has been selectedprotected abstract String
getCurrentTime()
Returns the "current" time.protected MapArea
getMapArea()
protected int
getMapHeight()
Gets the height of the map in the map widgetprotected int
getMapWidth()
Gets the width of the map in the map widgetprotected String
getUrlFromGetArgs(String baseUrl, String... params)
Encodes the URL, including proxy and base WMS URLprotected abstract GodivaStateInfo
getWidgetCollection(String layerId)
Gets theGodivaStateInfo
for the specified layerprotected String
getWmsRequestUrl(String wmsUrl, String request, Map<String,String> parameters)
Builds a URL given the request name and aMap
of parametersprotected void
handleCustomParams(com.google.gwt.json.client.JSONObject parentObj)
This is called after all other parameters have been received from a config servlet, and subclasses can use it to handle custom configuration options from the ConfigServlet.void
handleError(Throwable e)
Handles a general errorprotected abstract void
init()
This gets called once the page has loaded.protected void
initWithDefaults()
Initializes the WMS client with some default settings.protected void
invalidJson(Exception e, String response, String url, boolean displayPopup)
Handles the case where we are unable to parse JSON data returned from the server, or where non-JSON data is returned when we expected JSON data.void
layerDeselected(String layerId)
Called when a layer is deselected.protected void
layerDetailsLoaded(LayerDetails layerDetails)
This is called once a layer's details have been loaded.void
layerSelected(String wmsUrl, String layerId, boolean autoZoomAndPalette)
Called when a layer is selectedprotected abstract void
loadingFinished()
This is called when all loading processes have finishedprotected abstract void
loadingStarted()
This is called when a loading process startsvoid
logScaleChanged(String layerId, boolean newIsLogScale)
Called when the linear/log scale setting has been changedprotected void
maybeRequestAutoRange(String layerId, boolean force)
Possibly requests the auto-detected scale range.void
onMapMove(org.gwtopenmaps.openlayers.client.event.MapMoveListener.MapMoveEvent eventObject)
void
onMapZoom(org.gwtopenmaps.openlayers.client.event.MapZoomListener.MapZoomEvent eventObject)
void
onModuleLoad()
This is the entry point for GWT.void
paletteChanged(String layerId, String paletteName, String style, int nColorBands)
Called when the palette has changed in some wayprotected void
populateWidgets(LayerDetails layerDetails)
Populates the set of widgets associated with this layer.protected void
rangeLoaded(String layerId, double min, double max)
This is called when an auto scale range has been loaded.void
refreshLayerList()
Called when the user would like the list of layers to be refreshedprotected abstract void
requestAndPopulateMenu()
This is called at initialisation, and is used to populate the layer selection menu(s).protected void
requestLayerDetails(String wmsUrl, String layerId, String currentTime, boolean autoZoomAndPalette)
Request details about a particular layer.void
scaleRangeChanged(String layerId, String scaleRange)
Called when the scale range has been adjustedvoid
setLoading(boolean loading)
Should be called when a component starts or stops loading.protected void
setUnitConverter(String layerId, UnitConverter converter)
Allows the client to use different units to those specified on the server (e.g.protected abstract void
updateMap(MapArea mapArea, String layerUpdated)
This is where the map should be updated.protected void
updateMapBase(String layerUpdated)
Checks that all the required details are loaded (or do not need to be) before calling the subclass method-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface uk.ac.rdg.resc.godiva.client.handlers.GodivaActionsHandler
disableWidgets, enableWidgets, updateLinksEtc
-
Methods inherited from interface uk.ac.rdg.resc.godiva.client.handlers.PaletteSelectionHandler
setOpacity
-
-
-
-
Field Detail
-
mapHeight
protected int mapHeight
-
mapWidth
protected int mapWidth
-
proxyUrl
protected String proxyUrl
-
docHref
protected String docHref
-
nearestTime
protected String nearestTime
-
mapArea
protected MapArea mapArea
-
layerDetailsLoaded
protected boolean layerDetailsLoaded
-
dateTimeDetailsLoaded
protected boolean dateTimeDetailsLoaded
-
minMaxDetailsLoaded
protected boolean minMaxDetailsLoaded
-
-
Method Detail
-
onModuleLoad
public void onModuleLoad()
This is the entry point for GWT. Queries a config servlet and sets some global fields. If the config is not present, or there is an error, sets some defaults, and calls the initialisation method.- Specified by:
onModuleLoad
in interfacecom.google.gwt.core.client.EntryPoint
-
handleCustomParams
protected void handleCustomParams(com.google.gwt.json.client.JSONObject parentObj)
This is called after all other parameters have been received from a config servlet, and subclasses can use it to handle custom configuration options from the ConfigServlet.- Parameters:
parentObj
-
-
initWithDefaults
protected void initWithDefaults()
Initializes the WMS client with some default settings. Subclasses can override this to define new defaults
-
getMapArea
protected MapArea getMapArea()
-
getWmsRequestUrl
protected String getWmsRequestUrl(String wmsUrl, String request, Map<String,String> parameters)
Builds a URL given the request name and aMap
of parameters- Parameters:
request
- the request name (e.g. GetMap)parameters
- aMap
of parameters and their values- Returns:
- the URL of the request
-
getUrlFromGetArgs
protected String getUrlFromGetArgs(String baseUrl, String... params)
Encodes the URL, including proxy and base WMS URL- Parameters:
baseUrl
- The base URL to encodeparams
- A series of key=value arguments to append as GET parameters- Returns:
- the encoded URL
-
getMapHeight
protected int getMapHeight()
Gets the height of the map in the map widget- Returns:
- the height in pixels
-
getMapWidth
protected int getMapWidth()
Gets the width of the map in the map widget- Returns:
- the width in pixels
-
requestLayerDetails
protected void requestLayerDetails(String wmsUrl, String layerId, String currentTime, boolean autoZoomAndPalette)
Request details about a particular layer. Once loaded, layerDetailsLoaded will be called.- Parameters:
wmsUrl
- the base URL of the WMS server containing the layer detailslayerId
- the ID of the layer whose details are desiredcurrentTime
- the time we want to know the closest available time to. Can be nullautoZoomAndPalette
- true if we want to zoom to extents and possibly auto-adjust palette once the details have been loaded. Note that this will only auto-adjust the palette if the conditions are right
-
maybeRequestAutoRange
protected void maybeRequestAutoRange(String layerId, boolean force)
Possibly requests the auto-detected scale range. This will make the request ifforce
is true, or we have a default scale range set on the server- Parameters:
layerId
- the ID of the layer to request the scale range forforce
- whether to perform even if a scale has been set on the server
-
rangeLoaded
protected void rangeLoaded(String layerId, double min, double max)
This is called when an auto scale range has been loaded. It can be assumed that by this point we want to update the scale.- Parameters:
layerId
- the layer for which the scale range has been loadedmin
- the minimum scale valuemax
- the maximum scale value
-
layerDetailsLoaded
protected void layerDetailsLoaded(LayerDetails layerDetails)
This is called once a layer's details have been loaded. By default this will just populate the widgets associated with this layer, but subclasses may want to override this method to implement custom behaviour before/after populating the widgets- Parameters:
layerDetails
- the details received from the server
-
populateWidgets
protected void populateWidgets(LayerDetails layerDetails)
Populates the set of widgets associated with this layer. The ID of the layer is taken from theLayerDetails
and the associated widgets are retrieved and populated- Parameters:
layerDetails
- aLayerDetails
object containing the layer details. This gets returned when layer details are loaded
-
updateMapBase
protected void updateMapBase(String layerUpdated)
Checks that all the required details are loaded (or do not need to be) before calling the subclass method
-
invalidJson
protected void invalidJson(Exception e, String response, String url, boolean displayPopup)
Handles the case where we are unable to parse JSON data returned from the server, or where non-JSON data is returned when we expected JSON data. This covers a number of situations and so needs to be quite a general method.- Parameters:
e
- The exception which was caughtresponse
- The message texturl
- The URL which caused the exception
-
layerSelected
public void layerSelected(String wmsUrl, String layerId, boolean autoZoomAndPalette)
Description copied from interface:LayerSelectionHandler
Called when a layer is selected- Specified by:
layerSelected
in interfaceLayerSelectionHandler
- Parameters:
wmsUrl
- The WMS URL where the layer is presentlayerId
- The ID of the layer on the WMS serverautoZoomAndPalette
- Whether we want to automatically zoom to the layer extents and adjust the palette. Note that the palette will not be adjusted if a range has been set on the server
-
layerDeselected
public void layerDeselected(String layerId)
Description copied from interface:LayerSelectionHandler
Called when a layer is deselected. This is only likely to happen on multi-layer systems TODO perhaps this will need a wmsUrl to uniquely locate the layer? Currently we have no multi-layer systems on which to test this, so it's not really important. This comment should be removed when one gets implemented- Specified by:
layerDeselected
in interfaceLayerSelectionHandler
- Parameters:
layerId
- The ID of the layer which has been deselected
-
refreshLayerList
public void refreshLayerList()
Description copied from interface:LayerSelectionHandler
Called when the user would like the list of layers to be refreshed- Specified by:
refreshLayerList
in interfaceLayerSelectionHandler
-
elevationSelected
public void elevationSelected(String layerId, String elevation)
Description copied from interface:ElevationSelectionHandler
Called by theElevationSelector
when an elevation has been selected- Specified by:
elevationSelected
in interfaceElevationSelectionHandler
- Parameters:
layerId
- The layer ID for which an elevation was selectedelevation
- The selected elevation
-
paletteChanged
public void paletteChanged(String layerId, String paletteName, String style, int nColorBands)
Description copied from interface:PaletteSelectionHandler
Called when the palette has changed in some way- Specified by:
paletteChanged
in interfacePaletteSelectionHandler
- Parameters:
layerId
- The layer for which the palette has changedpaletteName
- The name of the palettestyle
- The name of the stylenColorBands
- The number of colour bands
-
scaleRangeChanged
public void scaleRangeChanged(String layerId, String scaleRange)
Description copied from interface:PaletteSelectionHandler
Called when the scale range has been adjusted- Specified by:
scaleRangeChanged
in interfacePaletteSelectionHandler
- Parameters:
layerId
- The layer for which the scale range has changedscaleRange
- A string representing the new scale range
-
logScaleChanged
public void logScaleChanged(String layerId, boolean newIsLogScale)
Description copied from interface:PaletteSelectionHandler
Called when the linear/log scale setting has been changed- Specified by:
logScaleChanged
in interfacePaletteSelectionHandler
- Parameters:
layerId
- The layer for which the linear/log setting has changednewIsLogScale
- true if the new state is logarithmic, false if it is linear
-
autoAdjustPalette
public void autoAdjustPalette(String layerId)
Description copied from interface:PaletteSelectionHandler
Called when a user wants to automatically adjust the palette range- Specified by:
autoAdjustPalette
in interfacePaletteSelectionHandler
- Parameters:
layerId
- The layer for which the palette should be adjusted
-
dateSelected
public void dateSelected(String layerId, String selectedDate)
Description copied from interface:TimeDateSelectionHandler
Called when a date is selected- Specified by:
dateSelected
in interfaceTimeDateSelectionHandler
- Parameters:
layerId
- The layer on which a date has been chosenselectedDate
- A string representing the selected date
-
datetimeSelected
public void datetimeSelected(String layerId, String selectedTime)
Description copied from interface:TimeDateSelectionHandler
Called when a time is selected- Specified by:
datetimeSelected
in interfaceTimeDateSelectionHandler
- Parameters:
layerId
- The layer on which a time has been chosenselectedTime
- A string representing the selected datetime
-
setUnitConverter
protected void setUnitConverter(String layerId, UnitConverter converter)
Allows the client to use different units to those specified on the server (e.g. convert celcius to kelvin)- Parameters:
layerId
- The ID of the layer to convert units forconverter
- TheUnitConverter
to use for conversion
-
setLoading
public void setLoading(boolean loading)
Description copied from interface:GodivaActionsHandler
Should be called when a component starts or stops loading. This allows implementing classes to keep a count of the number of elements loading and take appropriate action when something starts loading, or when everything has finished loading- Specified by:
setLoading
in interfaceGodivaActionsHandler
- Parameters:
loading
- true if the element has started loading, false if it has finished loading
-
onMapMove
public void onMapMove(org.gwtopenmaps.openlayers.client.event.MapMoveListener.MapMoveEvent eventObject)
- Specified by:
onMapMove
in interfaceorg.gwtopenmaps.openlayers.client.event.MapMoveListener
-
onMapZoom
public void onMapZoom(org.gwtopenmaps.openlayers.client.event.MapZoomListener.MapZoomEvent eventObject)
- Specified by:
onMapZoom
in interfaceorg.gwtopenmaps.openlayers.client.event.MapZoomListener
-
handleError
public void handleError(Throwable e)
Description copied from interface:ErrorHandler
Handles a general error- Specified by:
handleError
in interfaceErrorHandler
-
init
protected abstract void init()
This gets called once the page has loaded. Subclasses should use for initializing any widgets, and setting the layout. If this is not implemented, a blank page will be displayed
-
getWidgetCollection
protected abstract GodivaStateInfo getWidgetCollection(String layerId)
Gets theGodivaStateInfo
for the specified layer- Parameters:
layerId
- The WMS layer ID- Returns:
- The state information, usually in the form of widgets
-
requestAndPopulateMenu
protected abstract void requestAndPopulateMenu()
This is called at initialisation, and is used to populate the layer selection menu(s). Subclasses should use this to request any data and then populate the appropriate widget(s)
-
availableTimesLoaded
protected abstract void availableTimesLoaded(String layerId, List<String> availableTimes, String nearestTime)
This is called once a list of available times has been loaded- Parameters:
layerId
- the layer for which times have been loadedavailableTimes
- aList
of available timesnearestTime
- the nearest time to the current time (for e.g. auto selection)
-
updateMap
protected abstract void updateMap(MapArea mapArea, String layerUpdated)
This is where the map should be updated. It gets called when all details have been loaded and we actually want to update the map. Clients should handle this in the appropriate way, which will almost certainly involve a call to mapArea.addLayer(...)- Parameters:
mapArea
- The map area which can be updatedlayerUpdated
- The ID of the layer which we are viewing
-
loadingStarted
protected abstract void loadingStarted()
This is called when a loading process starts
-
loadingFinished
protected abstract void loadingFinished()
This is called when all loading processes have finished
-
getCurrentTime
protected abstract String getCurrentTime()
Returns the "current" time. The definition of current may depend on exactly what the client does. This is the time used when requesting layer details from the server - i.e. the time to which the "nearestTime" will refer- Returns:
- A string representation of the current time
-
-