org.geotools.map
Class MapContent

Object
  extended by MapContent
Direct Known Subclasses:
MapContext, 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:


 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
protected static Logger LOGGER
          The logger for the map module.
protected  MapViewport viewport
          Viewport for map rendering.
 
Constructor Summary
MapContent()
          Creates a new map content.
MapContent(CoordinateReferenceSystem crs)
          Deprecated. 
MapContent(MapContext context)
           
MapContent(MapLayer[] array)
          Deprecated. 
MapContent(MapLayer[] array, CoordinateReferenceSystem crs)
          Deprecated. 
MapContent(MapLayer[] array, String title, String contextAbstract, String contactInformation, String[] keywords)
          Deprecated. 
MapContent(MapLayer[] array, String title, String contextAbstract, String contactInformation, String[] keywords, CoordinateReferenceSystem crs)
          Deprecated. 
 
Method Summary
 boolean addLayer(Layer layer)
          Add a new layer (if not already present).
 int addLayers(Collection<? extends Layer> layers)
          Adds all layers from the input collection that are not already present in this map content.
 void addMapBoundsListener(MapBoundsListener listener)
          Register interest in receiving MapBoundsEvents.
 void addMapLayerListListener(MapLayerListListener listener)
          Register interest in receiving a LayerListEvent.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Registers PropertyChangeListener to receive events.
 void dispose()
          Clean up any listeners or cached state associated with this MapContent.
protected  void finalize()
          Checks that dispose has been called; producing a warning if needed.
protected  void fireLayerAdded(Layer element, int fromIndex, int toIndex)
           
protected  void fireLayerEvent(Layer element, int index, MapLayerEvent layerEvent)
           
protected  void fireLayerMoved(Layer element, int toIndex)
           
protected  void fireLayerPreDispose(Layer element, int toIndex)
           
protected  void fireLayerRemoved(Layer element, int fromIndex, int toIndex)
           
protected  void fireProperty(String propertyName, Object old, Object value)
           
 CoordinateReferenceSystem getCoordinateReferenceSystem()
          The coordinate reference system used for rendering the map.
 ReferencedEnvelope getMaxBounds()
          Get the bounding box of all the layers in this Map.
 String getTitle()
          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.
 MapViewport getViewport()
          Viewport describing the area visible on screen.
 List<Layer> layers()
          Gets the list of layers for this map content.
protected  void listenToMapLayers(boolean listen)
          Listen to the map layers; passing any events on to our own mapListListeners.
 void moveLayer(int sourcePosition, int destPosition)
          Moves a layer in the layer list.
 boolean removeLayer(Layer layer)
          Removes the given layer, if present, and publishes a MapLayerListEvent.
 void removeMapBoundsListener(MapBoundsListener listener)
          Remove interest in receiving a BoundingBoxEvents.
 void removeMapLayerListListener(MapLayerListListener listener)
          Remove interest in receiving LayerListEvent.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes PropertyChangeListener from the list of listeners.
 void setTitle(String title)
          Set the title of this context.
 void setViewport(MapViewport viewport)
          Sets the viewport for this map content.
 
Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.

Constructor Detail

MapContent

public MapContent()
Creates a new map content.


MapContent

public MapContent(MapContext context)

MapContent

@Deprecated
public MapContent(CoordinateReferenceSystem crs)
Deprecated. 


MapContent

@Deprecated
public MapContent(MapLayer[] array)
Deprecated. 


MapContent

@Deprecated
public MapContent(MapLayer[] array,
                             CoordinateReferenceSystem crs)
Deprecated. 


MapContent

@Deprecated
public MapContent(MapLayer[] array,
                             String title,
                             String contextAbstract,
                             String contactInformation,
                             String[] keywords)
Deprecated. 


MapContent

@Deprecated
public MapContent(MapLayer[] array,
                             String title,
                             String contextAbstract,
                             String contactInformation,
                             String[] keywords,
                             CoordinateReferenceSystem crs)
Deprecated. 

Method Detail

finalize

protected void finalize()
                 throws Throwable
Checks that dispose has been called; producing a warning if needed.

Overrides:
finalize in class Object
Throws:
Throwable

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 a LayerListEvent. A LayerListEvent is 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 receiving LayerListEvent.

Parameters:
listener - The object to stop sending LayerListEvents.

addLayer

public boolean addLayer(Layer layer)
Add a new layer (if not already present).

In an interactive setting this will trigger a LayerListEvent

Parameters:
layer -
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 be null or 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:
true if 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 layer
destPosition - 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: For these reasons, you should always work directly with the list returned by this method and avoid making copies since they will not have the above behaviour.

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:

Returns:
MapViewport describing how to draw this map

setViewport

public void setViewport(MapViewport viewport)
Sets the viewport for this map content. The viewport argument may be null, 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 receiving MapBoundsEvents.

Parameters:
listener - The object to notify when the area of interest has changed.

removeMapBoundsListener

public void removeMapBoundsListener(MapBoundsListener listener)
Remove interest in receiving a BoundingBoxEvents.

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.

Returns:

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.

fireProperty

protected void fireProperty(String propertyName,
                            Object old,
                            Object value)


Copyright © 1996-2014 Geotools. All Rights Reserved.