org.geotools.map
Class DefaultMapContext

Object
  extended by DefaultMapContext
All Implemented Interfaces:
MapContext
Direct Known Subclasses:
GraphicEnhancedMapContext

public class DefaultMapContext
extends Object
implements MapContext

The default implementation of the MapContext interface

Author:
Andrea Aime
Module:
modules/library/render (gt-render.jar)

Field Summary
protected  String abstracts
          Holds value of property abstracts.
protected  String contactInformation
          Holds value of property contactInformation.
protected  String[] keywords
          Holds value of property keywords.
protected  MapLayerListener layerListener
           
protected  EventListenerList listenerList
          Utility field used by event firing mechanism.
static Logger LOGGER
          The logger for the map module.
protected  PropertyChangeSupport propertyChangeSupport
          Utility field used by bound properties.
protected  String title
          Holds value of property title.
 
Constructor Summary
DefaultMapContext()
          Creates a default empty map context.
DefaultMapContext(CoordinateReferenceSystem crs)
          Creates a default empty map context
DefaultMapContext(MapLayer[] layers)
          Creates a map context with the provided layers.
DefaultMapContext(MapLayer[] layers, CoordinateReferenceSystem crs)
          Creates a map context with the provided layers and coordinate reference system
DefaultMapContext(MapLayer[] layers, String title, String contextAbstract, String contactInformation, String[] keywords)
          Creates a map context Note, the coordinate reference system for the context will be set from that of the first layer with an available CRS.
DefaultMapContext(MapLayer[] layers, String title, String contextAbstract, String contactInformation, String[] keywords, CoordinateReferenceSystem crs)
          Creates a new map context
 
Method Summary
 void addLayer(AbstractGridCoverage2DReader reader, Style style)
          Add a grid coverage data to be supplied by the given reader as a new layer to the end of the list of layers held by this context.
 void addLayer(CollectionSource source, Style style)
          Add the given collection source as a new layer to the end of the list of layers held by this context and trigger a MapLayerListEvent.
 void addLayer(Collection collection, Style style)
          Add the given collection as a new layer to the end of the list of layers held by this context and trigger a MapLayerListEvent.
 void addLayer(FeatureCollection<SimpleFeatureType,SimpleFeature> collection, Style style)
          Add the given feature collection as a new layer to the end of the list of layers held by this context and trigger a MapLayerListEvent.
 void addLayer(FeatureSource<SimpleFeatureType,SimpleFeature> featureSource, Style style)
          Add the given feature source as a new layer to the end of the list of layers held by this context and trigger a MapLayerListEvent.
 void addLayer(GridCoverage gc, Style style)
          Add a grid coverage as a new layer to the end of the list of layers held by this context.
 boolean addLayer(int index, MapLayer layer)
          Add a new layer if not already present and trigger a MapLayerListEvent.
 boolean addLayer(MapLayer layer)
          Add a new layer, if not already present, to the end of the list of layers held by this context and trigger a MapLayerListEvent If a coordinate reference system has not been set for the context an attempt is made to retrieve one from the new layer and use that as the context's CRS.
 int addLayers(MapLayer[] layers)
          Add an array of new layers to this context and trigger a MapLayerListEvent.
 void addMapBoundsListener(MapBoundsListener listener)
          Registers MapBoundsListener to receive events.
 void addMapLayerListListener(MapLayerListListener listener)
          Registers MapLayerListListener to receive events.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Registers PropertyChangeListener to receive events.
 void clearLayerList()
          Remove all of the map layers from this context.
 String getAbstract()
          Getter for property abstracts.
 ReferencedEnvelope getAreaOfInterest()
          Gets the current area of interest.
 String getContactInformation()
          Getter for property contactInformation.
 CoordinateReferenceSystem getCoordinateReferenceSystem()
          Get the current coordinate system of this context
 String[] getKeywords()
          Getter for property keywords.
 MapLayer getLayer(int index)
          Return the requested layer.
 ReferencedEnvelope getLayerBounds()
          Get the bounding box of all the layers in this MapContext.
 int getLayerCount()
          Returns the number of layers in this map context
 MapLayer[] getLayers()
          Return this model's list of layers.
 String getTitle()
          Getter for property title.
 int indexOf(MapLayer layer)
          Returns the index of the first occurrence of the specified layer, or -1 if this list does not contain this element.
 Iterator iterator()
          Returns an iterator over the layers in this context in proper sequence.
 void moveLayer(int sourcePosition, int destPosition)
          Change the position of a layer in this context's list of map layers.
 MapLayer removeLayer(int index)
          Remove the layer at the given position in the list of layers held by this context.
 boolean removeLayer(MapLayer layer)
          Remove the given layer from this context, if present, and trigger a MapLayerListEvent
 void removeLayers(MapLayer[] layers)
          Remove an array of layers, if present, and trigger a MapLayerListEvent.
 void removeMapBoundsListener(MapBoundsListener listener)
          Removes MapBoundsListener from the list of listeners.
 void removeMapLayerListListener(MapLayerListListener listener)
          Removes MapLayerListListener from the list of listeners.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes PropertyChangeListener from the list of listeners.
 void setAbstract(String abstractValue)
          Setter for property abstracts.
 void setAreaOfInterest(Envelope areaOfInterest)
          Deprecated. Use of this method is not safe. Please use setAreaOfInterest(Envelope, CoordinateReferenceSystem) instead.
 void setAreaOfInterest(Envelope areaOfInterest, CoordinateReferenceSystem crs)
          Set the area of interest.
 void setAreaOfInterest(ReferencedEnvelope areaOfInterest)
          Set the area of interest.
 void setContactInformation(String contactInformation)
          Setter for property contactInformation.
 void setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
          Set or change the coordinate reference system for this context.
 void setKeywords(String[] keywords)
          Setter for property keywords.
 void setTitle(String title)
          Setter for property title.
 void transform(AffineTransform transform)
          Transform the current area of interest for this context using the provided transform.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

