Class 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:

    
     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 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.
    • 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

        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:
        • 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.
        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:

        • 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
      • 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.

      • 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)