public class MapContext
extends org.gvsig.tools.dispose.impl.AbstractDisposable
implements org.cresques.geo.Projected, org.gvsig.tools.persistence.Persistent, org.gvsig.tools.observer.Observer
The MapContext
class represents the model and a part of the control and view around graphical layers
used by MapControl
.
An instance of MapContext
is made up with:
FLayers
nodes
GraphicLayer
layer
ViewPort
EventButter
LegendListener
s
LayerDrawingListener
s
ErrorListener
s
Modifier and Type | Class and Description |
---|---|
class |
MapContext.LayerEventListener
The class
LayerEventListener implements the methods of LayerCollectionListener
that handles the "layer added" or "layer removed" events in a map. |
Modifier and Type | Field and Description |
---|---|
static java.util.ArrayList |
AREAABBR |
static java.util.ArrayList |
AREANAMES |
static java.util.ArrayList |
AREATRANS2METER |
static int |
CONTAINS |
static int |
CROSSES |
static int |
DISJOINT |
static java.util.ArrayList |
DISTANCEABBR |
static java.util.ArrayList |
DISTANCENAMES |
static java.util.ArrayList |
DISTANCETRANS2METER |
static int |
EQUALS
Gets the name of all distance measurements supported by
MapContext . |
static int |
INTERSECTS |
protected FLayers |
layers
A hierarchy of
FLayers nodes. |
static int |
OVERLAPS |
static int |
TOUCHES |
static int |
WITHIN |
static double |
ZOOMINFACTOR
Default zoom in factor.
|
static double |
ZOOMOUTFACTOR
Default zoom out factor.
|
Constructor and Description |
---|
MapContext() |
MapContext(FLayers fLayers,
ViewPort vp)
Creates a new map context with the layers and the drawing information defined in the view port arguments.
|
MapContext(ViewPort vp)
Creates a new map context with the drawing information defined in the view port argument, and
without layers.
|
Modifier and Type | Method and Description |
---|---|
static void |
addAreaUnit(java.lang.String name,
java.lang.String abbr,
boolean isLinear,
double trans2meter) |
void |
addAsCollectionListener(FLayers layers2)
Adds the
LayerEventListener of this map to the
collection of layers argument. |
boolean |
addAtomicEventListener(AtomicEventListener listener)
Adds a listener of atomic events to the internal
EventBuffer . |
static void |
addDistanceUnit(java.lang.String name,
java.lang.String abbr,
double trans2meter) |
void |
addErrorListener(ErrorListener listener)
Adds the specified error listener to receive error events from this map.
|
void |
addLayerDrawingListener(LayerDrawingListener listener)
Adds the specified layer drawing listener to catch and handle drawing events from layers of this map.
|
void |
addLayerError(java.lang.String stringProperty)
Registers the message of an error associated to this map.
|
void |
addLayerListener(LegendListener listener)
Adds the specified legend listener (if didn't exist) to receive legend events from this map.
|
void |
addToTrackLayer(FLayer vectorial)
Adds a layer to the group of layers that are at a upper level in the tree.
|
void |
beginAtomicEvent() |
void |
callLegendChanged()
Notifies to all legend listeners registered, that one legend has changed.
|
void |
callNewErrorEvent(ErrorEvent e)
Notifies to all error listeners registered, that one error has been produced.
|
void |
clearErrors()
Removes all error messages associated to this map.
|
MapContext |
cloneFMap()
Creates a new independent
MapContext instance, that has a clone of the layers and the view port of this one. |
MapContext |
cloneToDraw()
Like cloneFMap(), but now doesn't clone the layers, rather copies them.
|
void |
createIndex() |
MapContext |
createNewFMap(ViewPort vp)
Returns a new
MapContext instance with the information of the vp argument, and the layers of this map. |
protected void |
doDispose() |
void |
draw(java.awt.image.BufferedImage image,
java.awt.Graphics2D g,
org.gvsig.tools.task.Cancellable cancel,
double scale)
Draws this map if its
ViewPort has an extent defined:Selects only the layers that have to be drawn: #prepareDrawing(BufferedImage, Graphics2D, double). |
void |
draw(java.awt.image.BufferedImage image,
java.awt.Graphics2D g,
double scale)
Like
draw(BufferedImage, Graphics2D, Cancellable, double)
, but creating the task as cancellable.
|
void |
drawLabels(java.awt.image.BufferedImage b)
Draws the visible layers of this map according its view port, on the image parameter.
|
void |
endAtomicEvent() |
boolean |
equals(java.lang.Object arg0)
Indicates whether some other object is "equal to" this map.
|
void |
fireLayerDrawingEvent(LayerDrawEvent e)
Fires a layer drawing event to all
LayerDrawingListener listeners registered,
distinguishing the kind of event. |
static java.lang.String[] |
getAreaAbbr() |
static java.lang.String[] |
getAreaNames() |
static double[] |
getAreaTrans2Meter() |
java.lang.String |
getClassName() |
static java.lang.String[] |
getDistanceAbbr() |
java.lang.String |
getDistanceName() |
static java.lang.String[] |
getDistanceNames() |
static int |
getDistancePosition(java.lang.String s) |
static double[] |
getDistanceTrans2Meter() |
static int |
getDrawFrameRate()
Returns the draw frame rate.
|
long |
getDrawVersion() |
org.gvsig.fmap.geom.primitive.Envelope |
getFullEnvelope()
Returns the union of all extents of all layers of this map.
|
GraphicLayer |
getGraphicsLayer()
Returns the internal
GraphicLayer . |
FLayers |
getLayers()
Returns the hierarchy of
FLayers nodes stored in this map. |
java.util.ArrayList |
getLayersError()
Gets the list with all error messages registered to this map.
|
java.util.ArrayList |
getLayersToSnap() |
MapContextDrawer |
getMapContextDrawer() |
FLayers |
getNewGroupLayer(FLayers parent)
Creates and returns a new group of layers that belongs to this
MapContext . |
static java.lang.String |
getOfLinear(int i) |
LayerOrderManager |
getOrderManager() |
org.cresques.cts.IProjection |
getProjection() |
long |
getScaleView()
Returns the scale of the view in the screen.
|
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.
|
org.gvsig.fmap.geom.primitive.Envelope |
getSelectionBounds() |
static java.awt.Color |
getSelectionColor()
Gets the color used to represent the selections.
|
ViewPort |
getViewPort()
Gets the
ViewPort associated to this map. |
void |
invalidate() |
void |
loadFromState(org.gvsig.tools.persistence.PersistentState state) |
void |
print(java.awt.Graphics2D g,
double scale,
org.gvsig.compat.print.PrintAttributes properties)
Prints the layers of this map using the
Graphics2D
argument, that usually is the Graphics of the printer. |
void |
process(org.gvsig.tools.visitor.Visitor visitor) |
void |
processSelected(org.gvsig.tools.visitor.Visitor visitor) |
static void |
registerPersistent() |
boolean |
removeAtomicEventListener(AtomicEventListener listener)
Removes a listener of atomic events from the internal
EventBuffer . |
void |
removeErrorListener(LegendListener listener)
Removes the specified error listener from this map.
|
void |
removeLayerDrawListener(LayerDrawingListener listener)
Removes the specified layer drawing listener from this map.
|
void |
removeLayerListener(LegendListener listener)
Removes the specified layer listener from this map.
|
void |
reportDriverExceptions(java.lang.String introductoryText,
java.util.List driverExceptions)
Reports to all driver error listeners registered of a bundle of driver exceptions caused in the same map atomic transaction.
|
void |
reProject(org.cresques.cts.ICoordTrans arg0) |
void |
saveToState(org.gvsig.tools.persistence.PersistentState state) |
void |
select(org.gvsig.tools.visitor.Visitor visitor) |
void |
selectFromSelection() |
static void |
setDrawFrameRate(int dFR)
Sets the draw frame rate.
|
void |
setGraphicsLayer(GraphicLayer graphicLayer)
Sets a new
GraphicLayer to this map. |
void |
setLayersToSnap(java.util.ArrayList layersToSnap) |
void |
setMapContextDrawer(MapContextDrawer drawer) |
void |
setMapContextDrawerClass(java.lang.Class mapContextDrawerClass) |
void |
setOrderManager(LayerOrderManager lom) |
void |
setProjection(org.cresques.cts.IProjection proj)
Sets the new projection.
|
void |
setScaleView(long scale)
Sets the new extent of the view, calculated using the scale argument.
|
static void |
setSelectionColor(java.awt.Color selectionColor)
Sets the color used to represent the selections.
|
void |
setViewPort(ViewPort viewPort)
Sets a
ViewPort with the drawing information
of this map. |
void |
update(org.gvsig.tools.observer.Observable observable,
java.lang.Object notification) |
protected void |
updateDrawVersion() |
void |
zoomToEnvelope(org.gvsig.fmap.geom.primitive.Envelope extent)
Sets the given extent to the
ViewPort and updates the view with the new zoom. |
public static java.util.ArrayList AREAABBR
public static java.util.ArrayList AREANAMES
public static java.util.ArrayList AREATRANS2METER
public static final int CONTAINS
public static final int CROSSES
public static final int DISJOINT
public static java.util.ArrayList DISTANCEABBR
public static java.util.ArrayList DISTANCENAMES
public static java.util.ArrayList DISTANCETRANS2METER
public static final int EQUALS
Gets the name of all distance measurements supported by MapContext
.
public static final int INTERSECTS
public static final int OVERLAPS
public static final int TOUCHES
public static final int WITHIN
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.
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.
public 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.
fLayers
- the initial hierarchy of nodes of layers that this map will havevp
- information for drawing the layers of this map in the available rectangular area according a projectionpublic MapContext(ViewPort vp)
Creates a new map context with the drawing information defined in the view port argument, and without layers.
vp
- information for drawing the layers of this map in the available rectangular area according a projectionpublic static void addAreaUnit(java.lang.String name, java.lang.String abbr, boolean isLinear, double trans2meter)
public void addAsCollectionListener(FLayers layers2)
Adds the LayerEventListener
of this map to the
collection of layers argument.
a
- collection of layerspublic boolean addAtomicEventListener(AtomicEventListener listener)
Adds a listener of atomic events to the internal EventBuffer
.
listener
- the new listenertrue
if has added the listener successfullyremoveAtomicEventListener(AtomicEventListener)
,
EventBuffer.addAtomicEventListener(AtomicEventListener)
public static void addDistanceUnit(java.lang.String name, java.lang.String abbr, double trans2meter)
public void addErrorListener(ErrorListener listener)
Adds the specified error listener to receive error events from this map.
listener
- the listener to addremoveErrorListener(LegendListener)
,
reportDriverExceptions(String, List)
public void addLayerDrawingListener(LayerDrawingListener listener)
Adds the specified layer drawing listener to catch and handle drawing events from layers of this map.
listener
- the listener to addremoveLayerDrawListener(LayerDrawingListener)
,
fireLayerDrawingEvent(LayerDrawEvent)
public void addLayerError(java.lang.String stringProperty)
Registers the message of an error associated to this map.
stringProperty
- the error messagegetLayersError()
,
clearErrors()
public void addLayerListener(LegendListener listener)
Adds the specified legend listener (if didn't exist) to receive legend events from this map.
listener
- the legend listenerremoveLayerListener(LegendListener)
,
callLegendChanged()
public void addToTrackLayer(FLayer vectorial)
Adds a layer to the group of layers that are at a upper level in the tree.
vectorial
- the layer to addpublic void beginAtomicEvent()
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.
public void callNewErrorEvent(ErrorEvent e)
Notifies to all error listeners registered, that one error has been produced.
e
- the event with information of the erroraddErrorListener(ErrorListener)
,
removeErrorListener(LegendListener)
,
reportDriverExceptions(String, List)
public void clearErrors()
Removes all error messages associated to this map.
addLayerError(String)
,
getLayersError()
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.
MapContext
instanceXMLException
- if fails cloning the view port or a layerFLayer.cloneLayer()
,
ViewPort#cloneViewPort()
public MapContext cloneToDraw()
public void createIndex()
org.gvsig.fmap.mapcontext.rendering.strategies.Strategy#createIndex()
public MapContext createNewFMap(ViewPort vp)
Returns a new MapContext
instance with the information of the vp
argument, and the layers of this map.
vp
- information for drawing the layers of this map in the available rectangular area according a projectionMapContext
instance projected by vp
protected void doDispose() throws org.gvsig.tools.exception.BaseException
doDispose
in class org.gvsig.tools.dispose.impl.AbstractDisposable
org.gvsig.tools.exception.BaseException
public void draw(java.awt.image.BufferedImage image, java.awt.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:
LayerDrawEvent.GRAPHICLAYER_BEFORE_DRAW
.
LayerDrawEvent.GRAPHICLAYER_AFTER_DRAW
.
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) platformcancel
- shared object that determines if this layer can continue being
drawnscale
- the scale of the view. Must be between
FLayer.getMinScale() and
FLayer.getMaxScale().MapContextException
- if there is an error getting the instance of MapContextDrawerReadDriverException
- if fails reading with the driver.org.gvsig.fmap.dal.exception.ReadException
public void draw(java.awt.image.BufferedImage image, java.awt.Graphics2D g, double scale) throws org.gvsig.fmap.dal.exception.ReadException, MapContextException
Like draw(BufferedImage, Graphics2D, Cancellable, double) , but creating the task as cancellable.
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) platformscale
- the scale of the view. Must be between
FLayer.getMinScale() and
FLayer.getMaxScale().MapContextException
- if there is an error getting the instance of MapContextDrawerReadDriverException
- if the driver fails reading.org.gvsig.fmap.dal.exception.ReadException
draw(BufferedImage, Graphics2D, Cancellable, double)
public void drawLabels(java.awt.image.BufferedImage b)
Draws the visible layers of this map according its view port, on the image parameter.
b
- image with an accessible buffer of image datapublic void endAtomicEvent()
public boolean equals(java.lang.Object arg0)
Indicates whether some other object is "equal to" this map.
Returns true
if success one of this options:
equals
in class java.lang.Object
obj
- the reference object with which to compare.true
if this object is the same as the arg0
argument; otherwise false
.Object.equals(Object)
public void fireLayerDrawingEvent(LayerDrawEvent e)
Fires a layer drawing event to all LayerDrawingListener
listeners registered,
distinguishing the kind of event.
e
- the eventaddLayerDrawingListener(LayerDrawingListener)
,
removeLayerDrawListener(LayerDrawingListener)
public static java.lang.String[] getAreaAbbr()
public static java.lang.String[] getAreaNames()
public static double[] getAreaTrans2Meter()
public java.lang.String getClassName()
public static java.lang.String[] getDistanceAbbr()
public java.lang.String getDistanceName()
public static java.lang.String[] getDistanceNames()
public static int getDistancePosition(java.lang.String s)
public static double[] getDistanceTrans2Meter()
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.
MapControl
instance that timer invokes per second#applyFrameRate()
,
setDrawFrameRate(int)
public long getDrawVersion()
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.
ReadDriverException
- if the driver fails reading.org.gvsig.fmap.dal.exception.ReadException
FLayers.getFullEnvelope()
public GraphicLayer getGraphicsLayer()
Returns the internal GraphicLayer
.
setGraphicsLayer(GraphicLayer)
public FLayers getLayers()
Returns the hierarchy of FLayers
nodes stored in this map.
public java.util.ArrayList getLayersError()
Gets the list with all error messages registered to this map.
addLayerError(String)
,
clearErrors()
public java.util.ArrayList getLayersToSnap()
public MapContextDrawer getMapContextDrawer() throws org.gvsig.fmap.dal.exception.ReadException, MapContextException
org.gvsig.fmap.dal.exception.ReadException
MapContextException
public FLayers getNewGroupLayer(FLayers parent)
Creates and returns a new group of layers that belongs to this MapContext
.
parent
- layer node in this MapContexte
that will be the parent of the new nodepublic static java.lang.String getOfLinear(int i)
public LayerOrderManager getOrderManager()
public org.cresques.cts.IProjection getProjection()
getProjection
in interface org.cresques.geo.Projected
Projected.getProjection()
,
ViewPort.getProjection()
,
setProjection(IProjection)
,
reProject(ICoordTrans)
public long getScaleView()
Returns the scale of the view in the screen.
-1
if there is no image
0
if there is no extent defined for the image
setScaleView(long)
,
ViewPort.getAdjustedExtent()
,
IProjection.getScale(double, double, double, double)
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.
public org.gvsig.fmap.geom.primitive.Envelope getSelectionBounds() throws org.gvsig.tools.exception.BaseException
org.gvsig.tools.exception.BaseException
public static java.awt.Color getSelectionColor()
Gets the color used to represent the selections.
public ViewPort getViewPort()
Gets the ViewPort
associated to this map.
setViewPort(ViewPort)
public void invalidate()
#redraw()
public void loadFromState(org.gvsig.tools.persistence.PersistentState state) throws org.gvsig.tools.persistence.exception.PersistenceException
loadFromState
in interface org.gvsig.tools.persistence.Persistent
org.gvsig.tools.persistence.exception.PersistenceException
public void print(java.awt.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.
g
- for rendering 2-dimensional shapes, text and images on the
Java(tm) platformscale
- 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 jobMapContextException
- if there is an error getting the instance of MapContextDrawerReadDriverException
- if fails reading with driver.org.gvsig.fmap.dal.exception.ReadException
FLayer.draw(BufferedImage, Graphics2D, ViewPort, Cancellable,
double)
public void process(org.gvsig.tools.visitor.Visitor visitor)
org.gvsig.fmap.mapcontext.rendering.strategies.Strategy#process(com.iver.cit.gvsig.fmap.FeatureSelectorVisitor)
public void processSelected(org.gvsig.tools.visitor.Visitor visitor)
org.gvsig.fmap.mapcontext.rendering.strategies.Strategy#processSelected(com.iver.cit.gvsig.fmap.FeatureVisitor)
public static void registerPersistent()
public boolean removeAtomicEventListener(AtomicEventListener listener)
Removes a listener of atomic events from the internal EventBuffer
.
listener
- the listener to removeaddAtomicEventListener(AtomicEventListener)
,
EventBuffer.removeAtomicEventListener(AtomicEventListener)
public void removeErrorListener(LegendListener listener)
Removes the specified error listener from this map.
listener
- the listener to removeaddErrorListener(ErrorListener)
,
reportDriverExceptions(String, List)
public void removeLayerDrawListener(LayerDrawingListener listener)
Removes the specified layer drawing listener from this map.
listener
- the listener to removeaddLayerDrawingListener(LayerDrawingListener)
,
fireLayerDrawingEvent(LayerDrawEvent)
public void removeLayerListener(LegendListener listener)
Removes the specified layer listener from this map.
listener
- the listener to removeaddLayerListener(LegendListener)
,
callLegendChanged()
public void reportDriverExceptions(java.lang.String introductoryText, java.util.List driverExceptions)
Reports to all driver error listeners registered of a bundle of driver exceptions caused in the same map atomic transaction.
introductoryText
- introductory text specified by developer. If null
, use ""driverExceptions
- list with a bundle of driver exceptions caught during an atomic eventaddErrorListener(ErrorListener)
,
removeErrorListener(LegendListener)
public void reProject(org.cresques.cts.ICoordTrans arg0)
reProject
in interface org.cresques.geo.Projected
Projected.reProject(org.cresques.cts.ICoordTrans)
public void saveToState(org.gvsig.tools.persistence.PersistentState state) throws org.gvsig.tools.persistence.exception.PersistenceException
saveToState
in interface org.gvsig.tools.persistence.Persistent
org.gvsig.tools.persistence.exception.PersistenceException
public void select(org.gvsig.tools.visitor.Visitor visitor)
org.gvsig.fmap.mapcontext.rendering.strategies.Strategy#select(com.iver.cit.gvsig.fmap.FeatureSelectorVisitor,
VectorialSubSet)
public void selectFromSelection()
org.gvsig.fmap.mapcontext.rendering.strategies.Strategy#selectFromSelection()
public static void setDrawFrameRate(int dFR)
Sets the draw frame rate.
Draw frame rate is the number of repaints of this MapControl
instance that timer invokes per second.
drawFrameRate
- number of repaints of this MapControl
instance that timer invokes per second#applyFrameRate()
,
getDrawFrameRate()
public void setGraphicsLayer(GraphicLayer graphicLayer)
Sets a new GraphicLayer
to this map.
graphicLayer
- the new graphic layergetGraphicsLayer()
public void setLayersToSnap(java.util.ArrayList layersToSnap)
public void setMapContextDrawer(MapContextDrawer drawer)
public void setMapContextDrawerClass(java.lang.Class mapContextDrawerClass) throws MapContextException
MapContextException
public void setOrderManager(LayerOrderManager lom)
public void setProjection(org.cresques.cts.IProjection proj)
Sets the new projection.
proj
- the new projectiongetProjection()
,
ViewPort.setProjection(IProjection)
,
reProject(ICoordTrans)
public void setScaleView(long 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.
scale
- the new scale for the viewViewPort.setProjection(IProjection)
,
getScaleView()
public static void setSelectionColor(java.awt.Color selectionColor)
Sets the color used to represent the selections.
selectionColor
- color used to represent the selectionspublic 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.
viewPort
- the viewPortgetViewPort()
public void update(org.gvsig.tools.observer.Observable observable, java.lang.Object notification)
update
in interface org.gvsig.tools.observer.Observer
protected void updateDrawVersion()
public void zoomToEnvelope(org.gvsig.fmap.geom.primitive.Envelope extent)
Sets the given extent to the ViewPort
and updates the view with the new zoom.
extent
- the extent of the new zoomCopyright © 2013 gvSIG Association. All rights reserved.