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 aGodivaStateInfoobject. 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 booleandateTimeDetailsLoadedprotected StringdocHrefprotected booleanlayerDetailsLoadedprotected MapAreamapAreaprotected intmapHeightprotected intmapWidthprotected booleanminMaxDetailsLoadedprotected StringnearestTimeprotected StringproxyUrl
-
Constructor Summary
Constructors Constructor Description BaseWmsClient()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidautoAdjustPalette(String layerId)Called when a user wants to automatically adjust the palette rangeprotected abstract voidavailableTimesLoaded(String layerId, List<String> availableTimes, String nearestTime)This is called once a list of available times has been loadedvoiddateSelected(String layerId, String selectedDate)Called when a date is selectedvoiddatetimeSelected(String layerId, String selectedTime)Called when a time is selectedvoidelevationSelected(String layerId, String elevation)Called by theElevationSelectorwhen an elevation has been selectedprotected abstract StringgetCurrentTime()Returns the "current" time.protected MapAreagetMapArea()protected intgetMapHeight()Gets the height of the map in the map widgetprotected intgetMapWidth()Gets the width of the map in the map widgetprotected StringgetUrlFromGetArgs(String baseUrl, String... params)Encodes the URL, including proxy and base WMS URLprotected abstract GodivaStateInfogetWidgetCollection(String layerId)Gets theGodivaStateInfofor the specified layerprotected StringgetWmsRequestUrl(String wmsUrl, String request, Map<String,String> parameters)Builds a URL given the request name and aMapof parametersprotected voidhandleCustomParams(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.voidhandleError(Throwable e)Handles a general errorprotected abstract voidinit()This gets called once the page has loaded.protected voidinitWithDefaults()Initializes the WMS client with some default settings.protected voidinvalidJson(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.voidlayerDeselected(String layerId)Called when a layer is deselected.protected voidlayerDetailsLoaded(LayerDetails layerDetails)This is called once a layer's details have been loaded.voidlayerSelected(String wmsUrl, String layerId, boolean autoZoomAndPalette)Called when a layer is selectedprotected abstract voidloadingFinished()This is called when all loading processes have finishedprotected abstract voidloadingStarted()This is called when a loading process startsvoidlogScaleChanged(String layerId, boolean newIsLogScale)Called when the linear/log scale setting has been changedprotected voidmaybeRequestAutoRange(String layerId, boolean force)Possibly requests the auto-detected scale range.voidonMapMove(org.gwtopenmaps.openlayers.client.event.MapMoveListener.MapMoveEvent eventObject)voidonMapZoom(org.gwtopenmaps.openlayers.client.event.MapZoomListener.MapZoomEvent eventObject)voidonModuleLoad()This is the entry point for GWT.voidpaletteChanged(String layerId, String paletteName, String style, int nColorBands)Called when the palette has changed in some wayprotected voidpopulateWidgets(LayerDetails layerDetails)Populates the set of widgets associated with this layer.protected voidrangeLoaded(String layerId, double min, double max)This is called when an auto scale range has been loaded.voidrefreshLayerList()Called when the user would like the list of layers to be refreshedprotected abstract voidrequestAndPopulateMenu()This is called at initialisation, and is used to populate the layer selection menu(s).protected voidrequestLayerDetails(String wmsUrl, String layerId, String currentTime, boolean autoZoomAndPalette)Request details about a particular layer.voidscaleRangeChanged(String layerId, String scaleRange)Called when the scale range has been adjustedvoidsetLoading(boolean loading)Should be called when a component starts or stops loading.protected voidsetUnitConverter(String layerId, UnitConverter converter)Allows the client to use different units to those specified on the server (e.g.protected abstract voidupdateMap(MapArea mapArea, String layerUpdated)This is where the map should be updated.protected voidupdateMapBase(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:
onModuleLoadin 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 aMapof parameters- Parameters:
request- the request name (e.g. GetMap)parameters- aMapof 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 ifforceis 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 theLayerDetailsand the associated widgets are retrieved and populated- Parameters:
layerDetails- aLayerDetailsobject 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:LayerSelectionHandlerCalled when a layer is selected- Specified by:
layerSelectedin 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:LayerSelectionHandlerCalled 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:
layerDeselectedin interfaceLayerSelectionHandler- Parameters:
layerId- The ID of the layer which has been deselected
-
refreshLayerList
public void refreshLayerList()
Description copied from interface:LayerSelectionHandlerCalled when the user would like the list of layers to be refreshed- Specified by:
refreshLayerListin interfaceLayerSelectionHandler
-
elevationSelected
public void elevationSelected(String layerId, String elevation)
Description copied from interface:ElevationSelectionHandlerCalled by theElevationSelectorwhen an elevation has been selected- Specified by:
elevationSelectedin 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:PaletteSelectionHandlerCalled when the palette has changed in some way- Specified by:
paletteChangedin 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:PaletteSelectionHandlerCalled when the scale range has been adjusted- Specified by:
scaleRangeChangedin 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:PaletteSelectionHandlerCalled when the linear/log scale setting has been changed- Specified by:
logScaleChangedin 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:PaletteSelectionHandlerCalled when a user wants to automatically adjust the palette range- Specified by:
autoAdjustPalettein interfacePaletteSelectionHandler- Parameters:
layerId- The layer for which the palette should be adjusted
-
dateSelected
public void dateSelected(String layerId, String selectedDate)
Description copied from interface:TimeDateSelectionHandlerCalled when a date is selected- Specified by:
dateSelectedin 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:TimeDateSelectionHandlerCalled when a time is selected- Specified by:
datetimeSelectedin 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- TheUnitConverterto use for conversion
-
setLoading
public void setLoading(boolean loading)
Description copied from interface:GodivaActionsHandlerShould 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:
setLoadingin 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:
onMapMovein interfaceorg.gwtopenmaps.openlayers.client.event.MapMoveListener
-
onMapZoom
public void onMapZoom(org.gwtopenmaps.openlayers.client.event.MapZoomListener.MapZoomEvent eventObject)
- Specified by:
onMapZoomin interfaceorg.gwtopenmaps.openlayers.client.event.MapZoomListener
-
handleError
public void handleError(Throwable e)
Description copied from interface:ErrorHandlerHandles a general error- Specified by:
handleErrorin 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 theGodivaStateInfofor 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- aListof 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
-
-