public static final Logger LOGGER
The logger for the map module.


listenerList

protected EventListenerList listenerList
Utility field used by event firing mechanism.


layerListener

protected MapLayerListener layerListener

abstracts

protected String abstracts
Holds value of property abstracts.


propertyChangeSupport

protected PropertyChangeSupport propertyChangeSupport
Utility field used by bound properties.


contactInformation

protected String contactInformation
Holds value of property contactInformation.


keywords

protected String[] keywords
Holds value of property keywords.


title

protected String title
Holds value of property title.

Constructor Detail

DefaultMapContext

public DefaultMapContext()
Creates a default empty map context. The coordinate reference system for the map context should be set explicitly, or implicitly via addLayer prior to using the context.


DefaultMapContext

public DefaultMapContext(CoordinateReferenceSystem crs)
Creates a default empty map context

Parameters:
crs - the coordindate reference system to be used with this context (may be null and set later)

DefaultMapContext

public DefaultMapContext(MapLayer[] layers)
Creates a map context with the provided layers.

Note, the coordinate reference system for the context will be set from that of the first layer with an available CRS.

Parameters:
layers - an array of MapLayer objects (may be empty or null) to be added to this context

DefaultMapContext

public DefaultMapContext(MapLayer[] layers,
                         CoordinateReferenceSystem crs)
Creates a map context with the provided layers and coordinate reference system

Parameters:
layers - an array of MapLayer objects (may be empty or null) to be added to this context
crs - the coordindate reference system to be used with this context (may be null and set later)

DefaultMapContext

public DefaultMapContext(MapLayer[] layers,
                         String title,
                         String contextAbstract,
                         String contactInformation,
                         String[] keywords)
Creates a map context

Note, the coordinate reference system for the context will be set from that of the first layer with an available CRS.

