Class MapContent
- Object
-
- MapContent
-
- Direct Known Subclasses:
SingleLayerMapContent
public class MapContent extends Object
Stores the contents of a map for display, including a list of layers, a MapViewport defining the device and world bounds of display area, and optional user data.Methods are provided to add, remove and reorder layers. Alternatively, the list of layers can be accessed directly with the layers(). For example:
Operations on the list returned by themapContent.layers().add( newLayer );layers{}method are guaranteed to be thread safe, and modifying the list contents will result inMapLayerListEventsbeing published.Note: This object is similar to early drafts of the OGC Open Web Service Context specification.
- Since:
- 2.7
- Author:
- Jody Garnett
-
-
Field Summary
Fields Modifier and Type Field Description protected static LoggerLOGGERThe logger for the map module.protected MapViewportviewportViewport for map rendering.
-
Constructor Summary
Constructors Constructor Description MapContent()Creates a new map content.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddLayer(Layer layer)Add a new layer (if not already present).intaddLayers(Collection<? extends Layer> layers)Adds all layers from the input collection that are not already present in this map content.voidaddMapBoundsListener(MapBoundsListener listener)Register interest in receivingMapBoundsEvents.voidaddMapLayerListListener(MapLayerListListener listener)Register interest in receiving aLayerListEvent.voidaddPropertyChangeListener(PropertyChangeListener listener)Registers PropertyChangeListener to receive events.voiddispose()Clean up any listeners or cached state associated with this MapContent.protected voidfinalize()Checks that dispose has been called; producing a warning if needed.protected voidfireLayerAdded(Layer element, int fromIndex, int toIndex)protected voidfireLayerEvent(Layer element, int index, MapLayerEvent layerEvent)protected voidfireLayerMoved(Layer element, int toIndex)protected voidfireLayerPreDispose(Layer element, int toIndex)protected voidfireLayerRemoved(Layer element, int fromIndex, int toIndex)protected voidfireProperty(String propertyName, Object old, Object value)CoordinateReferenceSystemgetCoordinateReferenceSystem()The coordinate reference system used for rendering the map.ReferencedEnvelopegetMaxBounds()Get the bounding box of all the layers in this Map.StringgetTitle()Get the title, returns an empty string if it has not been set yet.Map<String,Object>getUserData()As an example it can be used to record contact details, map abstract, keywords and so forth for an OGC "Open Web Service Context" document.MapViewportgetViewport()Viewport describing the area visible on screen.List<Layer>layers()Gets the list of layers for this map content.protected voidlistenToMapLayers(boolean listen)Listen to the map layers; passing any events on to our own mapListListeners.voidmoveLayer(int sourcePosition, int destPosition)Moves a layer in the layer list.booleanremoveLayer(Layer layer)Removes the given layer, if present, and publishes a MapLayerListEvent.voidremoveMapBoundsListener(MapBoundsListener listener)Remove interest in receiving aBoundingBoxEvents.voidremoveMapLayerListListener(MapLayerListListener listener)Remove interest in receivingLayerListEvent.voidremovePropertyChangeListener(PropertyChangeListener listener)Removes PropertyChangeListener from the list of listeners.voidsetTitle(String title)Set the title of this context.voidsetViewport(MapViewport viewport)Sets the viewport for this map content.
-
-
-
Field Detail
-
LOGGER
protected static final Logger LOGGER
The logger for the map module.
-
viewport
protected MapViewport viewport
Viewport for map rendering.While the map maintains one viewport internally to better reflect a map context document you are free to maintain a separate viewport; or indeed construct many viewports representing tiles to be rendered.
-
-
Method Detail
-
finalize
protected void finalize() throws ThrowableChecks that dispose has been called; producing a warning if needed.
-
dispose
public void dispose()
Clean up any listeners or cached state associated with this MapContent.Please note that open connections (FeatureSources and GridCoverage readers) are the responsibility of your application and are not cleaned up by this method.
-
addMapLayerListListener
public void addMapLayerListListener(MapLayerListListener listener)
Register interest in receiving aLayerListEvent. ALayerListEventis sent if a layer is added or removed, but not if the data within a layer changes.- Parameters:
listener- The object to notify when Layers have changed.
-
listenToMapLayers
protected void listenToMapLayers(boolean listen)
Listen to the map layers; passing any events on to our own mapListListeners.This method only has an effect if we have any actuall mapListListeners.
- Parameters:
listen- True to connect to all the layers and listen to events
-
removeMapLayerListListener
public void removeMapLayerListListener(MapLayerListListener listener)
Remove interest in receivingLayerListEvent.- Parameters:
listener- The object to stop sendingLayerListEvents.
-
addLayer
public boolean addLayer(Layer layer)
Add a new layer (if not already present).In an interactive setting this will trigger a
LayerListEvent- Returns:
- true if the layer was added
-
addLayers
public int addLayers(Collection<? extends Layer> layers)
Adds all layers from the input collection that are not already present in this map content.- Parameters:
layers- layers to add (may benullor empty)- Returns:
- the number of layers added
-
removeLayer
public boolean removeLayer(Layer layer)
Removes the given layer, if present, and publishes a MapLayerListEvent.- Parameters:
layer- the layer to be removed- Returns:
trueif the layer was removed
-
moveLayer
public void moveLayer(int sourcePosition, int destPosition)Moves a layer in the layer list. Will fire a MapLayerListEvent.- Parameters:
sourcePosition- existing position of the layerdestPosition- new position of the layer
-
layers
public List<Layer> layers()
Gets the list of layers for this map content. The returned list has the following characteristics:- It is "live", ie. changes to its contents will be reflected in this map content.
- It is thread-safe. Accessing list elements directly or via a ListIterator returns a snapshot view of the list contents (as per Java's CopyOnWriteArrayList class).
- Adding a layer to the list, or removing a layer from it, results in a MapLayerListEvent being published by the map content.
- Returns:
- a "live" reference to the layer list for this map content
-
fireLayerAdded
protected void fireLayerAdded(Layer element, int fromIndex, int toIndex)
-
fireLayerRemoved
protected void fireLayerRemoved(Layer element, int fromIndex, int toIndex)
-
fireLayerMoved
protected void fireLayerMoved(Layer element, int toIndex)
-
fireLayerPreDispose
protected void fireLayerPreDispose(Layer element, int toIndex)
-
fireLayerEvent
protected void fireLayerEvent(Layer element, int index, MapLayerEvent layerEvent)
-
getMaxBounds
public ReferencedEnvelope getMaxBounds()
Get the bounding box of all the layers in this Map. If all the layers cannot determine the bounding box in the speed required for each layer, then null is returned. The bounds will be expressed in the Map coordinate system.- Returns:
- The bounding box of the features or null if unknown and too expensive for the method to calculate.
- Throws:
IOException- if an IOException occurs while accessing the FeatureSource bounds
-
getViewport
public MapViewport getViewport()
Viewport describing the area visible on screen.Applications may create multiple viewports (perhaps to render tiles of content); the viewport recorded here is intended for interactive applications where it is helpful to have a single viewport representing what the user is seeing on screen.
With that in mind; if the user has not already supplied a viewport one will be created:
- The viewport will be configured to show the extent of the current layers as provided by
getMaxBounds(). - The viewport will have an empty
MapViewport.getBounds()if no layers have been added yet.
- Returns:
- MapViewport describing how to draw this map
- The viewport will be configured to show the extent of the current layers as provided by
-
setViewport
public void setViewport(MapViewport viewport)
Sets the viewport for this map content. Theviewportargument may benull, in which case a subsequent to getViewport() will return a new instance with default settings.- Parameters:
viewport- the new viewport
-
addMapBoundsListener
public void addMapBoundsListener(MapBoundsListener listener)
Register interest in receivingMapBoundsEvents.- Parameters:
listener- The object to notify when the area of interest has changed.
-
removeMapBoundsListener
public void removeMapBoundsListener(MapBoundsListener listener)
Remove interest in receiving aBoundingBoxEvents.- Parameters:
listener- The object to stop sending change events.
-
getCoordinateReferenceSystem
public CoordinateReferenceSystem getCoordinateReferenceSystem()
The coordinate reference system used for rendering the map.The coordinate reference system used for rendering is often considered to be the "world" coordinate reference system; this is distinct from the coordinate reference system used for each layer (which is often data dependent).
- Returns:
- coordinate reference system used for rendering the map.
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
Registers PropertyChangeListener to receive events.- Parameters:
listener- The listener to register.
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
Removes PropertyChangeListener from the list of listeners.- Parameters:
listener- The listener to remove.
-
getUserData
public Map<String,Object> getUserData()
As an example it can be used to record contact details, map abstract, keywords and so forth for an OGC "Open Web Service Context" document.Modifications to the userData will result in a propertyChange event.
-
getTitle
public String getTitle()
Get the title, returns an empty string if it has not been set yet.- Returns:
- the title, or an empty string if it has not been set.
-
setTitle
public void setTitle(String title)
Set the title of this context.- Parameters:
title- the title.
-
-