Class MapContent
- Direct Known Subclasses:
SingleLayerMapContent
Methods are provided to add, remove and reorder layers. Alternatively, the list of layers can be accessed directly with the layers(). For example:
mapContent.layers().add( newLayer );
Operations on the list returned by the layers{} method are guaranteed to be thread safe, and modifying the
list contents will result in MapLayerListEvents being 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
FieldsModifier and TypeFieldDescriptionprotected static final LoggerThe logger for the map module.protected MapViewportViewport for map rendering. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd 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.voidRegisters 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) The coordinate reference system used for rendering the map.Get the bounding box of all the layers in this Map.getTitle()Get the title, returns an empty string if it has not been set yet.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.Viewport describing the area visible on screen.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.voidRemove interest in receivingLayerListEvent.voidRemoves PropertyChangeListener from the list of listeners.voidSet the title of this context.voidsetViewport(MapViewport viewport) Sets the viewport for this map content.
-
Field Details
-
LOGGER
The logger for the map module. -
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.
-
-
Constructor Details
-
MapContent
public MapContent()Creates a new map content.
-
-
Method Details
-
finalize
Checks 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
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
Remove interest in receivingLayerListEvent.- Parameters:
listener- The object to stop sendingLayerListEvents.
-
addLayer
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
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
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
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
-
fireLayerRemoved
-
fireLayerMoved
-
fireLayerPreDispose
-
fireLayerEvent
-
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
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
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
Register interest in receivingMapBoundsEvents.- Parameters:
listener- The object to notify when the area of interest has changed.
-
removeMapBoundsListener
Remove interest in receiving aBoundingBoxEvents.- Parameters:
listener- The object to stop sending change events.
-
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
Registers PropertyChangeListener to receive events.- Parameters:
listener- The listener to register.
-
removePropertyChangeListener
Removes PropertyChangeListener from the list of listeners.- Parameters:
listener- The listener to remove.
-
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
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
Set the title of this context.- Parameters:
title- the title.
-
fireProperty
-