Class MapContext
- All Implemented Interfaces:
Iterable<FLayer>,Projected,org.gvsig.tools.dispose.Disposable,org.gvsig.tools.observer.Observer,org.gvsig.tools.persistence.Persistent
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:
- a hierarchy of
FLayersnodes - a
GraphicLayerlayer - a
ViewPort - an
EventButter - some
s
invalid reference
LegendListener - some
LayerDrawingListeners - some
ErrorListeners
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThe classLayerEventListenerimplements the methods ofLayerCollectionListenerthat handles the "layer added" or "layer removed" events in a map.static interfacestatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic ArrayListstatic ArrayListstatic ArrayListstatic final double[]Defines the value which a unit of a distance measurement must be divided to obtain its equivalent in centimeters.static final double[]static final intstatic final intstatic final Colorstatic final intstatic ArrayListstatic ArrayListstatic ArrayListstatic final intstatic final intprotected FLayersA hierarchy ofFLayersnodes.static final intstatic final intstatic final intstatic doubleDefault zoom in factor.static doubleDefault zoom out factor. -
Constructor Summary
ConstructorsConstructorDescriptionMapContext(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. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddAreaUnit(String name, String abbr, boolean isLinear, double trans2meter) voidaddAsCollectionListener(FLayers layers2) Adds theLayerEventListenerof this map to the collection of layers argument.booleanaddAtomicEventListener(AtomicEventListener listener) Adds a listener of atomic events to the internalEventBuffer.static voidaddDistanceUnit(String name, String abbr, double trans2meter) voidaddErrorListener(ErrorListener listener) Adds the specified error listener to receive error events from this map.voidaddLayerDrawingListener(LayerDrawingListener listener) Adds the specified layer drawing listener to catch and handle drawing events from layers of this map.voidaddLayerError(String stringProperty) Registers the message of an error associated to this map.voidaddLayerListener(LegendListener listener) Adds the specified legend listener (if didn't exist) to receive legend events from this map.voidaddLegendListener(LegendListener listener) Adds the specified legend listener (if didn't exist) to receive legend events from this map.voidRegisters an event buffer as a listener for all layers as argument.voidaddToTrackLayer(FLayer vectorial) Adds a layer to the group of layers that are at a upper level in the tree.voidvoidNotifies to all legend listeners registered, that one legend has changed.voidNotifies to all error listeners registered, that one error has been produced.voidRemoves all error messages associated to this map.Creates a new independentMapContextinstance, that has a clone of the layers and the view port of this one.Like cloneFMap(), but now doesn't clone the layers, rather copies them.voidReturns a newMapContextinstance with the information of thevpargument, and the layers of this map.protected voidvoiddraw(BufferedImage image, Graphics2D g, double scale) Like draw(BufferedImage, Graphics2D, Cancellable, double) , but creating the task as cancellable.voiddraw(BufferedImage image, Graphics2D g, org.gvsig.tools.task.Cancellable cancel, double scale) Draws this map if itsViewPorthas an extent defined:
Selects only the layers that have to be drawn:.invalid reference
#prepareDrawing(BufferedImage, Graphics2D, double)
voiddrawGraphics(BufferedImage image, Graphics2D g, org.gvsig.tools.task.Cancellable cancel, double scale) Draws only the internal graphic layer using the information of theViewPortof this map.voidDraws the visible layers of this map according its view port, on the image parameter.voidbooleanIndicates whether some other object is "equal to" this map.voidFires a layer drawing event to allLayerDrawingListenerlisteners registered, distinguishing the kind of event.static String[]static String[]static double[]static String[]static String[]static intstatic double[]static intReturns the draw frame rate.longgetExtent(Rectangle2D extent, double scale, double wImage, double hImage, double mapUnits, double distanceUnits, double dpi) org.gvsig.fmap.geom.primitive.EnvelopeReturns the union of all extents of all layers of this map.Returns the internalGraphicLayer.getGraphicsLayer(String name) Returns the hierarchy ofFLayersnodes stored in this map.Gets the list with all error messages registered to this map.getNewGroupLayer(FLayers parent) Creates and returns a new group of layers that belongs to thisMapContext.static StringgetOfLinear(int i) org.gvsig.crs.projection.lib.ProjectionReturns the current projection.longdoubleReturns the scale of the view in the screen.static doubleReturns 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.EnvelopeGets the color used to represent the selections.Gets theViewPortassociated to this map.booleanbooleanbooleanbooleanvoidbooleaniterator()voidloadFromState(org.gvsig.tools.persistence.PersistentState state) voidprint(Graphics2D g, double scale, org.gvsig.compat.print.PrintAttributes properties) Prints the layers of this map using theGraphics2Dargument, that usually is theGraphicsof the printer.voidprocess(org.gvsig.tools.visitor.Visitor visitor) voidprocessSelected(org.gvsig.tools.visitor.Visitor visitor) booleanremoveAtomicEventListener(AtomicEventListener listener) Removes a listener of atomic events from the internalEventBuffer.voidremoveErrorListener(LegendListener listener) Removes the specified error listener from this map.voidremoveGraphicsLayer(String name) voidremoveLayerDrawListener(LayerDrawingListener listener) Removes the specified layer drawing listener from this map.voidremoveLayerListener(LegendListener listener) Removes the specified layer listener from this map.voidreportDriverExceptions(String introductoryText, List driverExceptions) Reports to all driver error listeners registered of a bundle of driver exceptions caused in the same map atomic transaction.voidreProject(org.gvsig.crs.projection.lib.CoordinateTransformation arg0) Changes projection of the graphical information of this object.voidsaveToState(org.gvsig.tools.persistence.PersistentState state) voidselect(org.gvsig.tools.visitor.Visitor visitor) voidstatic voidsetDrawFrameRate(int theDrawFrameRate) Sets the draw frame rate.voidsetGraphicsLayer(String name, FLyrVect layer) voidsetGraphicsLayer(GraphicLayer graphicLayer) Sets a newGraphicLayerto this map.voidsetLayersToSnap(Set<FLyrVect> layers) Adds the layers to the current "layersToSnap" without replacing the current instance of "layersToSnap"voidsetMapContextDrawer(MapContextDrawer drawer) voidsetMapContextDrawerClass(Class mapContextDrawerClass) voidvoidsetPrintGraphicsLayer(boolean b) voidsetProjection(org.gvsig.crs.projection.lib.Projection proj) Sets the new projection.voidsetScaleToUseWhenEnvelopeCollapse(long scale) voidsetScaleView(double scale) Sets the new extent of the view, calculated using the scale argument.voidsetSelectionColor(Color selectionColor) Sets the color used to represent the selections.voidsetViewPort(ViewPort viewPort) Sets aViewPortwith the drawing information of this map.voidprotected voidvoidzoomToEnvelope(org.gvsig.fmap.geom.primitive.Envelope env) Sets the given extent to theViewPortand updates the view with the new zoom.Methods inherited from class org.gvsig.tools.dispose.impl.AbstractDisposable
dispose, disposeMethods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
CHANGEM
public static final double[] CHANGEM -
AREANAMES
-
AREAABBR
-
AREATRANS2METER
-
DISTANCENAMES
-
DISTANCEABBR
-
DISTANCETRANS2METER
-
DEFAULT_SELECTION_COLOR
-
CHANGE
public static final double[] CHANGEDefines 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]: kilometerMapContext.CHANGE[1]: meterMapContext.CHANGE[2]: centimeterMapContext.CHANGE[3]: millimeterMapContext.CHANGE[4]: international statute mileMapContext.CHANGE[5]: yardMapContext.CHANGE[6]: footMapContext.CHANGE[7]: inchMapContext.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:
The value ofMapContext.CHANGE[8]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
A hierarchy ofFLayersnodes. -
ZOOMINFACTOR
public static double ZOOMINFACTORDefault 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 ZOOMOUTFACTORDefault 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
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
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 havevp- 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
MapControlinstance that timer invokes per second.- Returns:
- number of repaints of this
MapControlinstance 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
MapControlinstance that timer invokes per second.- Parameters:
theDrawFrameRate- number of repaints of thisMapControlinstance that timer invokes per second- See Also:
-
addAreaUnit
-
getAreaNames
-
getAreaAbbr
-
getAreaTrans2Meter
public static double[] getAreaTrans2Meter() -
getOfLinear
-
addDistanceUnit
-
getDistanceNames
-
getDistanceName
-
getDistanceAbbr
-
getDistanceTrans2Meter
public static double[] getDistanceTrans2Meter() -
getDistancePosition
-
getSelectionColor
Gets the color used to represent the selections.
- Returns:
- color used to represent the selections
-
setSelectionColor
Sets the color used to represent the selections.
- Parameters:
selectionColor- color used to represent the selections
-
reportDriverExceptions
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. Ifnull, use ""driverExceptions- list with a bundle of driver exceptions caught during an atomic event- See Also:
-
addLayerListener
Adds the specified legend listener (if didn't exist) to receive legend events from this map.
- Parameters:
listener- the legend listener- See Also:
-
addLegendListener
Adds the specified legend listener (if didn't exist) to receive legend events from this map.
- Parameters:
listener- the legend listener- See Also:
-
getLegendListeners
-
addLayerDrawingListener
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
-
removeLayerDrawListener
Removes the specified layer drawing listener from this map.
- Parameters:
listener- the listener to remove- See Also:
-
addErrorListener
Adds the specified error listener to receive error events from this map.
- Parameters:
listener- the listener to add- See Also:
-
getErrorListeners
-
removeErrorListener
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
Fires a layer drawing event to all
LayerDrawingListenerlisteners registered, distinguishing the kind of event.- Parameters:
e- the event- See Also:
-
callNewErrorEvent
Notifies to all error listeners registered, that one error has been produced.
- Parameters:
e- the event with information of the error- See Also:
-
removeLayerListener
Removes the specified layer listener from this map.
- Parameters:
listener- the listener to remove- See Also:
-
getLayers
Returns the hierarchy of
FLayersnodes stored in this map.- Returns:
- the hierarchy of nodes of layers stored in this map
-
drawLabels
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:
-
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
Graphics2Dargument, that usually is theGraphicsof the printer.- Parameters:
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 job- See Also:
-
createNewFMap
Returns a new
MapContextinstance with the information of thevpargument, 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
MapContextinstance projected byvp
-
cloneFMap
Creates a new independent
MapContextinstance, 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
MapContextinstance - See Also:
-
cloneToDraw
Like cloneFMap(), but now doesn't clone the layers, rather copies them.- Returns:
- the new map
-
addToTrackLayer
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
-1if there is no image0if 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
- 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:
-
processSelected
public void processSelected(org.gvsig.tools.visitor.Visitor visitor) - See Also:
-
select
public void select(org.gvsig.tools.visitor.Visitor visitor) - See Also:
-
selectFromSelection
public void selectFromSelection()- See Also:
-
createIndex
public void createIndex()- See Also:
-
getProjection
public org.gvsig.crs.projection.lib.Projection getProjection()Description copied from interface:ProjectedReturns the current projection.
- Specified by:
getProjectionin interfaceProjected- 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:ProjectedChanges projection of the graphical information of this object.
-
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
ViewPorthas an extent defined:
- Selects only the layers that have to be drawn:
.
invalid reference
#prepareDrawing(BufferedImage, Graphics2D, double)
- Sets quality: antialiasing by text and images, and quality rendering.
- Draws the layers.
- Fires a
LayerDrawEvent.GRAPHICLAYER_BEFORE_DRAW. - Draws the graphic layer.
- Fires a
LayerDrawEvent.GRAPHICLAYER_AFTER_DRAW. - Invokes the garbage collector and memory clean.
- Parameters:
image- buffer used sometimes insteadgto 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().
- Selects only the layers that have to be drawn:
-
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
ViewPortof this map.- Parameters:
image- image used to accelerate the screen drawg- for rendering 2-dimensional shapes, text and images on the Java(tm) platformcancel- shared object that determines if this layer can continue being drawnscale- 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 insteadgto 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().- See Also:
-
getViewPort
Gets the
ViewPortassociated to this map.- Returns:
- the view port
- See Also:
-
setViewPort
Sets a
ViewPortwith the drawing information of this map.If there was a previous view port, removes its
EventBufferand 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
ViewPortand 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.ReadExceptionReturns the union of all extents of all layers of this map.
- Returns:
- full extent of layers of this map
- See Also:
-
addAtomicEventListener
Adds a listener of atomic events to the internal
EventBuffer.- Parameters:
listener- the new listener- Returns:
trueif has added the listener successfully- See Also:
-
getAtomicEventListeners
-
removeAtomicEventListener
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
Adds the
LayerEventListenerof this map to the collection of layers argument.- Parameters:
a- collection of layers
-
getGraphicsLayer
-
getGraphicsLayers
-
setGraphicsLayer
-
removeGraphicsLayer
-
getGraphicsLayer
Returns the internal
GraphicLayer.- Returns:
- the graphic layer of this map
- See Also:
-
setGraphicsLayer
Sets a new
GraphicLayerto this map.- Parameters:
graphicLayer- the new graphic layer- See Also:
-
equals
Indicates whether some other object is "equal to" this map.
Returns
trueif 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.
-
addLayerError
Registers the message of an error associated to this map.
- Parameters:
stringProperty- the error message- See Also:
-
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
Creates and returns a new group of layers that belongs to this
MapContext.- Parameters:
parent- layer node in thisMapContextethat will be the parent of the new node- Returns:
- the new layer node
-
getClassName
-
getLayersToSnap
-
setLayersToSnap
Adds the layers to the current "layersToSnap" without replacing the current instance of "layersToSnap"- Parameters:
layers-
-
update
- Specified by:
updatein interfaceorg.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.ReadExceptionMapContextException
-
setMapContextDrawerClass
- Throws:
MapContextException
-
setMapContextDrawer
-
loadFromState
public void loadFromState(org.gvsig.tools.persistence.PersistentState state) throws org.gvsig.tools.persistence.exception.PersistenceException - Specified by:
loadFromStatein interfaceorg.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:
saveToStatein interfaceorg.gvsig.tools.persistence.Persistent- Throws:
org.gvsig.tools.persistence.exception.PersistenceException
-
doDispose
protected void doDispose() throws org.gvsig.tools.exception.BaseException- Specified by:
doDisposein classorg.gvsig.tools.dispose.impl.AbstractDisposable- Throws:
org.gvsig.tools.exception.BaseException
-
addSelectionListener
Registers an event buffer as a listener for all layers as argument.
Each
FLayerof this map must have an event buffer for all kind of specific listeners of that layer. This method distinguish betweenClassifiable,, andinvalid reference
AlphanumericDataFLayerslayers, and for each one, registers, for their specific listeners, theeventBufferas a listener.- Parameters:
the- layer or layers
-
setOrderManager
-
getOrderManager
-
hasVectorLayers
public boolean hasVectorLayers() -
hasActiveVectorLayers
public boolean hasActiveVectorLayers() -
hasActiveLayers
public boolean hasActiveLayers() -
hasLayers
public boolean hasLayers() -
iterator
-
deepiterator
-
getTimeContext
-
getScaleToUseWhenEnvelopeCollapse
public long getScaleToUseWhenEnvelopeCollapse() -
setScaleToUseWhenEnvelopeCollapse
public void setScaleToUseWhenEnvelopeCollapse(long scale) -
setPrintGraphicsLayer
public void setPrintGraphicsLayer(boolean b) -
isPrintGraphicsLayer
public boolean isPrintGraphicsLayer()
-