Revision 39022
tags/v2_0_0_Build_2056/libraries/libFMap_mapcontext/resources-test/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
|
2 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
3 |
|
|
4 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
5 |
|
|
6 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
7 |
<layout class="org.apache.log4j.PatternLayout"> |
|
8 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
9 |
</layout> |
|
10 |
</appender> |
|
11 |
|
|
12 |
<category name="org.gvsig.tools"> |
|
13 |
<priority value="DEBUG" /> |
|
14 |
</category> |
|
15 |
<category name="org.gvsig.fmap.mapcontext"> |
|
16 |
<priority value="DEBUG" /> |
|
17 |
</category> |
|
18 |
|
|
19 |
<root> |
|
20 |
<priority value="INFO" /> |
|
21 |
<appender-ref ref="CONSOLE" /> |
|
22 |
</root> |
|
23 |
</log4j:configuration> |
tags/v2_0_0_Build_2056/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/MapContextManager.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {DiSiD Technologies} {Create Manager to register MapContextDrawer implementation} |
|
26 |
*/ |
|
27 |
package org.gvsig.fmap.mapcontext; |
|
28 |
|
|
29 |
import java.awt.Color; |
|
30 |
import java.awt.Font; |
|
31 |
|
|
32 |
import org.cresques.cts.IProjection; |
|
33 |
|
|
34 |
import org.gvsig.fmap.dal.DataStore; |
|
35 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
36 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
|
37 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
38 |
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer; |
|
39 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
40 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
|
41 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendReader; |
|
42 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter; |
|
43 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
|
44 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
|
45 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
46 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IWarningSymbol; |
|
47 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
|
48 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences; |
|
49 |
|
|
50 |
/** |
|
51 |
* Manager of the MapContext library. |
|
52 |
* |
|
53 |
* Holds the default implementation of the {@link MapContextDrawer}. |
|
54 |
* |
|
55 |
* @author <a href="mailto:cordinyana@gvsig.org">C?sar Ordi?ana</a> |
|
56 |
* @author <a href="mailto:jjdelcerro@gvsig.org">Joaquin Jose del Cerro</a> |
|
57 |
*/ |
|
58 |
public interface MapContextManager { |
|
59 |
|
|
60 |
/** |
|
61 |
* Create a new layer from the data parameters passed as parameter. |
|
62 |
* |
|
63 |
* @param layerName name used in for the new layer. |
|
64 |
* @param parameters used for create the {@link DataStore} of the new layer |
|
65 |
* |
|
66 |
* @return the new FLayer |
|
67 |
* |
|
68 |
* @throws LoadLayerException |
|
69 |
*/ |
|
70 |
public FLayer createLayer(String layerName, |
|
71 |
DataStoreParameters parameters) throws LoadLayerException; |
|
72 |
|
|
73 |
/** |
|
74 |
* Create a layer from a {@link DataStore}. |
|
75 |
* |
|
76 |
* @param layerName name used in for the new layer. |
|
77 |
* @param store used for the new layer |
|
78 |
* |
|
79 |
* @return the new FLayer |
|
80 |
* |
|
81 |
* @throws LoadLayerException |
|
82 |
*/ |
|
83 |
public FLayer createLayer(String layerName, DataStore store) |
|
84 |
throws LoadLayerException; |
|
85 |
|
|
86 |
/** |
|
87 |
* Create a layer to be used as the {@link GraphicLayer}. |
|
88 |
* |
|
89 |
* @param projection used in the layer. |
|
90 |
* |
|
91 |
* @return the new {@link GraphicLayer}. |
|
92 |
*/ |
|
93 |
public GraphicLayer createGraphicsLayer(IProjection projection); |
|
94 |
|
|
95 |
/** |
|
96 |
* Returns the current {@link SymbolManager}. |
|
97 |
* |
|
98 |
* @return the {@link SymbolManager} |
|
99 |
*/ |
|
100 |
SymbolManager getSymbolManager(); |
|
101 |
|
|
102 |
/** |
|
103 |
* Sets the class to use as the default implementation for the |
|
104 |
* {@link MapContextDrawer}. |
|
105 |
* |
|
106 |
* @param drawerClazz |
|
107 |
* the {@link MapContextDrawer} class to use |
|
108 |
* @throws MapContextException |
|
109 |
* if there is any error setting the class |
|
110 |
*/ |
|
111 |
public void setDefaultMapContextDrawer(Class drawerClazz) |
|
112 |
throws MapContextException; |
|
113 |
|
|
114 |
public void validateMapContextDrawer(Class drawerClazz) throws MapContextException; |
|
115 |
|
|
116 |
/** |
|
117 |
* Creates a new instance of the default {@link MapContextDrawer} |
|
118 |
* implementation. |
|
119 |
* |
|
120 |
* @return the new {@link MapContextDrawer} instance |
|
121 |
* @throws MapContextException |
|
122 |
* if there is an error creating the new object instance |
|
123 |
*/ |
|
124 |
public MapContextDrawer createDefaultMapContextDrawerInstance() |
|
125 |
throws MapContextException; |
|
126 |
|
|
127 |
/** |
|
128 |
* Creates a new instance of the provided {@link MapContextDrawer} |
|
129 |
* implementation. |
|
130 |
* |
|
131 |
* @param drawerClazz |
|
132 |
* the {@link MapContextDrawer} implementation class |
|
133 |
* @return the new {@link MapContextDrawer} instance |
|
134 |
* @throws MapContextException |
|
135 |
* if there is an error creating the new object instance |
|
136 |
*/ |
|
137 |
public MapContextDrawer createMapContextDrawerInstance(Class drawerClazz) |
|
138 |
throws MapContextException; |
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
void registerLegend(String legendName, Class legendClass) |
|
143 |
throws MapContextRuntimeException; |
|
144 |
|
|
145 |
ILegend createLegend(String legendName) throws MapContextRuntimeException; |
|
146 |
|
|
147 |
void setDefaultVectorLegend(String legendName); |
|
148 |
|
|
149 |
IVectorLegend createDefaultVectorLegend(int shapeType) |
|
150 |
throws MapContextRuntimeException; |
|
151 |
|
|
152 |
void registerLegendWriter(String legendName, String format, |
|
153 |
Class writerClass) throws MapContextRuntimeException; |
|
154 |
|
|
155 |
void registerLegendReader(String format, Class readerClass) |
|
156 |
throws MapContextRuntimeException; |
|
157 |
|
|
158 |
ILegendWriter createLegendWriter(String legendName, String format) |
|
159 |
throws MapContextException; |
|
160 |
|
|
161 |
ILegendReader createLegendReader(String format) |
|
162 |
throws MapContextRuntimeException; |
|
163 |
|
|
164 |
/** |
|
165 |
* @deprecated to be removed in gvSIG 2.0 |
|
166 |
* @see {@link SymbolPreferences}. |
|
167 |
*/ |
|
168 |
int getDefaultCartographicSupportMeasureUnit(); |
|
169 |
|
|
170 |
/** |
|
171 |
* @deprecated to be removed in gvSIG 2.0 |
|
172 |
* @see {@link SymbolPreferences}. |
|
173 |
*/ |
|
174 |
void setDefaultCartographicSupportMeasureUnit( |
|
175 |
int defaultCartographicSupportMeasureUnit); |
|
176 |
|
|
177 |
/** |
|
178 |
* @deprecated to be removed in gvSIG 2.0 |
|
179 |
* @see {@link SymbolPreferences}. |
|
180 |
*/ |
|
181 |
int getDefaultCartographicSupportReferenceSystem(); |
|
182 |
|
|
183 |
/** |
|
184 |
* @deprecated to be removed in gvSIG 2.0 |
|
185 |
* @see {@link SymbolPreferences}. |
|
186 |
*/ |
|
187 |
void setDefaultCartographicSupportReferenceSystem( |
|
188 |
int defaultCartographicSupportReferenceSystem); |
|
189 |
|
|
190 |
/** |
|
191 |
* @deprecated to be removed in gvSIG 2.0 |
|
192 |
* @see {@link SymbolPreferences}. |
|
193 |
*/ |
|
194 |
Color getDefaultSymbolColor(); |
|
195 |
|
|
196 |
/** |
|
197 |
* @deprecated to be removed in gvSIG 2.0 |
|
198 |
* @see {@link SymbolPreferences}. |
|
199 |
*/ |
|
200 |
void setDefaultSymbolColor(Color defaultSymbolColor); |
|
201 |
|
|
202 |
/** |
|
203 |
* @deprecated to be removed in gvSIG 2.0 |
|
204 |
* @see {@link SymbolPreferences}. |
|
205 |
*/ |
|
206 |
void resetDefaultSymbolColor(); |
|
207 |
|
|
208 |
/** |
|
209 |
* @deprecated to be removed in gvSIG 2.0 |
|
210 |
* @see {@link SymbolPreferences}. |
|
211 |
*/ |
|
212 |
Color getDefaultSymbolFillColor(); |
|
213 |
|
|
214 |
/** |
|
215 |
* @deprecated to be removed in gvSIG 2.0 |
|
216 |
* @see {@link SymbolPreferences}. |
|
217 |
*/ |
|
218 |
void setDefaultSymbolFillColor(Color defaultSymbolFillColor); |
|
219 |
|
|
220 |
/** |
|
221 |
* @deprecated to be removed in gvSIG 2.0 |
|
222 |
* @see {@link SymbolPreferences}. |
|
223 |
*/ |
|
224 |
void resetDefaultSymbolFillColor(); |
|
225 |
|
|
226 |
/** |
|
227 |
* @deprecated to be removed in gvSIG 2.0 |
|
228 |
* @see {@link SymbolPreferences}. |
|
229 |
*/ |
|
230 |
boolean isDefaultSymbolFillColorAleatory(); |
|
231 |
|
|
232 |
/** |
|
233 |
* @deprecated to be removed in gvSIG 2.0 |
|
234 |
* @see {@link SymbolPreferences}. |
|
235 |
*/ |
|
236 |
void setDefaultSymbolFillColorAleatory( |
|
237 |
boolean defaultSymbolFillColorAleatory); |
|
238 |
|
|
239 |
/** |
|
240 |
* @deprecated to be removed in gvSIG 2.0 |
|
241 |
* @see {@link SymbolPreferences}. |
|
242 |
*/ |
|
243 |
void resetDefaultSymbolFillColorAleatory(); |
|
244 |
|
|
245 |
/** |
|
246 |
* @deprecated to be removed in gvSIG 2.0 |
|
247 |
* @see {@link SymbolPreferences}. |
|
248 |
*/ |
|
249 |
Font getDefaultSymbolFont(); |
|
250 |
|
|
251 |
/** |
|
252 |
* @deprecated to be removed in gvSIG 2.0 |
|
253 |
* @see {@link SymbolPreferences}. |
|
254 |
*/ |
|
255 |
void setDefaultSymbolFont(Font defaultSymbolFont); |
|
256 |
|
|
257 |
/** |
|
258 |
* @deprecated to be removed in gvSIG 2.0 |
|
259 |
* @see {@link SymbolPreferences}. |
|
260 |
*/ |
|
261 |
void resetDefaultSymbolFont(); |
|
262 |
|
|
263 |
/** |
|
264 |
* @deprecated to be removed in gvSIG 2.0 |
|
265 |
* @see {@link SymbolPreferences}. |
|
266 |
*/ |
|
267 |
String getSymbolLibraryPath(); |
|
268 |
|
|
269 |
/** |
|
270 |
* @deprecated to be removed in gvSIG 2.0 |
|
271 |
* @see {@link SymbolPreferences}. |
|
272 |
*/ |
|
273 |
void setSymbolLibraryPath(String symbolLibraryPath); |
|
274 |
|
|
275 |
/** |
|
276 |
* @deprecated to be removed in gvSIG 2.0 |
|
277 |
* @see {@link SymbolPreferences}. |
|
278 |
*/ |
|
279 |
void resetSymbolLibraryPath(); |
|
280 |
|
|
281 |
|
|
282 |
/** |
|
283 |
* @deprecated to be removed in gvSIG 2.0 @see {@link SymbolManager} |
|
284 |
*/ |
|
285 |
ISymbol createSymbol(String symbolName) throws MapContextRuntimeException; |
|
286 |
|
|
287 |
/** |
|
288 |
* @deprecated to be removed in gvSIG 2.0 @see {@link SymbolManager} |
|
289 |
*/ |
|
290 |
ISymbol createSymbol(int shapeType) throws MapContextRuntimeException; |
|
291 |
|
|
292 |
/** |
|
293 |
* @deprecated to be removed in gvSIG 2.0 @see {@link SymbolManager} |
|
294 |
*/ |
|
295 |
ISymbol createSymbol(String symbolName, Color color) |
|
296 |
throws MapContextRuntimeException; |
|
297 |
|
|
298 |
/** |
|
299 |
* @deprecated to be removed in gvSIG 2.0 @see {@link SymbolManager} |
|
300 |
*/ |
|
301 |
ISymbol createSymbol(int shapeType, Color color) |
|
302 |
throws MapContextRuntimeException; |
|
303 |
|
|
304 |
/** |
|
305 |
* @deprecated to be removed in gvSIG 2.0 @see {@link SymbolManager} |
|
306 |
*/ |
|
307 |
IMultiLayerSymbol createMultiLayerSymbol(String symbolName) |
|
308 |
throws MapContextRuntimeException; |
|
309 |
|
|
310 |
/** |
|
311 |
* @deprecated to be removed in gvSIG 2.0 @see {@link SymbolManager} |
|
312 |
*/ |
|
313 |
IMultiLayerSymbol createMultiLayerSymbol(int shapeType) |
|
314 |
throws MapContextRuntimeException; |
|
315 |
|
|
316 |
/** |
|
317 |
* @deprecated to be removed in gvSIG 2.0 @see {@link SymbolManager} |
|
318 |
*/ |
|
319 |
void registerSymbol(String symbolName, Class symbolClass) |
|
320 |
throws MapContextRuntimeException; |
|
321 |
|
|
322 |
/** |
|
323 |
* @deprecated to be removed in gvSIG 2.0 @see {@link SymbolManager} |
|
324 |
*/ |
|
325 |
void registerSymbol(String symbolName, int[] shapeTypes, Class symbolClass) |
|
326 |
throws MapContextException; |
|
327 |
|
|
328 |
/** |
|
329 |
* @deprecated to be removed in gvSIG 2.0 @see {@link SymbolManager} |
|
330 |
*/ |
|
331 |
void registerMultiLayerSymbol(String symbolName, Class symbolClass) |
|
332 |
throws MapContextRuntimeException; |
|
333 |
|
|
334 |
/** |
|
335 |
* @deprecated to be removed in gvSIG 2.0 @see {@link SymbolManager} |
|
336 |
*/ |
|
337 |
void registerMultiLayerSymbol(String symbolName, int[] shapeTypes, |
|
338 |
Class symbolClass) throws MapContextRuntimeException; |
|
339 |
|
|
340 |
/** |
|
341 |
* @deprecated to be removed in gvSIG 2.0 @see {@link SymbolManager} |
|
342 |
*/ |
|
343 |
IWarningSymbol getWarningSymbol(String message, String symbolDesc, |
|
344 |
int symbolDrawExceptionType) throws MapContextRuntimeException; |
|
345 |
|
|
346 |
/** |
|
347 |
* It returns the legend associated with a {@link DataStore}. |
|
348 |
* If the legend doesn't exist it returns <code>null</code>. |
|
349 |
* @param dataStore |
|
350 |
* the store that could have a legend. |
|
351 |
* @return |
|
352 |
* the legend or <code>null</code>. |
|
353 |
*/ |
|
354 |
ILegend getLegend(DataStore dataStore); |
|
355 |
|
|
356 |
/** |
|
357 |
* It returns the labeling strategy associated with a {@link DataStore}. |
|
358 |
* If the labeling strategy doesn't exist it returns <code>null</code>. |
|
359 |
* @param dataStore |
|
360 |
* the store that could have a labeling strategy. |
|
361 |
* @return |
|
362 |
* the labeling strategy or <code>null</code>. |
|
363 |
*/ |
|
364 |
ILabelingStrategy getLabelingStrategy(DataStore dataStore); |
|
365 |
|
|
366 |
|
|
367 |
void registerIconLayer(String store, String iconName); |
|
368 |
|
|
369 |
String getIconLayer(DataStore store); |
|
370 |
|
|
371 |
// TODO: |
|
372 |
// DynObjectModel getFeatureTypeUIModel(DataStore store, |
|
373 |
// FeatureType featureType); |
|
374 |
|
|
375 |
/** |
|
376 |
* Returns the default CRS. |
|
377 |
* This is NOT taken from the app |
|
378 |
* preferences because this is a library. It is a |
|
379 |
* "hard-coded" default CRS, used as a last resort. |
|
380 |
* @return the default CRS |
|
381 |
*/ |
|
382 |
IProjection getDefaultCRS(); |
|
383 |
} |
tags/v2_0_0_Build_2056/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/SelectedZoomVisitor.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.fmap.mapcontext; |
|
42 |
|
|
43 |
import org.gvsig.fmap.dal.DataSet; |
|
44 |
import org.gvsig.fmap.dal.feature.Feature; |
|
45 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
|
46 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
47 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
48 |
import org.gvsig.fmap.mapcontext.layers.operations.LayersVisitor; |
|
49 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
|
50 |
import org.gvsig.tools.exception.BaseException; |
|
51 |
import org.gvsig.tools.visitor.NotSupportedOperationException; |
|
52 |
import org.gvsig.tools.visitor.Visitable; |
|
53 |
import org.gvsig.tools.visitor.Visitor; |
|
54 |
|
|
55 |
|
|
56 |
/** |
|
57 |
* Visitor de zoom a lo seleccionado. |
|
58 |
* |
|
59 |
* @author Vicente Caballero Navarro |
|
60 |
*/ |
|
61 |
public class SelectedZoomVisitor implements LayersVisitor, Visitor { |
|
62 |
private Envelope rectangle = null; |
|
63 |
|
|
64 |
/** |
|
65 |
* Devuelve el Extent de los shapes seleccionados, y si no hay ning?n shape |
|
66 |
* seleccionado devuelve null. |
|
67 |
* |
|
68 |
* @return Extent de los shapes seleccionados. |
|
69 |
*/ |
|
70 |
public Envelope getSelectBound() { |
|
71 |
return rectangle; |
|
72 |
} |
|
73 |
|
|
74 |
public String getProcessDescription() { |
|
75 |
return "Defining rectangle to zoom from selected geometries"; |
|
76 |
} |
|
77 |
|
|
78 |
public void visit(Feature feature) throws BaseException { |
|
79 |
if (rectangle == null) { |
|
80 |
rectangle = (feature.getDefaultGeometry()).getEnvelope(); |
|
81 |
} else { |
|
82 |
rectangle.add((feature.getDefaultGeometry()) |
|
83 |
.getEnvelope()); |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
public void visit(FeatureReference featureRefence) throws BaseException { |
|
88 |
this.visit(featureRefence.getFeature()); |
|
89 |
} |
|
90 |
|
|
91 |
public void visit(Object obj) throws BaseException { |
|
92 |
if (obj instanceof FeatureReference) { |
|
93 |
this.visit((FeatureReference) obj); |
|
94 |
return; |
|
95 |
} |
|
96 |
if (obj instanceof Feature) { |
|
97 |
this.visit((Feature) obj); |
|
98 |
return; |
|
99 |
} |
|
100 |
if (obj instanceof FLayer) { |
|
101 |
this.visit((FLayer) obj); |
|
102 |
return; |
|
103 |
} |
|
104 |
|
|
105 |
throw new NotSupportedOperationException(this, obj); |
|
106 |
} |
|
107 |
|
|
108 |
public void visit(FLayer layer) throws BaseException { |
|
109 |
if (!(layer instanceof SingleLayer)) { |
|
110 |
return; |
|
111 |
} else if (!layer.isActive()) { |
|
112 |
return; |
|
113 |
} |
|
114 |
DataSet selection = ((SingleLayer) layer).getDataStore() |
|
115 |
.getSelection(); |
|
116 |
|
|
117 |
if (selection instanceof Visitable) { |
|
118 |
((Visitable) selection).accept(this); |
|
119 |
} |
|
120 |
} |
|
121 |
|
|
122 |
|
|
123 |
} |
tags/v2_0_0_Build_2056/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/Record.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.fmap.mapcontext; |
|
42 |
|
|
43 |
public interface Record { |
|
44 |
int getFieldCount() ; |
|
45 |
|
|
46 |
String getFieldName(int index) ; |
|
47 |
|
|
48 |
String getFieldValue(int index) ; |
|
49 |
} |
tags/v2_0_0_Build_2056/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/ViewPort.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib��ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.fmap.mapcontext; |
|
42 |
|
|
43 |
import java.awt.Color; |
|
44 |
import java.awt.Dimension; |
|
45 |
import java.awt.Toolkit; |
|
46 |
import java.awt.geom.AffineTransform; |
|
47 |
import java.awt.geom.NoninvertibleTransformException; |
|
48 |
import java.awt.geom.Point2D; |
|
49 |
import java.awt.geom.Rectangle2D; |
|
50 |
import java.util.ArrayList; |
|
51 |
|
|
52 |
import org.cresques.cts.GeoCalc; |
|
53 |
import org.cresques.cts.IProjection; |
|
54 |
import org.cresques.cts.UTM; |
|
55 |
import org.slf4j.Logger; |
|
56 |
import org.slf4j.LoggerFactory; |
|
57 |
|
|
58 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
59 |
import org.gvsig.fmap.geom.Geometry; |
|
60 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
61 |
import org.gvsig.fmap.geom.GeometryManager; |
|
62 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
|
63 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
64 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
65 |
import org.gvsig.fmap.geom.primitive.Point; |
|
66 |
import org.gvsig.fmap.mapcontext.events.ColorEvent; |
|
67 |
import org.gvsig.fmap.mapcontext.events.ExtentEvent; |
|
68 |
import org.gvsig.fmap.mapcontext.events.ProjectionEvent; |
|
69 |
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener; |
|
70 |
import org.gvsig.timesupport.Time; |
|
71 |
import org.gvsig.tools.ToolsLocator; |
|
72 |
import org.gvsig.tools.dynobject.DynStruct; |
|
73 |
import org.gvsig.tools.lang.Cloneable; |
|
74 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
75 |
import org.gvsig.tools.persistence.Persistent; |
|
76 |
import org.gvsig.tools.persistence.PersistentState; |
|
77 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
78 |
import org.gvsig.tools.util.Callable; |
|
79 |
|
|
80 |
/** |
|
81 |
* <p> |
|
82 |
* <code>ViewPort</code> class represents the logic needed to transform a |
|
83 |
* rectangular area of a map to the available area in screen to display it. |
|
84 |
* </p> |
|
85 |
* |
|
86 |
* <p> |
|
87 |
* Includes an affine transformation, between the rectangular area selected of |
|
88 |
* the external map, in its own <i>map coordinates</i>, to the rectangular area |
|
89 |
* available of a view in <i>screen coordinates</i>. |
|
90 |
* </p> |
|
91 |
* |
|
92 |
* <p> |
|
93 |
* Elements: |
|
94 |
* <ul> |
|
95 |
* <li><i>extent</i>: the area selected of the map, in <i>map coordinates</i>. |
|
96 |
* <li><i>imageSize</i>: width and height in pixels (<i>screen coordinates</i>) |
|
97 |
* of the area available in screen to display the area selected of the map. |
|
98 |
* <li><i>adjustedExtent</i>: the area selected must be an scale of |
|
99 |
* <i>imageSize</i>.<br> |
|
100 |
* This implies adapt the extent, preserving and centering it, and adding around |
|
101 |
* the needed area to fill all the image size. That added area will be extracted |
|
102 |
* from the original map, wherever exists, and filled with the background color |
|
103 |
* wherever not. |
|
104 |
* <li><i>scale</i>: the scale between the adjusted extent and the image size. |
|
105 |
* <li><i>backColor</i>: the default background color in the view, if there is |
|
106 |
* no map. |
|
107 |
* <li><i>trans</i>: the affine transformation. |
|
108 |
* <li><i>proj</i>: map projection used in this view. |
|
109 |
* <li><i>distanceUnits</i>: distance measurement units, of data in screen. |
|
110 |
* <li><i>mapUnits</i>: measurement units, of data in map. |
|
111 |
* <li><i>extents</i>: an {@link ExtentHistory ExtentHistory} with the last |
|
112 |
* previous extents. |
|
113 |
* <li><i>offset</i>: position in pixels of the available rectangular area, |
|
114 |
* where start drawing the map. |
|
115 |
* <li><i>dist1pixel</i>: the distance in <i>world coordinates</i> equivalent to |
|
116 |
* 1 pixel in the view with the current extent. |
|
117 |
* <li><i>dist3pixel</i>: the distance in <i>world coordinates</i> equivalent to |
|
118 |
* 3 pixels in the view with the current extent. |
|
119 |
* <li><i>listeners</i>: list with the {@link ViewPortListener ViewPortListener} |
|
120 |
* registered. |
|
121 |
* </ul> |
|
122 |
* </p> |
|
123 |
* |
|
124 |
* @author Vicente Caballero Navarro |
|
125 |
*/ |
|
126 |
public class ViewPort implements Persistent, Cloneable { |
|
127 |
|
|
128 |
private static final String FIELD_DISTANCE_AREA = "distanceArea"; |
|
129 |
private static final String FIELD_IMAGE_SIZE = "imageSize"; |
|
130 |
private static final String FIELD_PROJ = "proj"; |
|
131 |
private static final String FIELD_OFFSET = "offset"; |
|
132 |
private static final String FIELD_MAP_UNITS = "mapUnits"; |
|
133 |
private static final String FIELD_EXTENT = "extent"; |
|
134 |
private static final String FIELD_EXTENTS = "extents"; |
|
135 |
private static final String FIELD_DISTANCE_UNITS = "distanceUnits"; |
|
136 |
private static final String FIELD_DIST3PIXEL = "dist3pixel"; |
|
137 |
private static final String FIELD_DIST1PIXEL = "dist1pixel"; |
|
138 |
private static final String FIELD_CLIP = "clip"; |
|
139 |
private static final String FIELD_BACK_COLOR = "backColor"; |
|
140 |
private static final String FIELD_ADJUSTED_EXTENT = "adjustedExtent"; |
|
141 |
|
|
142 |
private static final GeometryManager geomManager = |
|
143 |
GeometryLocator.getGeometryManager(); |
|
144 |
private static final Logger logger = |
|
145 |
LoggerFactory.getLogger(ViewPort.class); |
|
146 |
|
|
147 |
/** |
|
148 |
* <p> |
|
149 |
* Screen resolution in <i>dots-per-inch</i>. Useful to calculate the |
|
150 |
* geographic scale of the view. |
|
151 |
* </p> |
|
152 |
* |
|
153 |
* @see Toolkit#getScreenResolution() |
|
154 |
* @see #getScale() |
|
155 |
*/ |
|
156 |
private static int dpi = java.awt.Toolkit.getDefaultToolkit() |
|
157 |
.getScreenResolution(); |
|
158 |
|
|
159 |
/** |
|
160 |
* <p> |
|
161 |
* Area selected by user using some tool. |
|
162 |
* </p> |
|
163 |
* |
|
164 |
* <p> |
|
165 |
* When the zoom changes (for instance when using the zoom in or zoom out |
|
166 |
* tools, but also zooming to a selected feature or shape) the extent that |
|
167 |
* covers that area is the value returned by this method. It is not the |
|
168 |
* actual area shown in the view because it does not care about the aspect |
|
169 |
* ratio of the available area. However, any part of the real world |
|
170 |
* contained in this extent is shown in the view. |
|
171 |
* </p> |
|
172 |
* <p> |
|
173 |
* Probably this is not what you are looking for. If you are looking for the |
|
174 |
* complete extent currently shown, you must use |
|
175 |
* {@linkplain #getAdjustedExtent()} method which returns the extent that |
|
176 |
* contains this one but regarding the current view's aspect ratio. |
|
177 |
* </p> |
|
178 |
* |
|
179 |
* @see #getExtent() |
|
180 |
* @see #setEnvelope(Envelope) |
|
181 |
*/ |
|
182 |
protected Rectangle2D extent; |
|
183 |
|
|
184 |
protected Time time; |
|
185 |
|
|
186 |
/** |
|
187 |
* <p> |
|
188 |
* Location and dimensions of the extent adjusted to the image size. |
|
189 |
* </p> |
|
190 |
* |
|
191 |
* @see #getAdjustedExtent() |
|
192 |
*/ |
|
193 |
protected Rectangle2D adjustedExtent; |
|
194 |
|
|
195 |
/** |
|
196 |
* Draw version of the context. It's used for know when de componend has |
|
197 |
* changed any visualization property |
|
198 |
* |
|
199 |
* @see getDrawVersion |
|
200 |
* @see updateDrawVersion |
|
201 |
*/ |
|
202 |
private long drawVersion = 0L; |
|
203 |
|
|
204 |
/** |
|
205 |
* <p> |
|
206 |
* History with the last extents of the view. |
|
207 |
* </p> |
|
208 |
* |
|
209 |
* @see #setPreviousExtent() |
|
210 |
* @see #getExtents() |
|
211 |
*/ |
|
212 |
protected ExtentHistory extents = new ExtentHistory(); |
|
213 |
|
|
214 |
/** |
|
215 |
* <p> |
|
216 |
* Size in <i>screen coordinates</i> of the rectangle where the image is |
|
217 |
* displayed. |
|
218 |
* </p> |
|
219 |
* <p> |
|
220 |
* Used by {@linkplain #calculateAffineTransform()} to calculate:<br> |
|
221 |
* |
|
222 |
* <ul> |
|
223 |
* <li>The new {@link #scale scale} . |
|
224 |
* <li>The new {@link #adjustedExtent adjustableExtent} . |
|
225 |
* <li>The new {@link #trans trans} . |
|
226 |
* <li>The new real world coordinates equivalent to 1 pixel ( |
|
227 |
* {@link #dist1pixel dist1pixel}) . |
|
228 |
* <li>The new real world coordinates equivalent to 3 pixels ( |
|
229 |
* {@link #dist3pixel dist3pixel}) . |
|
230 |
* </ul> |
|
231 |
* </p> |
|
232 |
* |
|
233 |
* @see #getImageSize() |
|
234 |
* @see #getImageHeight() |
|
235 |
* @see #getImageWidth() |
|
236 |
* @see #setImageSize(Dimension) |
|
237 |
*/ |
|
238 |
private Dimension imageSize; |
|
239 |
|
|
240 |
/** |
|
241 |
* <p> |
|
242 |
* the affine transformation between the {@link #extent extent} in <i>map 2D |
|
243 |
* coordinates</i> to the image area in the screen, in <i>screen 2D |
|
244 |
* coordinates</i> (pixels). |
|
245 |
* </p> |
|
246 |
* |
|
247 |
* @see AffineTransform |
|
248 |
* |
|
249 |
* @see #getAffineTransform() |
|
250 |
* @see #setAffineTransform(AffineTransform) |
|
251 |
* @see #calculateAffineTransform() |
|
252 |
*/ |
|
253 |
private AffineTransform trans = new AffineTransform(); |
|
254 |
|
|
255 |
/** |
|
256 |
* <p> |
|
257 |
* Measurement unit used for measuring distances and displaying information. |
|
258 |
* </p> |
|
259 |
* |
|
260 |
* @see #getDistanceUnits() |
|
261 |
* @see #setDistanceUnits(int) |
|
262 |
*/ |
|
263 |
private int distanceUnits = 1; |
|
264 |
/** |
|
265 |
* <p> |
|
266 |
* Measurement unit used for measuring areas and displaying information. |
|
267 |
* </p> |
|
268 |
* |
|
269 |
* @see #getDistanceArea() |
|
270 |
* @see #setDistanceArea(int) |
|
271 |
*/ |
|
272 |
private int distanceArea = 1; |
|
273 |
/** |
|
274 |
* <p> |
|
275 |
* Measurement unit used by this view port for the map. |
|
276 |
* </p> |
|
277 |
* |
|
278 |
* @see #getMapUnits() |
|
279 |
* @see #setMapUnits(int) |
|
280 |
*/ |
|
281 |
private int mapUnits = 1; |
|
282 |
|
|
283 |
/** |
|
284 |
* <p> |
|
285 |
* Array with the {@link ViewPortListener ViewPortListener}s registered to |
|
286 |
* this view port. |
|
287 |
* </p> |
|
288 |
* |
|
289 |
* @see #addViewPortListener(ViewPortListener) |
|
290 |
* @see #removeViewPortListener(ViewPortListener) |
|
291 |
*/ |
|
292 |
private ArrayList listeners = new ArrayList(); |
|
293 |
|
|
294 |
/** |
|
295 |
* <p> |
|
296 |
* The offset is the position where start drawing the map. |
|
297 |
* </p> |
|
298 |
* <p> |
|
299 |
* The offset of a <a href="http://www.gvsig.gva.es/">gvSIG</a>'s |
|
300 |
* <i>View</i> is always (0, 0) because the drawing area fits with the full |
|
301 |
* window area. But in a <a href="http://www.gvsig.gva.es/">gvSIG</a>'s |
|
302 |
* <i>Layout</i> it's up to the place where the <code>FFrameView</code> is |
|
303 |
* located. |
|
304 |
* </p> |
|
305 |
* |
|
306 |
* @see #getOffset() |
|
307 |
* @see #setOffset(Point2D) |
|
308 |
*/ |
|
309 |
private Point2D offset = new Point2D.Double(0, 0); |
|
310 |
|
|
311 |
/** |
|
312 |
* <p> |
|
313 |
* Clipping area. |
|
314 |
* </p> |
|
315 |
*/ |
|
316 |
// private Rectangle2D clip; |
|
317 |
|
|
318 |
/** |
|
319 |
* <p> |
|
320 |
* Background color of this view. |
|
321 |
* </p> |
|
322 |
* |
|
323 |
* @see #getBackColor() |
|
324 |
* @see #setBackColor(Color) |
|
325 |
*/ |
|
326 |
private Color backColor = null; // Color.WHITE; |
|
327 |
|
|
328 |
/** |
|
329 |
* <p> |
|
330 |
* Information about the map projection used in this view. |
|
331 |
* </p> |
|
332 |
* |
|
333 |
* @see #getProjection() |
|
334 |
* @see #setProjection(IProjection) |
|
335 |
*/ |
|
336 |
private IProjection proj; |
|
337 |
|
|
338 |
/** |
|
339 |
* <p> |
|
340 |
* Represents the distance in <i>world coordinates</i> equivalent to 1 pixel |
|
341 |
* in the view with the current extent. |
|
342 |
* </p> |
|
343 |
* |
|
344 |
* @see #getDist1pixel() |
|
345 |
* @see #setDist1pixel(double) |
|
346 |
*/ |
|
347 |
private double dist1pixel; |
|
348 |
|
|
349 |
/** |
|
350 |
* <p> |
|
351 |
* Represents the distance in <i>world coordinates</i> equivalent to 3 |
|
352 |
* pixels in the view with the current extent. |
|
353 |
* </p> |
|
354 |
* |
|
355 |
* @see #getDist3pixel() |
|
356 |
* @see #setDist3pixel(double) |
|
357 |
*/ |
|
358 |
private double dist3pixel; |
|
359 |
|
|
360 |
/** |
|
361 |
* <p> |
|
362 |
* Ratio between the size of <code>imageSize</code> and <code>extent</code>: |
|
363 |
* <br> |
|
364 |
* <i> |
|
365 |
* |
|
366 |
* <pre> |
|
367 |
* min{(imageSize.getHeight()/extent.getHeight(), imageSize.getWidth()/extent.getWidth())} |
|
368 |
* </pre> |
|
369 |
* |
|
370 |
* </i> |
|
371 |
* </p> |
|
372 |
*/ |
|
373 |
private double scale; |
|
374 |
|
|
375 |
/** |
|
376 |
* <p> |
|
377 |
* Clipping area. |
|
378 |
* </p> |
|
379 |
* |
|
380 |
* @see #setClipRect(Rectangle2D) |
|
381 |
*/ |
|
382 |
private Rectangle2D cliprect; |
|
383 |
|
|
384 |
/** |
|
385 |
* <p> |
|
386 |
* Enables or disables the <i>"adjustable extent"</i> mode. |
|
387 |
* </p> |
|
388 |
* |
|
389 |
* <p> |
|
390 |
* When calculates the affine transform, if |
|
391 |
* <ul> |
|
392 |
* <li><i>enabled</i>: the new <code>adjustedExtent</code> will have the (X, |
|
393 |
* Y) coordinates of the <code>extent</code> and an area that will be an |
|
394 |
* scale of the image size. That area will have different height or width |
|
395 |
* (not both) of the extent according the least ratio (height or width) in |
|
396 |
* |
|
397 |
* <pre> |
|
398 |
* image.size/extent.size" |
|
399 |
* </pre>. |
|
400 |
* <li><i>disabled</i>: the new <code>adjustedExtent</code> will be like |
|
401 |
* <code>extent</code>. |
|
402 |
* </ul> |
|
403 |
* </p> |
|
404 |
* |
|
405 |
* @see #setAdjustable(boolean) |
|
406 |
*/ |
|
407 |
private boolean adjustableExtent = true; |
|
408 |
|
|
409 |
public ViewPort() { |
|
410 |
|
|
411 |
} |
|
412 |
|
|
413 |
/** |
|
414 |
* <p> |
|
415 |
* Creates a new view port with the information of the projection in |
|
416 |
* <code>proj</code> argument, and default configuration: |
|
417 |
* </p> |
|
418 |
* <p> |
|
419 |
* <ul> |
|
420 |
* <li><i><code>distanceUnits</code></i> = meters |
|
421 |
* <li><i><code>mapUnits</code></i> = meters |
|
422 |
* <li><i><code>backColor</code></i> = <i>undefined</i> |
|
423 |
* <li><i><code>offset</code></i> = <code>new Point2D.Double(0, 0);</code> |
|
424 |
* </ul> |
|
425 |
* </p> |
|
426 |
* |
|
427 |
* @param proj |
|
428 |
* information of the projection for this view port |
|
429 |
*/ |
|
430 |
public ViewPort(IProjection proj) { |
|
431 |
// Por defecto |
|
432 |
this.proj = proj; |
|
433 |
} |
|
434 |
|
|
435 |
/** |
|
436 |
* <p> |
|
437 |
* Changes the status of the <i>"adjustable extent"</i> option to enabled or |
|
438 |
* disabled. |
|
439 |
* </p> |
|
440 |
* |
|
441 |
* <p> |
|
442 |
* If view port isn't adjustable, won't bear in mind the aspect ratio of the |
|
443 |
* available rectangular area to calculate the affine transform from the |
|
444 |
* original map in real coordinates. (Won't scale the image to adapt it to |
|
445 |
* the available rectangular area). |
|
446 |
* </p> |
|
447 |
* |
|
448 |
* @param boolean the boolean to be set |
|
449 |
*/ |
|
450 |
public void setAdjustable(boolean adjustable) { |
|
451 |
if (adjustable == adjustableExtent) { |
|
452 |
return; |
|
453 |
} |
|
454 |
adjustableExtent = adjustable; |
|
455 |
this.updateDrawVersion(); |
|
456 |
} |
|
457 |
|
|
458 |
/** |
|
459 |
* <p> |
|
460 |
* Appends the specified {@link ViewPortListener ViewPortListener} listener |
|
461 |
* if weren't. |
|
462 |
* </p> |
|
463 |
* |
|
464 |
* @param arg0 |
|
465 |
* the listener to add |
|
466 |
* |
|
467 |
* @return <code>true</code> if has been added successfully |
|
468 |
* |
|
469 |
* @see #removeViewPortListener(ViewPortListener) |
|
470 |
*/ |
|
471 |
public boolean addViewPortListener(ViewPortListener arg0) { |
|
472 |
if (!listeners.contains(arg0)) { |
|
473 |
return listeners.add(arg0); |
|
474 |
} |
|
475 |
return false; |
|
476 |
} |
|
477 |
|
|
478 |
/** |
|
479 |
* <p> |
|
480 |
* Removes the specified {@link ViewPortListener ViewPortListener} listener, |
|
481 |
* if existed. |
|
482 |
* </p> |
|
483 |
* |
|
484 |
* @param arg0 |
|
485 |
* the listener to remove |
|
486 |
* |
|
487 |
* @return <code>true</code> if the contained the specified listener. |
|
488 |
* |
|
489 |
* @see #addViewPortListener(ViewPortListener) |
|
490 |
*/ |
|
491 |
public boolean removeViewPortListener(ViewPortListener arg0) { |
|
492 |
return listeners.remove(arg0); |
|
493 |
} |
|
494 |
|
|
495 |
/** |
|
496 |
* <p> |
|
497 |
* Converts and returns the distance <code>d</code>, that is in <i>map |
|
498 |
* coordinates</i> to <i>screen coordinates</i> using a <i>delta |
|
499 |
* transform</i> with the transformation affine information in the |
|
500 |
* {@link #trans #trans} attribute. |
|
501 |
* </p> |
|
502 |
* |
|
503 |
* @param d |
|
504 |
* distance in <i>map coordinates</i> |
|
505 |
* |
|
506 |
* @return distance equivalent in <i>screen coordinates</i> |
|
507 |
* |
|
508 |
* @see #toMapDistance(int) |
|
509 |
* @see AffineTransform#deltaTransform(Point2D, Point2D)S |
|
510 |
*/ |
|
511 |
public int fromMapDistance(double d) { |
|
512 |
Point2D.Double pWorld = new Point2D.Double(1, 1); |
|
513 |
Point2D.Double pScreen = new Point2D.Double(); |
|
514 |
|
|
515 |
try { |
|
516 |
trans.deltaTransform(pWorld, pScreen); |
|
517 |
} catch (Exception e) { |
|
518 |
System.err.print(e.getMessage()); |
|
519 |
} |
|
520 |
|
|
521 |
return (int) (d * pScreen.x); |
|
522 |
} |
|
523 |
|
|
524 |
/** |
|
525 |
* <p> |
|
526 |
* Converts and returns the 2D point <code>(x,y)</code>, that is in <i>map |
|
527 |
* coordinates</i> to <i>screen coordinates</i> (pixels) using the affine |
|
528 |
* transformation in the {@link #trans #trans} attribute. |
|
529 |
* </p> |
|
530 |
* |
|
531 |
* @param x |
|
532 |
* the <code>x</code> <i>map coordinate</i> of a 2D point |
|
533 |
* @param y |
|
534 |
* the <code>y</code> <i>map coordinate</i> of a 2D point |
|
535 |
* |
|
536 |
* @return 2D point equivalent in <i>screen coordinates</i> (pixels) |
|
537 |
* |
|
538 |
* @see #fromMapPoint(Point2D) |
|
539 |
* @see AffineTransform#transform(Point2D, Point2D) |
|
540 |
*/ |
|
541 |
public Point2D fromMapPoint(double x, double y) { |
|
542 |
Point2D.Double pWorld = new Point2D.Double(x, y); |
|
543 |
Point2D.Double pScreen = new Point2D.Double(); |
|
544 |
|
|
545 |
try { |
|
546 |
trans.transform(pWorld, pScreen); |
|
547 |
} catch (Exception e) { |
|
548 |
System.err.print(e.getMessage()); |
|
549 |
} |
|
550 |
|
|
551 |
return pScreen; |
|
552 |
} |
|
553 |
|
|
554 |
/** |
|
555 |
* <p> |
|
556 |
* Converts and returns the 2D point argument, that is in <i>map |
|
557 |
* coordinates</i> to <i>screen coordinates</i> (pixels) using the affine |
|
558 |
* transformation in the {@link #trans #trans} attribute. |
|
559 |
* </p> |
|
560 |
* |
|
561 |
* @param point |
|
562 |
* the 2D point in <i>map coordinates</i> |
|
563 |
* |
|
564 |
* @return 2D point equivalent in <i>screen coordinates</i> (pixels) |
|
565 |
* |
|
566 |
* @see #toMapPoint(Point2D) |
|
567 |
* @see #fromMapPoint(double, double) |
|
568 |
*/ |
|
569 |
public Point2D fromMapPoint(Point2D point) { |
|
570 |
return fromMapPoint(point.getX(), point.getY()); |
|
571 |
} |
|
572 |
|
|
573 |
/** |
|
574 |
* <p> |
|
575 |
* Converts and returns the 2D point <code>(x,y)</code>, that is in |
|
576 |
* <i>screen coordinates</i> (pixels) to <i>map coordinates</i> using the |
|
577 |
* affine transformation in the {@link #trans #trans} attribute. |
|
578 |
* </p> |
|
579 |
* |
|
580 |
* @param x |
|
581 |
* the <code>x</code> <i>screen coordinate</i> of a 2D point |
|
582 |
* @param y |
|
583 |
* the <code>y</code> <i>screen coordinate</i> of a 2D point |
|
584 |
* |
|
585 |
* @return 2D point equivalent in <i>map coordinates</i> |
|
586 |
* |
|
587 |
* @see #toMapPoint(Point2D) |
|
588 |
* @see #fromMapPoint(double, double) |
|
589 |
* @deprecated use {@link #convertToMapPoint(int, int)} |
|
590 |
*/ |
|
591 |
public Point2D toMapPoint(int x, int y) { |
|
592 |
Point2D pScreen = new Point2D.Double(x, y); |
|
593 |
|
|
594 |
return toMapPoint(pScreen); |
|
595 |
} |
|
596 |
|
|
597 |
/** |
|
598 |
* <p> |
|
599 |
* Converts and returns the {@link Rectangle2D Rectangle2D}, that is in |
|
600 |
* <i>screen coordinates</i> (pixels) to <i>map coordinates</i> using |
|
601 |
* {@linkplain #toMapDistance(int)}, and {@linkplain #toMapPoint(int, int)}. |
|
602 |
* </p> |
|
603 |
* |
|
604 |
* @param r |
|
605 |
* the 2D rectangle in <i>screen coordinates</i> (pixels) |
|
606 |
* @return 2D rectangle equivalent in <i>map coordinates</i> |
|
607 |
* |
|
608 |
* @see #fromMapRectangle(Rectangle2D) |
|
609 |
* @see #toMapDistance(int) |
|
610 |
* @see #toMapPoint(int, int) |
|
611 |
*/ |
|
612 |
public Rectangle2D toMapRectangle(Rectangle2D r) { |
|
613 |
Rectangle2D rect = new Rectangle2D.Double(); |
|
614 |
Point2D p1 = toMapPoint((int) r.getX(), (int) r.getY()); |
|
615 |
Point2D p2 = toMapPoint((int) r.getMaxX(), (int) r.getMaxY()); |
|
616 |
rect.setFrameFromDiagonal(p1, p2); |
|
617 |
return rect; |
|
618 |
} |
|
619 |
|
|
620 |
/** |
|
621 |
* <p> |
|
622 |
* Converts and returns the distance <code>d</code>, that is in <i>screen |
|
623 |
* coordinates</i> to <i>map coordinates</i> using the transformation affine |
|
624 |
* information in the {@link #trans #trans} attribute. |
|
625 |
* </p> |
|
626 |
* |
|
627 |
* @param d |
|
628 |
* distance in pixels |
|
629 |
* |
|
630 |
* @return distance equivalent in <i>map coordinates</i> |
|
631 |
* |
|
632 |
* @see #fromMapDistance(double) |
|
633 |
* @see AffineTransform |
|
634 |
*/ |
|
635 |
public double toMapDistance(int d) { |
|
636 |
double dist = d / trans.getScaleX(); |
|
637 |
|
|
638 |
return dist; |
|
639 |
} |
|
640 |
|
|
641 |
/** |
|
642 |
* <p> |
|
643 |
* Converts and returns the 2D point argument, that is in <i>screen |
|
644 |
* coordinates</i> (pixels) to <i>map coordinates</i> using the inverse |
|
645 |
* affine transformation of the {@link #trans #trans} attribute. |
|
646 |
* </p> |
|
647 |
* |
|
648 |
* @param pScreen |
|
649 |
* the 2D point in <i>screen coordinates</i> (pixels) |
|
650 |
* |
|
651 |
* @return 2D point equivalent in <i>map coordinates</i> |
|
652 |
* |
|
653 |
* @see #toMapPoint(int, int) |
|
654 |
* @see AffineTransform#createInverse() |
|
655 |
* @see AffineTransform#transform(Point2D, Point2D) |
|
656 |
* @deprecated use {@link #convertToMapPoint(Point2D)} |
|
657 |
*/ |
|
658 |
public Point2D toMapPoint(Point2D pScreen) { |
|
659 |
Point2D.Double pWorld = new Point2D.Double(); |
|
660 |
AffineTransform at; |
|
661 |
|
|
662 |
try { |
|
663 |
at = trans.createInverse(); |
|
664 |
at.transform(pScreen, pWorld); |
|
665 |
} catch (NoninvertibleTransformException e) { |
|
666 |
throw new RuntimeException("Non invertible transform Exception", e); |
|
667 |
} |
|
668 |
|
|
669 |
return pWorld; |
|
670 |
} |
|
671 |
|
|
672 |
public Point convertToMapPoint(Point2D pScreen) { |
|
673 |
Point2D p = toMapPoint(pScreen); |
|
674 |
try { |
|
675 |
return geomManager.createPoint( |
|
676 |
p.getX(), |
|
677 |
p.getY(), |
|
678 |
Geometry.SUBTYPES.GEOM2D |
|
679 |
); |
|
680 |
} catch (CreateGeometryException e) { |
|
681 |
// FIXME: Use a most especific exception. |
|
682 |
throw new RuntimeException(e); |
|
683 |
} |
|
684 |
} |
|
685 |
|
|
686 |
public Point convertToMapPoint(int x, int y) { |
|
687 |
Point2D pScreen = new Point2D.Double(x, y); |
|
688 |
|
|
689 |
return convertToMapPoint(pScreen); |
|
690 |
} |
|
691 |
|
|
692 |
|
|
693 |
/** |
|
694 |
* <p> |
|
695 |
* Returns the real distance (in <i>world coordinates</i>) at the graphic |
|
696 |
* layers of two 2D points (in <i>map coordinates</i>) of the plane where is |
|
697 |
* selected the <i>extent</i>. |
|
698 |
* </p> |
|
699 |
* <p> |
|
700 |
* If the projection of this view is UTM, considers the Earth curvature. |
|
701 |
* </p> |
|
702 |
* |
|
703 |
* @param pt1 |
|
704 |
* a 2D point in <i>map coordinates</i> |
|
705 |
* @param pt2 |
|
706 |
* another 2D point in <i>map coordinates</i> |
|
707 |
* |
|
708 |
* @return the distance in meters between the two points 2D |
|
709 |
* |
|
710 |
* @see GeoCalcImpl#distanceVincenty(Point2D, Point2D) |
|
711 |
*/ |
|
712 |
public double distanceWorld(Point2D pt1, Point2D pt2) { |
|
713 |
double dist = -1; |
|
714 |
dist = pt1.distance(pt2); |
|
715 |
|
|
716 |
if ((proj != null) && !(proj instanceof UTM)) { |
|
717 |
dist = |
|
718 |
new GeoCalc(proj).distanceVincenty(proj.toGeo(pt1), |
|
719 |
proj.toGeo(pt2)); |
|
720 |
return dist; |
|
721 |
} |
|
722 |
return (dist * MapContext.getDistanceTrans2Meter()[getMapUnits()]); |
|
723 |
} |
|
724 |
|
|
725 |
/** |
|
726 |
* <p> |
|
727 |
* Sets as extent and adjusted extent of this view port, the previous. |
|
728 |
* Recalculating its parameters. |
|
729 |
* </p> |
|
730 |
* |
|
731 |
* @see #getExtents() |
|
732 |
* @see #calculateAffineTransform() |
|
733 |
* @deprecated use {@link ViewPort#setPreviousEnvelope()} |
|
734 |
*/ |
|
735 |
public void setPreviousExtent() { |
|
736 |
setPreviousEnvelope(); |
|
737 |
} |
|
738 |
|
|
739 |
/** |
|
740 |
* <p> |
|
741 |
* Sets as envelope and adjusted envelope of this view port, the previous. |
|
742 |
* Recalculating its parameters. |
|
743 |
* </p> |
|
744 |
* |
|
745 |
* @see #getExtents() |
|
746 |
* @see #calculateAffineTransform() |
|
747 |
*/ |
|
748 |
public void setPreviousEnvelope() { |
|
749 |
this.updateDrawVersion(); |
|
750 |
extent = extents.removePrev(); |
|
751 |
|
|
752 |
// Calcula la transformaci�n af�n |
|
753 |
calculateAffineTransform(); |
|
754 |
|
|
755 |
// Lanzamos los eventos de extent cambiado |
|
756 |
callExtentChanged(getAdjustedExtent()); |
|
757 |
} |
|
758 |
|
|
759 |
/** |
|
760 |
* <p> |
|
761 |
* Gets the area selected by user using some tool. |
|
762 |
* </p> |
|
763 |
* |
|
764 |
* <p> |
|
765 |
* When the zoom changes (for instance using the <i>zoom in</i> or <i>zoom |
|
766 |
* out</i> tools, but also zooming to a selected feature or shape) the |
|
767 |
* extent that covers that area is the value returned by this method. It is |
|
768 |
* not the actual area shown because it doesn't care about the aspect ratio |
|
769 |
* of the image size of the view. However, any part of the real world |
|
770 |
* contained in this extent is shown in the view. |
|
771 |
* </p> |
|
772 |
* |
|
773 |
* <p> |
|
774 |
* If you are looking for the complete extent currently shown, you must use |
|
775 |
* the {@linkplain #getAdjustedExtent()} method. |
|
776 |
* </p> |
|
777 |
* |
|
778 |
* @return the current extent |
|
779 |
* |
|
780 |
* @see #setEnvelope(Envelope) |
|
781 |
* @see #getAdjustedExtent() |
|
782 |
* @see #setPreviousExtent() |
|
783 |
* @see #getExtents() |
|
784 |
* |
|
785 |
* @deprecated use {@link ViewPort#getEnvelope()} |
|
786 |
*/ |
|
787 |
public Rectangle2D getExtent() { |
|
788 |
return extent; |
|
789 |
} |
|
790 |
|
|
791 |
/** |
|
792 |
* <p> |
|
793 |
* Gets the envelope selected by user using some tool. |
|
794 |
* </p> |
|
795 |
* |
|
796 |
* <p> |
|
797 |
* When the zoom changes (for instance using the <i>zoom in</i> or <i>zoom |
|
798 |
* out</i> tools, but also zooming to a selected feature or shape) the |
|
799 |
* envelope that covers that area is the value returned by this method. It |
|
800 |
* is not the actual envelope shown because it doesn't care about the aspect |
|
801 |
* ratio of the image size of the view. However, any part of the real world |
|
802 |
* contained in this envelope is shown in the view. |
|
803 |
* </p> |
|
804 |
* |
|
805 |
* <p> |
|
806 |
* If you are looking for the complete extent currently shown, you must use |
|
807 |
* the {@linkplain #getAdjustedEnvelope()} method. |
|
808 |
* </p> |
|
809 |
* |
|
810 |
* @return the current envelope |
|
811 |
* |
|
812 |
* @see #setEnvelope(Envelope) |
|
813 |
* @see #getAdjustedEnvelope() |
|
814 |
* @see #setPreviousEnvelope() |
|
815 |
* @see #getEnvelopes() |
|
816 |
*/ |
|
817 |
public Envelope getEnvelope() { |
|
818 |
if (this.extent == null) { |
|
819 |
return null; |
|
820 |
} |
|
821 |
try { |
|
822 |
return geomManager.createEnvelope(extent.getMinX(), |
|
823 |
extent.getMinY(), |
|
824 |
extent.getMaxX(), |
|
825 |
extent.getMaxY(), |
|
826 |
SUBTYPES.GEOM2D); |
|
827 |
// This class has to use Envelope instead of Rectangle2D. This catch |
|
828 |
// will disappear |
|
829 |
} catch (CreateEnvelopeException e) { |
|
830 |
logger.error("Error creating the envelope"); |
|
831 |
} |
|
832 |
return null; |
|
833 |
} |
|
834 |
|
|
835 |
/** |
|
836 |
* <p> |
|
837 |
* Changes the <i>extent</i> and <i>adjusted extent</i> of this view port:<br> |
|
838 |
* <ul> |
|
839 |
* <li>Stores the previous extent. |
|
840 |
* <li>Calculates the new extent using <code>r</code>: |
|
841 |
* |
|
842 |
* <pre> |
|
843 |
* extent = |
|
844 |
* new Rectangle2D.Double(r.getMinX() - 0.1, |
|
845 |
* r.getMinY() - 0.1, |
|
846 |
* r.getWidth() + 0.2, |
|
847 |
* r.getHeight() + 0.2); |
|
848 |
* </pre> |
|
849 |
* |
|
850 |
* <li>Executes {@linkplain #calculateAffineTransform()}: getting the new |
|
851 |
* scale, adjusted extent, affine transformation between map and screen |
|
852 |
* coordinates, the real world coordinates equivalent to 1 pixel, and the |
|
853 |
* real world coordinates equivalent to 3 pixels. |
|
854 |
* <li>Notifies all {@link ViewPortListener ViewPortListener} registered |
|
855 |
* that the extent has changed. |
|
856 |
* </ul> |
|
857 |
* </p> |
|
858 |
* |
|
859 |
* @param r |
|
860 |
* the new extent |
|
861 |
* |
|
862 |
* @see #getExtent() |
|
863 |
* @see #getExtents() |
|
864 |
* @see #calculateAffineTransform() |
|
865 |
* @see #setPreviousExtent() |
|
866 |
*/ |
|
867 |
public void setEnvelope(Envelope r) { |
|
868 |
Rectangle2D newExtent = null; |
|
869 |
// Esto comprueba que el extent no es de anchura o altura = "0" |
|
870 |
// y si es as� lo redimensiona. |
|
871 |
if (r != null) { |
|
872 |
if ((r.getMaximum(0) - r.getMinimum(0) == 0) |
|
873 |
|| (r.getMaximum(1) - r.getMinimum(1) == 0)) { |
|
874 |
newExtent = |
|
875 |
new Rectangle2D.Double(r.getMinimum(0) - 0.1, |
|
876 |
r.getMinimum(1) - 0.1, |
|
877 |
r.getMaximum(0) - r.getMinimum(0) + 0.2, |
|
878 |
r.getMaximum(1) - r.getMinimum(1) + 0.2); |
|
879 |
} else { |
|
880 |
newExtent = |
|
881 |
new Rectangle2D.Double(r.getMinimum(0), |
|
882 |
r.getMinimum(1), |
|
883 |
Math.abs(r.getMaximum(0) - r.getMinimum(0)), |
|
884 |
Math.abs(r.getMaximum(1) - r.getMinimum(1))); |
|
885 |
} |
|
886 |
} |
|
887 |
|
|
888 |
if (this.extent != null && this.extent.equals(newExtent)) { |
|
889 |
return; |
|
890 |
} |
|
891 |
if (extent != null) { |
|
892 |
extents.put(extent); |
|
893 |
} |
|
894 |
this.updateDrawVersion(); |
|
895 |
this.extent = newExtent; |
|
896 |
|
Also available in: Unified diff