Class MapContext

java.lang.Object
org.gvsig.tools.dispose.impl.AbstractDisposable
org.gvsig.fmap.mapcontext.MapContext
All Implemented Interfaces:
Iterable<FLayer>, Projected, org.gvsig.tools.dispose.Disposable, org.gvsig.tools.observer.Observer, org.gvsig.tools.persistence.Persistent

public class MapContext extends org.gvsig.tools.dispose.impl.AbstractDisposable implements Projected, org.gvsig.tools.persistence.Persistent, org.gvsig.tools.observer.Observer, Iterable<FLayer>

The MapContext class represents the model and a part of the control and view around graphical layers used by

invalid reference
MapControl
.

An instance of MapContext is made up with:

  • Field Details

    • CHANGEM

      public static final double[] CHANGEM
    • AREANAMES

      public static ArrayList AREANAMES
    • AREAABBR

      public static ArrayList AREAABBR
    • AREATRANS2METER

      public static ArrayList AREATRANS2METER
    • DISTANCENAMES

      public static ArrayList DISTANCENAMES
    • DISTANCEABBR

      public static ArrayList DISTANCEABBR
    • DISTANCETRANS2METER

      public static ArrayList DISTANCETRANS2METER
    • DEFAULT_SELECTION_COLOR

      public static final Color DEFAULT_SELECTION_COLOR
    • CHANGE

      public static final double[] CHANGE

      Defines the value which a unit of a distance measurement must be divided to obtain its equivalent in centimeters.

      Conversion values of distance measurements:

      • MapContext.CHANGE[0]: kilometer
      • MapContext.CHANGE[1]: meter
      • MapContext.CHANGE[2]: centimeter
      • MapContext.CHANGE[3]: millimeter
      • MapContext.CHANGE[4]: international statute mile
      • MapContext.CHANGE[5]: yard
      • MapContext.CHANGE[6]: foot
      • MapContext.CHANGE[7]: inch
      • MapContext.CHANGE[8]: grade

      Examples:

      1 international statute mile / MapContext.CHANGE[4] = X centimeters
      1 kilometer / MapContext.CHANGE[0] = X centimeters
      1 grade / MapContext.CHANGE[8] = X centimeters

      Grade conversion value: MapContext.CHANGE[8]

      The value of MapContext.CHANGE[8] represents the centimeters of a straight line between two points on the Earth surface that are 1 grade far each other of the center of the Earth. This value has been calculated using a radius approximated of REarth=6.37846082678100774672e6 meters, according these equations:
      D = 2 * (sin (1)) * REarth
      MapContext.CHANGE[8] = 1 / D

      Explanation:

      We get an isosceles triangle with the center of the Earth and the 2 points on the surface. This triangle can be divided into two rectangle triangles. We know two values, the angle of 1 grade, that will be 0.50 grades in each triangle, and the Earth radius that is the hypotenuse. Then we apply trigonometry and get the distance D between both points on the Earth surface.

      Now we only must invert that value to obtain MapContext.CHANGE[8].

    • EQUALS

      public static final int EQUALS
      See Also:
    • DISJOINT

      public static final int DISJOINT
      See Also:
    • INTERSECTS

      public static final int INTERSECTS
      See Also:
    • TOUCHES

      public static final int TOUCHES
      See Also:
    • CROSSES

      public static final int CROSSES
      See Also:
    • WITHIN

      public static final int WITHIN
      See Also:
    • CONTAINS

      public static final int CONTAINS
      See Also:
    • OVERLAPS

      public static final int OVERLAPS
      See Also:
    • layers

      protected FLayers layers
      A hierarchy of FLayers nodes.
    • ZOOMINFACTOR

      public static double ZOOMINFACTOR

      Default zoom in factor.

      Doing a zoom in operation, decreases the focal distance and increases the eyesight angle to the surface. This allows view an smaller area but with the items bigger.

    • ZOOMOUTFACTOR

      public static double ZOOMOUTFACTOR

      Default zoom out factor.

      Doing a zoom out operation, increases the focal distance and decreases the eyesight angle to the surface. This allows view a bigger area but with the items smaller.

  • Constructor Details

    • MapContext

      public MapContext(ViewPort vp)

      Creates a new map context with the drawing information defined in the view port argument, and without layers.

      Parameters:
      vp - information for drawing the layers of this map in the available rectangular area according a projection
    • MapContext

      public MapContext()
    • MapContext

      public MapContext(FLayers fLayers, ViewPort vp)

      Creates a new map context with the layers and the drawing information defined in the view port arguments.

      Parameters:
      fLayers - the initial hierarchy of nodes of layers that this map will have
      vp - information for drawing the layers of this map in the available rectangular area according a projection
  • Method Details

    • getDrawFrameRate

      public static int getDrawFrameRate()

      Returns the draw frame rate.

      Draw frame rate is the number of repaints of this MapControl instance that timer invokes per second.

      Returns:
      number of repaints of this MapControl instance that timer invokes per second
      See Also:
    • setDrawFrameRate

      public static void setDrawFrameRate(int theDrawFrameRate)

      Sets the draw frame rate.

      Draw frame rate is the number of repaints of this MapControl instance that timer invokes per second.

      Parameters:
      theDrawFrameRate - number of repaints of this MapControl instance that timer invokes per second
      See Also:
    • addAreaUnit

      public static void addAreaUnit(String name, String abbr, boolean isLinear, double trans2meter)
    • getAreaNames

      public static String[] getAreaNames()
    • getAreaAbbr

      public static String[] getAreaAbbr()
    • getAreaTrans2Meter

      public static double[] getAreaTrans2Meter()
    • getOfLinear

      public static String getOfLinear(int i)
    • addDistanceUnit

      public static void addDistanceUnit(String name, String abbr, double trans2meter)
    • getDistanceNames

      public static String[] getDistanceNames()
    • getDistanceName

      public String getDistanceName()
    • getDistanceAbbr

      public static String[] getDistanceAbbr()
    • getDistanceTrans2Meter

      public static double[] getDistanceTrans2Meter()
    • getDistancePosition

      public static int getDistancePosition(String s)
    • getSelectionColor

      public Color getSelectionColor()

      Gets the color used to represent the selections.

      Returns:
      color used to represent the selections
    • setSelectionColor

      public void setSelectionColor(Color selectionColor)

      Sets the color used to represent the selections.

      Parameters:
      selectionColor - color used to represent the selections
    • reportDriverExceptions

      public void reportDriverExceptions(String introductoryText, List driverExceptions)

      Reports to all driver error listeners registered of a bundle of driver exceptions caused in the same map atomic transaction.

      Parameters:
      introductoryText - introductory text specified by developer. If null, use ""
      driverExceptions - list with a bundle of driver exceptions caught during an atomic event
      See Also:
    • addLayerListener

      public void addLayerListener(LegendListener listener)

      Adds the specified legend listener (if didn't exist) to receive legend events from this map.

      Parameters:
      listener - the legend listener
      See Also:
    • addLegendListener

      public void addLegendListener(LegendListener listener)

      Adds the specified legend listener (if didn't exist) to receive legend events from this map.

      Parameters:
      listener - the legend listener
      See Also:
    • getLegendListeners

      public List getLegendListeners()
    • addLayerDrawingListener

      public void addLayerDrawingListener(LayerDrawingListener listener)

      Adds the specified layer drawing listener to catch and handle drawing events from layers of this map.

      Parameters:
      listener - the listener to add
      See Also:
    • getLayerDrawingListeners

      public List getLayerDrawingListeners()
    • removeLayerDrawListener

      public void removeLayerDrawListener(LayerDrawingListener listener)

      Removes the specified layer drawing listener from this map.

      Parameters:
      listener - the listener to remove
      See Also:
    • addErrorListener

      public void addErrorListener(ErrorListener listener)

      Adds the specified error listener to receive error events from this map.

      Parameters:
      listener - the listener to add
      See Also:
    • getErrorListeners

      public List getErrorListeners()
    • removeErrorListener

      public void removeErrorListener(LegendListener listener)

      Removes the specified error listener from this map.

      Parameters:
      listener - the listener to remove
      See Also:
    • callLegendChanged

      public void callLegendChanged()
      Notifies to all legend listeners registered, that one legend has changed. This method must be called only if it's wanted to reflect a legend change.
      See Also:
    • fireLayerDrawingEvent

      public void fireLayerDrawingEvent(LayerDrawEvent e)

      Fires a layer drawing event to all LayerDrawingListener listeners registered, distinguishing the kind of event.

      Parameters:
      e - the event
      See Also:
    • callNewErrorEvent

      public void callNewErrorEvent(ErrorEvent e)

      Notifies to all error listeners registered, that one error has been produced.

      Parameters:
      e - the event with information of the error
      See Also:
    • removeLayerListener

      public void removeLayerListener(LegendListener listener)

      Removes the specified layer listener from this map.

      Parameters:
      listener - the listener to remove
      See Also:
    • getLayers

      public FLayers getLayers()

      Returns the hierarchy of FLayers nodes stored in this map.

      Returns:
      the hierarchy of nodes of layers stored in this map
    • drawLabels

      public void drawLabels(BufferedImage b)

      Draws the visible layers of this map according its view port, on the image parameter.

      Parameters:
      b - image with an accessible buffer of image data
    • invalidate

      public void invalidate()
      See Also:
      • invalid reference
        #redraw()
    • print

      public void print(Graphics2D g, double scale, org.gvsig.compat.print.PrintAttributes properties) throws org.gvsig.fmap.dal.exception.ReadException, MapContextException

      Prints the layers of this map using the Graphics2D argument, that usually is the Graphics of the printer.

      Parameters:
      g - for rendering 2-dimensional shapes, text and images on the Java(tm) platform
      scale - the scale of the view. Must be between FLayer.getMinScale() and FLayer.getMaxScale().
      properties - a set with the settings to be applied to a whole print job and to all the documents in the print job
      See Also:
    • createNewFMap

      public MapContext createNewFMap(ViewPort vp)

      Returns a new MapContext instance with the information of the vp argument, and the layers of this map.

      Parameters:
      vp - information for drawing the layers of this map in the available rectangular area according a projection
      Returns:
      a new MapContext instance projected by vp
    • cloneFMap

      public MapContext cloneFMap()

      Creates a new independent MapContext instance, that has a clone of the layers and the view port of this one.

      The new map will have the same data source drivers to avoid waste memory, and work faster.

      Returns:
      the new MapContext instance
      See Also:
    • cloneToDraw

      public MapContext cloneToDraw()
      Like cloneFMap(), but now doesn't clone the layers, rather copies them.
      Returns:
      the new map
    • addToTrackLayer

      public void addToTrackLayer(FLayer vectorial)

      Adds a layer to the group of layers that are at a upper level in the tree.

      Parameters:
      vectorial - the layer to add
    • getScaleView

      public double getScaleView()

      Returns the scale of the view in the screen.

      Returns:
      one of this values:
      • the scale of the adjusted extent scale of the view in the screen
      • -1 if there is no image
      • 0 if there is no extent defined for the image
      See Also:
    • setScaleView

      public void setScaleView(double scale)

      Sets the new extent of the view, calculated using the scale argument.

      Doesn't updates the scale if there isn't information about the dimension of the image or the adjusted extent.

      Parameters:
      scale - the new scale for the view
      See Also:
    • getExtent

      public Rectangle2D getExtent(Rectangle2D extent, double scale, double wImage, double hImage, double mapUnits, double distanceUnits, double dpi)
    • toGeo

      public Point2D toGeo(Point2D p) throws org.gvsig.crs.projection.lib.ProjectionException
      Throws:
      org.gvsig.crs.projection.lib.ProjectionException
    • getScreenDPI

      public static double getScreenDPI()

      Returns the screen resolution (Dots Per Inch) as it was defined by the user's preference, or by default as it is defined in the default Toolkit.

      Be care, use ViewPort#getDPI to ensure are using the corrects DPI.
      Returns:
      double with the screen's dpi
    • process

      public void process(org.gvsig.tools.visitor.Visitor visitor)
      See Also:
      • invalid reference
        org.gvsig.fmap.mapcontext.rendering.strategies.Strategy#process(com.iver.cit.gvsig.fmap.FeatureSelectorVisitor)
    • processSelected

      public void processSelected(org.gvsig.tools.visitor.Visitor visitor)
      See Also:
      • invalid reference
        org.gvsig.fmap.mapcontext.rendering.strategies.Strategy#processSelected(com.iver.cit.gvsig.fmap.FeatureVisitor)
    • select

      public void select(org.gvsig.tools.visitor.Visitor visitor)
      See Also:
      • invalid reference
        org.gvsig.fmap.mapcontext.rendering.strategies.Strategy#select(com.iver.cit.gvsig.fmap.FeatureSelectorVisitor, VectorialSubSet)
    • selectFromSelection

      public void selectFromSelection()
      See Also:
      • invalid reference
        org.gvsig.fmap.mapcontext.rendering.strategies.Strategy#selectFromSelection()
    • createIndex

      public void createIndex()
      See Also:
      • invalid reference
        org.gvsig.fmap.mapcontext.rendering.strategies.Strategy#createIndex()
    • getProjection

      public org.gvsig.crs.projection.lib.Projection getProjection()
      Description copied from interface: Projected

      Returns the current projection.

      Specified by:
      getProjection in interface Projected
      Returns:
      current projection
      See Also:
    • setProjection

      public void setProjection(org.gvsig.crs.projection.lib.Projection proj)

      Sets the new projection.

      Parameters:
      proj - the new projection
      See Also:
    • reProject

      public void reProject(org.gvsig.crs.projection.lib.CoordinateTransformation arg0)
      Description copied from interface: Projected

      Changes projection of the graphical information of this object.

      Specified by:
      reProject in interface Projected
      Parameters:
      arg0 - transformation coordinates for obtaining the new projection
      See Also:
      • invalid reference
        org.cresques.geo.Projected#reProject(org.cresques.cts.CoordinateTransformation)
    • getSelectionBounds

      public org.gvsig.fmap.geom.primitive.Envelope getSelectionBounds() throws org.gvsig.tools.exception.BaseException
      Throws:
      org.gvsig.tools.exception.BaseException
    • draw

      public void draw(BufferedImage image, Graphics2D g, org.gvsig.tools.task.Cancellable cancel, double scale) throws org.gvsig.fmap.dal.exception.ReadException, MapContextException

      Draws this map if its ViewPort has an extent defined:

      1. Selects only the layers that have to be drawn:
        invalid reference
        #prepareDrawing(BufferedImage, Graphics2D, double)
        .
      2. Sets quality: antialiasing by text and images, and quality rendering.
      3. Draws the layers.
      4. Fires a LayerDrawEvent.GRAPHICLAYER_BEFORE_DRAW.
      5. Draws the graphic layer.
      6. Fires a LayerDrawEvent.GRAPHICLAYER_AFTER_DRAW.
      7. Invokes the garbage collector and memory clean.

      Parameters:
      image - buffer used sometimes instead g to accelerate the draw. For example, if two points are as closed that can't be distinguished, draws only one.
      g - for rendering 2-dimensional shapes, text and images on the Java(tm) platform
      cancel - shared object that determines if this layer can continue being drawn
      scale - the scale of the view. Must be between FLayer.getMinScale() and FLayer.getMaxScale().
    • drawGraphics

      public void drawGraphics(BufferedImage image, Graphics2D g, org.gvsig.tools.task.Cancellable cancel, double scale) throws org.gvsig.fmap.dal.exception.ReadException

      Draws only the internal graphic layer using the information of the ViewPort of this map.

      Parameters:
      image - image used to accelerate the screen draw
      g - for rendering 2-dimensional shapes, text and images on the Java(tm) platform
      cancel - shared object that determines if this layer can continue being drawn
      scale - value that represents the scale
      See Also:
    • draw

      public void draw(BufferedImage image, Graphics2D g, double scale) throws org.gvsig.fmap.dal.exception.ReadException, MapContextException

      Like draw(BufferedImage, Graphics2D, Cancellable, double) , but creating the task as cancellable.

      Parameters:
      image - buffer used sometimes instead g to accelerate the draw. For example, if two points are as closed that can't be distinguished, draws only one.
      g - for rendering 2-dimensional shapes, text and images on the Java(tm) platform
      scale - the scale of the view. Must be between FLayer.getMinScale() and FLayer.getMaxScale().
      See Also:
    • getViewPort

      public ViewPort getViewPort()

      Gets the ViewPort associated to this map.

      Returns:
      the view port
      See Also:
    • setViewPort

      public void setViewPort(ViewPort viewPort)

      Sets a ViewPort with the drawing information of this map.

      If there was a previous view port, removes its EventBuffer and adds the new one.

      Parameters:
      viewPort - the viewPort
      See Also:
    • zoomToEnvelope

      public void zoomToEnvelope(org.gvsig.fmap.geom.primitive.Envelope env)

      Sets the given extent to the ViewPort and updates the view with the new zoom.

      Parameters:
      extent - the extent of the new zoom
    • getFullEnvelope

      public org.gvsig.fmap.geom.primitive.Envelope getFullEnvelope() throws org.gvsig.fmap.dal.exception.ReadException

      Returns the union of all extents of all layers of this map.

      Returns:
      full extent of layers of this map
      See Also:
    • addAtomicEventListener

      public boolean addAtomicEventListener(AtomicEventListener listener)

      Adds a listener of atomic events to the internal EventBuffer.

      Parameters:
      listener - the new listener
      Returns:
      true if has added the listener successfully
      See Also:
    • getAtomicEventListeners

      public List getAtomicEventListeners()
    • removeAtomicEventListener

      public boolean removeAtomicEventListener(AtomicEventListener listener)

      Removes a listener of atomic events from the internal EventBuffer.

      Parameters:
      listener - the listener to remove
      Returns:
      true if the list contained the specified element
      See Also:
    • beginAtomicEvent

      public void beginAtomicEvent()
      See Also:
    • endAtomicEvent

      public void endAtomicEvent()
      See Also:
    • addAsCollectionListener

      public void addAsCollectionListener(FLayers layers2)

      Adds the LayerEventListener of this map to the collection of layers argument.

      Parameters:
      a - collection of layers
    • getGraphicsLayer

      public VectorLayer getGraphicsLayer(String name)
    • getGraphicsLayers

      public Collection<VectorLayer> getGraphicsLayers()
    • setGraphicsLayer

      public void setGraphicsLayer(String name, FLyrVect layer)
    • removeGraphicsLayer

      public void removeGraphicsLayer(String name)
    • getGraphicsLayer

      public GraphicLayer getGraphicsLayer()

      Returns the internal GraphicLayer.

      Returns:
      the graphic layer of this map
      See Also:
    • setGraphicsLayer

      public void setGraphicsLayer(GraphicLayer graphicLayer)

      Sets a new GraphicLayer to this map.

      Parameters:
      graphicLayer - the new graphic layer
      See Also:
    • equals

      public boolean equals(Object arg0)

      Indicates whether some other object is "equal to" this map.

      Returns true if success one of this options:

      • Both objects are equal according to Object.equals(Object).
      • Both maps have the same layers.
      • Both maps have the same number of layers and with the same name.

      Overrides:
      equals in class Object
      Parameters:
      obj - the reference object with which to compare.
      Returns:
      true if this object is the same as the arg0 argument; otherwise false.
      See Also:
    • addLayerError

      public void addLayerError(String stringProperty)

      Registers the message of an error associated to this map.

      Parameters:
      stringProperty - the error message
      See Also:
    • getLayersError

      public ArrayList getLayersError()

      Gets the list with all error messages registered to this map.

      Returns:
      the list of errors registered to this map
      See Also:
    • clearErrors

      public void clearErrors()

      Removes all error messages associated to this map.

      See Also:
    • getNewGroupLayer

      public FLayers getNewGroupLayer(FLayers parent)

      Creates and returns a new group of layers that belongs to this MapContext.

      Parameters:
      parent - layer node in this MapContexte that will be the parent of the new node
      Returns:
      the new layer node
    • getClassName

      public String getClassName()
    • getLayersToSnap

      public Set<FLyrVect> getLayersToSnap()
    • setLayersToSnap

      public void setLayersToSnap(Set<FLyrVect> layers)
      Adds the layers to the current "layersToSnap" without replacing the current instance of "layersToSnap"
      Parameters:
      layers -
    • update

      public void update(org.gvsig.tools.observer.Observable observable, Object notification)
      Specified by:
      update in interface org.gvsig.tools.observer.Observer
    • getDrawVersion

      public long getDrawVersion()
    • updateDrawVersion

      protected void updateDrawVersion()
    • getMapContextDrawer

      public MapContextDrawer getMapContextDrawer() throws org.gvsig.fmap.dal.exception.ReadException, MapContextException
      Throws:
      org.gvsig.fmap.dal.exception.ReadException
      MapContextException
    • setMapContextDrawerClass

      public void setMapContextDrawerClass(Class mapContextDrawerClass) throws MapContextException
      Throws:
      MapContextException
    • setMapContextDrawer

      public void setMapContextDrawer(MapContextDrawer drawer)
    • loadFromState

      public void loadFromState(org.gvsig.tools.persistence.PersistentState state) throws org.gvsig.tools.persistence.exception.PersistenceException
      Specified by:
      loadFromState in interface org.gvsig.tools.persistence.Persistent
      Throws:
      org.gvsig.tools.persistence.exception.PersistenceException
    • saveToState

      public void saveToState(org.gvsig.tools.persistence.PersistentState state) throws org.gvsig.tools.persistence.exception.PersistenceException
      Specified by:
      saveToState in interface org.gvsig.tools.persistence.Persistent
      Throws:
      org.gvsig.tools.persistence.exception.PersistenceException
    • doDispose

      protected void doDispose() throws org.gvsig.tools.exception.BaseException
      Specified by:
      doDispose in class org.gvsig.tools.dispose.impl.AbstractDisposable
      Throws:
      org.gvsig.tools.exception.BaseException
    • addSelectionListener

      public void addSelectionListener(FLayer lyr)

      Registers an event buffer as a listener for all layers as argument.

      Each FLayer of this map must have an event buffer for all kind of specific listeners of that layer. This method distinguish between Classifiable,

      invalid reference
      AlphanumericData
      , and FLayers layers, and for each one, registers, for their specific listeners, the eventBuffer as a listener.

      Parameters:
      the - layer or layers
    • setOrderManager

      public void setOrderManager(LayerOrderManager lom)
    • getOrderManager

      public LayerOrderManager getOrderManager()
    • hasVectorLayers

      public boolean hasVectorLayers()
    • hasActiveVectorLayers

      public boolean hasActiveVectorLayers()
    • hasActiveLayers

      public boolean hasActiveLayers()
    • hasLayers

      public boolean hasLayers()
    • iterator

      public Iterator<FLayer> iterator()
      Specified by:
      iterator in interface Iterable<FLayer>
    • deepiterator

      public Iterator deepiterator()
    • getTimeContext

      public MapContext.MapTimeContext getTimeContext()
    • getScaleToUseWhenEnvelopeCollapse

      public long getScaleToUseWhenEnvelopeCollapse()
    • setScaleToUseWhenEnvelopeCollapse

      public void setScaleToUseWhenEnvelopeCollapse(long scale)
    • setPrintGraphicsLayer

      public void setPrintGraphicsLayer(boolean b)
    • isPrintGraphicsLayer

      public boolean isPrintGraphicsLayer()