Parameters:
layers - an array of MapLayer objects (may be empty or null) to be added to this context
title - a title for this context (e.g. might be used by client-code that is displaying the context's layers); may be null or an empty string
contextAbstract - a short description of the context and its contents; may be null or an empty string
contactInformation - can be used, for example, to record the creators or custodians of the data that are, or will be, held by this context; may be null or an empty string
keywords - an optional array of key words pertaining to the data that are, or will be, held by this context; may be null or a zero-length String array

DefaultMapContext

public DefaultMapContext(MapLayer[] layers,
                         String title,
                         String contextAbstract,
                         String contactInformation,
                         String[] keywords,
                         CoordinateReferenceSystem crs)
Creates a new map context

Parameters:
layers - an array of MapLayer objects (may be empty or null) to be added to this context
title - a title for this context (e.g. might be used by client-code that is displaying the context's layers); may be null or an empty string
contextAbstract - a short description of the context and its contents; may be null or an empty string
contactInformation - can be used, for example, to record the creators or custodians of the data that are, or will be, held by this context; may be null or an empty string
keywords - an optional array of key words pertaining to the data that are, or will be, held by this context; may be null or a zero-length String array
crs - the coordindate reference system to be used with this context (may be null and set later)
Method Detail

addLayer

public boolean addLayer(int index,
                        MapLayer layer)
Add a new layer if not already present and trigger a MapLayerListEvent. If a coordinate reference system has not been set for the context an attempt is made to retrieve one from the new layer and use that as the context's CRS.

Specified by:
addLayer in interface MapContext
Parameters:
index - the position at which to insert the layer in the list of layers held by this context
layer - the map layer to add
Returns:
true if the layer was added; false otherwise (layer was already present)

addLayer

public boolean addLayer(MapLayer layer)
Add a new layer, if not already present, to the end of the list of layers held by this context and trigger a MapLayerListEvent If a coordinate reference system has not been set for the context an attempt is made to retrieve one from the new layer and use that as the context's CRS.

Specified by:
addLayer in interface MapContext
Parameters:
layer - the map layer to add
Returns:
true if the layer was added; false otherwise (layer was already present)

addLayer

public void addLayer(FeatureSource<SimpleFeatureType,SimpleFeature> featureSource,
                     Style style)
Add the given feature source as a new layer to the end of the list of layers held by this context and trigger a MapLayerListEvent. This is a convenience method equivalent to addLayer(int, org.geotools.map.MapLayer)(new DefaultMapLayer(featureSource, style).

If a coordinate reference system has not been set for the context an attempt is made to retrieve one from the new layer and use that as the context's CRS.

If style is null, a default style is created using SLD.createSimpleStyle(org.opengis.feature.simple.SimpleFeatureType).

Specified by:
addLayer in interface MapContext
Parameters:
featureSource - the source of the features for the new layer
style - a Style object to be used in rendering this layer.

addLayer

public void addLayer(CollectionSource source,
                     Style style)
Add the given collection source as a new layer to the end of the list of layers held by this context and trigger a MapLayerListEvent. This is a convenience method equivalent to addLayer(int, org.geotools.map.MapLayer)(new DefaultMapLayer(source, style).

If a coordinate reference system has not been set for the context an attempt is made to retrieve one from the new layer and use that as the context's CRS.

Parameters:
source - the source of the features for the new layer
style - a Style object to be used in rendering this layer

addLayer

public void addLayer(GridCoverage gc,
                     Style style)
Add a grid coverage as a new layer to the end of the list of layers held by this context.

If a coordinate reference system has not been set for the context an attempt is made to retrieve one from the grid coverage and use that as the context's CRS.

Specified by:
addLayer in interface MapContext
Parameters:
gc - the grid coverage
style - a Style to be used when rendering the new layer

addLayer

public void addLayer(AbstractGridCoverage2DReader reader,
                     Style style)
Add a grid coverage data to be supplied by the given reader as a new layer to the end of the list of layers held by this context.

If a coordinate reference system has not been set for the context an attempt is made to retrieve one from the reader and use that as the context's CRS.

Specified by:
addLayer in interface MapContext
Parameters:
reader - the grid coverage reader
style - a Style to be used when rendering the new layer

addLayer

public void addLayer(FeatureCollection<SimpleFeatureType,SimpleFeature> collection,
                     Style style)
Add the given feature collection as a new layer to the end of the list of layers held by this context and trigger a MapLayerListEvent. This is a convenience method equivalent to addLayer(int, org.geotools.map.MapLayer)(new DefaultMapLayer(collection, style).

Specified by:
addLayer in interface MapContext
Parameters:
collection - the collection of features for the new layer
style - a Style object to be used in rendering this layer

addLayer

public void addLayer(Collection collection,
                     Style style)
Add the given collection as a new layer to the end of the list of layers held by this context and trigger a MapLayerListEvent. This is a convenience method equivalent to addLayer(int, org.geotools.map.MapLayer)(new DefaultMapLayer(collection, style).

Specified by:
addLayer in interface MapContext
Parameters:
collection - the collection of features for the new layer
style - a Style object to be used in rendering this layer

removeLayer

public boolean removeLayer(MapLayer layer)
Remove the given layer from this context, if present, and trigger a MapLayerListEvent

Specified by:
removeLayer in interface MapContext
Parameters:
layer - the layer to be removed
Returns:
true if the layer was present; false otherwise

removeLayer

public MapLayer removeLayer(int index)
Remove the layer at the given position in the list of layers held by this context. The position must be valid or an IndexOutOfBoundsException will result. CAlling this method triggers a MapLayerListEvent.

Specified by:
removeLayer in interface MapContext
Parameters:
index - the position of the layer in this context's list of layers
Returns:
the layer that was removed

addLayers

public int addLayers(MapLayer[] layers)
Add an array of new layers to this context and trigger a MapLayerListEvent.

Specified by:
addLayers in interface MapContext
Parameters:
layers - the new layers that are to be added.
Returns:
the number of new layers actually added (will be less than the length of the layers array if some layers were already present)

removeLayers

public void removeLayers(MapLayer[] layers)
Remove an array of layers, if present, and trigger a MapLayerListEvent.

Specified by:
removeLayers in interface MapContext
Parameters:
layers - The layers that are to be removed.

getLayers

public MapLayer[] getLayers()
Return this model's list of layers. If no layers are present, then an empty array is returned.

Specified by:
getLayers in interface MapContext
Returns:
This model's list of layers.

getLayer

public MapLayer getLayer(int index)
                  throws IndexOutOfBoundsException
Return the requested layer.

Specified by:
getLayer in interface MapContext
Parameters:
index - index of layer to return.
Returns:
the layer at the specified position
Throws:
IndexOutOfBoundsException - if the index is out of range

indexOf

public int indexOf(MapLayer layer)
Description copied from interface: MapContext
Returns the index of the first occurrence of the specified layer, or -1 if this list does not contain this element.

Specified by:
indexOf in interface MapContext
Parameters:
layer - the MapLayer to search for
Returns:
DOCUMENT ME!
See Also:
MapContext.indexOf(org.geotools.map.MapLayer)

iterator

public Iterator iterator()
Returns an iterator over the layers in this context in proper sequence.

Specified by:
iterator in interface MapContext
Returns:
an iterator over the layers in this context in proper sequence.

getLayerBounds

public ReferencedEnvelope getLayerBounds()
                                  throws IOException
Get the bounding box of all the layers in this MapContext. 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 MapContext coordinate system.

Specified by:
getLayerBounds in interface MapContext
Returns:
The bounding box of the features or null if unknown and too expensive for the method to calculate. TODO: when coordinate system information will be added reproject the bounds according to the current coordinate system
Throws:
IOException - DOCUMENT ME!

getAreaOfInterest

public ReferencedEnvelope getAreaOfInterest()
Gets the current area of interest. If no area of interest is set, the default is to fall back on the layer bounds

Specified by:
getAreaOfInterest in interface MapContext
Returns:
Current area of interest

getCoordinateReferenceSystem

public CoordinateReferenceSystem getCoordinateReferenceSystem()
Get the current coordinate system of this context

Specified by:
getCoordinateReferenceSystem in interface MapContext
Returns:
the coordinate system (may be null)

transform

public void transform(AffineTransform transform)
Transform the current area of interest for this context using the provided transform. This may be useful for zooming and panning processes.

Specified by:
transform in interface MapContext
Parameters:
transform - The transform to change area of interest.

moveLayer

public void moveLayer(int sourcePosition,
                      int destPosition)
Change the position of a layer in this context's list of map layers. This triggers a MapLayerList event.

Specified by:
moveLayer in interface MapContext
Parameters:
sourcePosition - the layer's current position
destPosition - the new position
Throws:
IndexOutOfBoundsException - if either position is less than zero or not less than the number of layers.

clearLayerList

public void clearLayerList()
Remove all of the map layers from this context. This triggers a MapLayerListEvent.

Specified by:
clearLayerList in interface MapContext

getLayerCount

public int getLayerCount()
Returns the number of layers in this map context

Specified by:
getLayerCount in interface MapContext
Returns:
the number of layers in this map context

getAbstract

public String getAbstract()
Getter for property abstracts.

Specified by:
getAbstract in interface MapContext
Returns:
Value of property abstracts.

setAbstract

public void setAbstract(String abstractValue)
Setter for property abstracts.

Specified by:
setAbstract in interface MapContext
Parameters:
abstractValue - New value of property abstracts.

getContactInformation

public String getContactInformation()
Getter for property contactInformation.

Specified by:
getContactInformation in interface MapContext
Returns:
Value of property contactInformation.

setContactInformation

public void setContactInformation(String contactInformation)
Setter for property contactInformation.

Specified by:
setContactInformation in interface MapContext
Parameters:
contactInformation - New value of property contactInformation.

getKeywords

public String[] getKeywords()
Getter for property keywords.

Specified by:
getKeywords in interface MapContext
Returns:
Value of property keywords.

setKeywords

public void setKeywords(String[] keywords)
Setter for property keywords.

Specified by:
setKeywords in interface MapContext
Parameters:
keywords - New value of property keywords.

getTitle

public String getTitle()
Getter for property title.

Specified by:
getTitle in interface MapContext
Returns:
Value of property title.

setTitle

public void setTitle(String title)
Setter for property title.

Specified by:
setTitle in interface MapContext
Parameters:
title - New value of property title.

addMapLayerListListener

public void addMapLayerListListener(MapLayerListListener listener)
Registers MapLayerListListener to receive events.

Specified by:
addMapLayerListListener in interface MapContext
Parameters:
listener - The listener to register.

removeMapLayerListListener

public void removeMapLayerListListener(MapLayerListListener listener)
Removes MapLayerListListener from the list of listeners.

Specified by:
removeMapLayerListListener in interface MapContext
Parameters:
listener - The listener to remove.

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Registers PropertyChangeListener to receive events.

Specified by:
addPropertyChangeListener in interface MapContext
Parameters:
listener - The listener to register.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes PropertyChangeListener from the list of listeners.

Specified by:
removePropertyChangeListener in interface MapContext
Parameters:
listener - The listener to remove.

addMapBoundsListener

public void addMapBoundsListener(MapBoundsListener listener)
Registers MapBoundsListener to receive events.

Specified by:
addMapBoundsListener in interface MapContext
Parameters:
listener - The listener to register.

removeMapBoundsListener

public void removeMapBoundsListener(MapBoundsListener listener)
Removes MapBoundsListener from the list of listeners.

Specified by:
removeMapBoundsListener in interface MapContext
Parameters:
listener - The listener to remove.

setAreaOfInterest

public void setAreaOfInterest(Envelope areaOfInterest)
                       throws IllegalArgumentException
Deprecated. Use of this method is not safe. Please use setAreaOfInterest(Envelope, CoordinateReferenceSystem) instead.

Set the area of interest. This triggers a MapBoundsEvent to be published.

Specified by:
setAreaOfInterest in interface MapContext
Parameters:
areaOfInterest - the new area of interest
Throws:
IllegalArgumentException - if the argument is null

setAreaOfInterest

public void setAreaOfInterest(Envelope areaOfInterest,
                              CoordinateReferenceSystem crs)
                       throws IllegalArgumentException
Set the area of interest. This triggers a MapBoundsEvent to be published.

Specified by:
setAreaOfInterest in interface MapContext
Parameters:
areaOfInterest - the new area of interest
coordinateReferenceSystem - the CRS for the new area of interest
Throws:
IllegalArgumentException - if areaOfInterest is null

setAreaOfInterest

public void setAreaOfInterest(ReferencedEnvelope areaOfInterest)
Set the area of interest. This triggers a MapBoundsEvent to be published.

Specified by:
setAreaOfInterest in interface MapContext
Parameters:
areaOfInterest - the new area of interest
Throws:
IllegalArgumentException - if the provided areaOfInterest is null or does not have a coordinate reference system

setCoordinateReferenceSystem

public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
                                  throws TransformException,
                                         FactoryException
Set or change the coordinate reference system for this context. This will trigger a MapBoundsEvent to be published to listeners.

Specified by:
setCoordinateReferenceSystem in interface MapContext
Throws:
FactoryException
TransformException


Copyright © 1996-2009 Geotools. All Rights Reserved.