001: /*
002: * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
003: * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
004: * under the terms of the GNU Lesser General Public License as published by the Free Software
005: * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
006: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
007: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
008: */
009: package net.refractions.udig.project.render;
010:
011: import java.awt.Dimension;
012: import java.awt.Point;
013: import java.awt.geom.AffineTransform;
014:
015: import net.refractions.udig.project.IMap;
016: import net.refractions.udig.project.internal.render.impl.ViewportModelImpl;
017:
018: import org.opengis.referencing.crs.CoordinateReferenceSystem;
019:
020: import com.vividsolutions.jts.geom.Coordinate;
021: import com.vividsolutions.jts.geom.Envelope;
022:
023: /**
024: * Models the Viewport on the map.
025: *
026: * @author Jesse
027: * @since 0.5
028: */
029: public interface IViewportModel {
030:
031: /**
032: * A Default setting to use for the viewport CRS.
033: */
034: public static final CoordinateReferenceSystem DEFAULT_CRS = ViewportModelImpl.DEFAULT_CRS;
035:
036: /**
037: * Returns the local coordinate system. The local coordinate system is the CRS that all the
038: * layer data will be transformed into. Once the layer data is transformed into the local CRS
039: * then it is transformed for display onto the screen
040: *
041: * @return the local coordinate system
042: * @see CoordinateReferenceSystem
043: */
044: public CoordinateReferenceSystem getCRS();
045:
046: /**
047: * Returns the bounding box of the Viewport in world coordinates.
048: * <p>
049: * Note: Since Envelope is not a UDIG element changes to the bounds envelope object will not
050: * raise events. Therefore the bounds should only be modified via the ViewportModel interface
051: * </p>
052: * The bounds are in the same CRS as returned by {@linkplain #getCRS()}
053: *
054: * @return the bounding box of the Viewport in world coordinates.
055: * @see Envelope
056: */
057: public Envelope getBounds(); // TODO: THIS MUST BE A REFERENCED ENVELOPE!
058:
059: /**
060: * Returns the center of the viewport in world coordinates. The bounds are in the same CRS as
061: * returned by {@linkplain #getCRS()}
062: *
063: * @return the center of the viewport in world coordinates
064: * @see Coordinate
065: */
066: public Coordinate getCenter();
067:
068: /**
069: * Returns the Viewport's height in world coordinates. The bounds are in the same CRS as
070: * returned by {@linkplain #getCRS()}
071: *
072: * @return the Viewport's height in world coordinates.
073: */
074: public double getHeight();
075:
076: /**
077: * Returns the Viewport's width in world coordinates. The bounds are in the same CRS as returned
078: * by {@linkplain #getCRS()}
079: *
080: * @return the Viewport's width in world coordinates.
081: */
082: public double getWidth();
083:
084: /**
085: * Returns the aspect ratio of the viewport.
086: *
087: * @return The aspect ratio of the viewport.
088: */
089: public double getAspectRatio();
090:
091: /**
092: * Gets the Map that contains the current ViewportModel
093: *
094: * @return the Map that contains the current ViewportModel
095: */
096: public IMap getMap();
097:
098: /**
099: * Gets up the affine transform that will transform from the world to screen. A convenience
100: * method.
101: *
102: * @return a transform that maps from real world coordinates to the screen
103: * @see AffineTransform
104: */
105: public AffineTransform worldToScreenTransform();
106:
107: /**
108: * Returns the pixel on the screen for a given coordinate in world space.
109: *
110: * @param coord A coordinate in world space.
111: * @return The pixel on the screen that the world coordinate is drawn on.
112: * @see Point
113: * @see Coordinate
114: */
115: public Point worldToPixel(Coordinate coord);
116:
117: /**
118: * Gets up the affine transform that will transform from the world to the display of size
119: * destination. A convenience method. This method is independent of the CRS.
120: *
121: * @return a transform that maps from real world coordinates to the screen
122: */
123: public AffineTransform worldToScreenTransform(Envelope mapExtent,
124: Dimension destination);
125:
126: /**
127: * Converts a coordinate expressed on the device space back to real world coordinates
128: *
129: * @param x horizontal coordinate on device space
130: * @param y vertical coordinate on device space
131: * @return The correspondent real world coordinate
132: * @see Coordinate
133: */
134: public Coordinate pixelToWorld(int x, int y);
135:
136: /**
137: * Returns the size of a pixel in world units.
138: *
139: * @return the size of a pixel in world units.
140: * @see Coordinate
141: */
142: public Coordinate getPixelSize();
143:
144: /**
145: * Find the scale denominator of the map.
146: * Method:
147: * 1. find the diagonal distance (meters)
148: * 2. find the diagonal distance (pixels)
149: * 3. find the diagonal distance (meters) -- use DPI
150: * 4. calculate scale (#1/#2)
151: *
152: * NOTE: return the scale denominator not the actual scale (1/scale = denominator)
153: *
154: * TODO: (SLD spec page 28):
155: * Since it is common to integrate the output of multiple servers into a single displayed result in the
156: * web-mapping environment, it is important that different map servers have consistent behaviour with respect to
157: * processing scales, so that all of the independent servers will select or deselect rules at the same scales.
158: * To insure consistent behaviour, scales relative to coordinate spaces must be handled consistently between map
159: * servers. For geographic coordinate systems, which use angular units, the angular coverage of a map should be
160: * converted to linear units for computation of scale by using the circumference of the Earth at the equator and
161: * by assuming perfectly square linear units. For linear coordinate systems, the size of the coordinate space
162: * should be used directly without compensating for distortions in it with respect to the shape of the real Earth.
163: *
164: * NOTE: we are actually doing a a much more exact calculation, and accounting for non-square pixels
165: *
166: * @return the scale denominator of the map on the current display. Return -1 if something is wrong. For example the display has not
167: * yet been created.
168: */
169: public double getScaleDenominator();
170:
171: /**
172: * Adds a IViewportModelListener to this map. A given listener will only be added once.
173: *
174: * @param listener Listener to be added
175: * @see net.refractions.udig.project.ViewportModelEvent.ViewportModelEventType
176: */
177: public void addViewportModelListener(IViewportModelListener listener);
178:
179: /**
180: * Removes a IViewportModelListener from this map.
181: *
182: * @param listener Listener to be removed
183: */
184: public void removeViewportModelListener(
185: IViewportModelListener listener);
186: }
|