root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / FMap.java @ 470
History | View | Annotate | Download (13.6 KB)
1 |
/* Generated by Together */
|
---|---|
2 |
package com.iver.cit.gvsig.fmap; |
3 |
|
4 |
import java.awt.Graphics2D; |
5 |
import java.awt.Toolkit; |
6 |
import java.awt.geom.Point2D; |
7 |
import java.awt.geom.Rectangle2D; |
8 |
import java.awt.image.BufferedImage; |
9 |
import java.util.ArrayList; |
10 |
import java.util.Iterator; |
11 |
import java.io.File; |
12 |
|
13 |
import org.cresques.cts.ICoordTrans; |
14 |
import org.cresques.cts.IProjection; |
15 |
import org.cresques.cts.ProjectionPool; |
16 |
import org.cresques.geo.Projected; |
17 |
|
18 |
import com.hardcode.driverManager.DriverLoadException; |
19 |
import com.hardcode.gdbms.engine.data.DriverException; |
20 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
21 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
22 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
23 |
import com.iver.cit.gvsig.fmap.layers.DifferentVersionException; |
24 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
25 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
26 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
27 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent; |
28 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener; |
29 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
30 |
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent; |
31 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
32 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
33 |
import com.iver.cit.gvsig.fmap.operations.QueriedPoint; |
34 |
import com.iver.cit.gvsig.fmap.operations.selection.Record; |
35 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
36 |
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
37 |
import com.iver.utiles.XMLEntity; |
38 |
|
39 |
|
40 |
/**
|
41 |
* DOCUMENT ME!
|
42 |
*
|
43 |
* @author Fernando Gonz?lez Cort?s
|
44 |
*/
|
45 |
public class FMap implements Projected { |
46 |
public static final double[] CHANGEM = { |
47 |
1000, 1, 0.01, 0.001, 1609.344, 0.9144, 0.3048, 0.0254 |
48 |
}; |
49 |
|
50 |
/** DOCUMENT ME! */
|
51 |
public static final double[] CHANGE = { |
52 |
100000, 100, 1, 0.1, 160934.4, 91.44, 30.48, 2.54 |
53 |
}; |
54 |
|
55 |
public static final int EQUALS = 0; |
56 |
public static final int DISJOINT = 1; |
57 |
public static final int INTERSECTS = 2; |
58 |
public static final int TOUCHES = 3; |
59 |
public static final int CROSSES = 4; |
60 |
public static final int WITHIN = 5; |
61 |
public static final int CONTAINS = 6; |
62 |
public static final int OVERLAPS = 7; |
63 |
private FLayers layers = new FLayers(); |
64 |
private ViewPort viewPort;
|
65 |
|
66 |
private ArrayList invalidationListeners = new ArrayList(); |
67 |
|
68 |
public FMap(ViewPort vp){
|
69 |
this.viewPort = vp;
|
70 |
layers.addLayerCollectionListener(new LayerListener());
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* DOCUMENT ME!
|
75 |
*
|
76 |
* @return DOCUMENT ME!
|
77 |
*/
|
78 |
public FLayers getLayers() {
|
79 |
return layers;
|
80 |
} |
81 |
|
82 |
/**
|
83 |
* Dibuja en la imagen que se pasa como par?metro el contenido de las capas
|
84 |
* visibles del mapa y teniendo en cuenta los datos del ViewPort contenido
|
85 |
* en este FMap
|
86 |
*
|
87 |
* @param b DOCUMENT ME!
|
88 |
*/
|
89 |
public void drawLabels(BufferedImage b) { |
90 |
} |
91 |
|
92 |
/**
|
93 |
* DOCUMENT ME!
|
94 |
*
|
95 |
* @param g DOCUMENT ME!
|
96 |
* @throws DriverIOException
|
97 |
* @throws DriverException
|
98 |
* @throws DriverLoadException
|
99 |
*/
|
100 |
public void print(Graphics2D g) throws DriverIOException, DriverLoadException, DriverException { |
101 |
draw(null,g);
|
102 |
} |
103 |
|
104 |
/**
|
105 |
* Crea un nuevo FMap con la informaci?n del ViewPort que se pasa como
|
106 |
* par?metro.
|
107 |
*
|
108 |
* @param vp DOCUMENT ME!
|
109 |
*
|
110 |
* @return DOCUMENT ME!
|
111 |
*/
|
112 |
public FMap createNewFMap(ViewPort vp) {
|
113 |
FMap ret = new FMap(vp);
|
114 |
ret.layers = this.layers;
|
115 |
|
116 |
return ret;
|
117 |
} |
118 |
|
119 |
/**
|
120 |
* Crea un nuevo FMap totalmente desligado, se replican las capas y el
|
121 |
* ViewPort
|
122 |
*
|
123 |
* @return DOCUMENT ME!
|
124 |
*/
|
125 |
public FMap cloneFMap() {
|
126 |
return createXMLEntity(getXMLEntity());
|
127 |
} |
128 |
|
129 |
|
130 |
|
131 |
/**
|
132 |
* DOCUMENT ME!
|
133 |
*
|
134 |
* @param xe DOCUMENT ME!
|
135 |
*
|
136 |
* @return DOCUMENT ME!
|
137 |
*/
|
138 |
public FMap createXMLEntity(XMLEntity xe) {
|
139 |
// TODO Implementar bien
|
140 |
return new FMap(null); |
141 |
} |
142 |
|
143 |
/**
|
144 |
* A?ade la capa que se pasa como par?metro al nodo que se pasa como
|
145 |
* parametro y lanza ProjectionMismatchException si no est?n todas las
|
146 |
* capas de este FMap en la misma proyecci?n. Lanza un
|
147 |
* ChildNotAllowedException si la capa no es un FLayers y no permite hijos
|
148 |
*
|
149 |
* @param parent DOCUMENT ME!
|
150 |
* @param layer DOCUMENT ME!
|
151 |
*
|
152 |
* @throws ProjectionMismatchException DOCUMENT ME!
|
153 |
* @throws ChildrenNotAllowedException DOCUMENT ME!
|
154 |
*/
|
155 |
/* public void addLayer(LayerPath parent, FLayer layer)
|
156 |
throws ProjectionMismatchException, ChildrenNotAllowedException {
|
157 |
layers.addLayer(parent, layer);
|
158 |
}
|
159 |
public void removeLayer(LayerPath parent)throws ChildrenNotAllowedException{
|
160 |
layers.removeLayer(parent);
|
161 |
}
|
162 |
*/
|
163 |
/**
|
164 |
* A?ade una capa al grupo de capas que se sit?a por encima de todas las
|
165 |
* otras capas
|
166 |
*
|
167 |
* @param vectorial DOCUMENT ME!
|
168 |
*/
|
169 |
public void addToTrackLayer(FLyrVect vectorial) { |
170 |
} |
171 |
|
172 |
public long getScaleView() { |
173 |
Toolkit kit = Toolkit.getDefaultToolkit(); |
174 |
double dpi = kit.getScreenResolution();
|
175 |
IProjection proj = viewPort.getProjection(); |
176 |
|
177 |
double w = ((viewPort.getImageSize().getWidth() / dpi) * 2.54); |
178 |
|
179 |
if (viewPort.getAdjustedExtent() == null) { |
180 |
return 0; |
181 |
} |
182 |
|
183 |
|
184 |
if (proj == null) |
185 |
return (long) (viewPort.getAdjustedExtent().getWidth() / w * CHANGE[getViewPort() |
186 |
.getMapUnits()]); |
187 |
return (long) proj.getScale(viewPort.getAdjustedExtent().getMinX(), viewPort.getAdjustedExtent().getMaxX(), viewPort.getImageSize().getWidth(), dpi); |
188 |
} |
189 |
|
190 |
/**
|
191 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#setVectorial(com.iver.cit.gvsig.fmap.VectorialAdapter)
|
192 |
*/
|
193 |
public void setVectorial(VectorialAdapter v) { |
194 |
} |
195 |
|
196 |
/**
|
197 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#process(com.iver.cit.gvsig.fmap.FeatureSelectorVisitor, VectorialSubSet)
|
198 |
*/
|
199 |
public void process(FeatureVisitor visitor) { |
200 |
} |
201 |
|
202 |
/**
|
203 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#processSelected(com.iver.cit.gvsig.fmap.FeatureVisitor)
|
204 |
*/
|
205 |
public void processSelected(FeatureVisitor visitor) { |
206 |
} |
207 |
|
208 |
/**
|
209 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#select(com.iver.cit.gvsig.fmap.FeatureSelectorVisitor, VectorialSubSet)
|
210 |
*/
|
211 |
public void select(FeatureVisitor visitor) { |
212 |
} |
213 |
|
214 |
/**
|
215 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectFromSelection()
|
216 |
*/
|
217 |
public void selectFromSelection() { |
218 |
} |
219 |
|
220 |
/**
|
221 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#createIndex()
|
222 |
*/
|
223 |
public void createIndex() { |
224 |
} |
225 |
|
226 |
/**
|
227 |
* @see org.cresques.geo.Projected#getProjection()
|
228 |
*/
|
229 |
public IProjection getProjection() {
|
230 |
return null; |
231 |
} |
232 |
|
233 |
/**
|
234 |
* @see org.cresques.geo.Projected#reProject(org.cresques.cts.ICoordTrans)
|
235 |
*/
|
236 |
public void reProject(ICoordTrans arg0) { |
237 |
} |
238 |
|
239 |
/**
|
240 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectByPoint(java.awt.geom.Point2D,
|
241 |
* double)
|
242 |
*/
|
243 |
public void selectByPoint(Point2D p, double tolerance) throws DriverIOException { |
244 |
QueriedPoint qp = new QueriedPoint(p.getX(), p.getY());
|
245 |
Point2D mapPoint = viewPort.toMapPoint((int) p.getX(), (int) p.getY()); |
246 |
qp.setRealCoords(mapPoint.getX(), mapPoint.getY()); |
247 |
layers.selectByPoint(qp, tolerance); |
248 |
invalidate(); |
249 |
} |
250 |
|
251 |
/**
|
252 |
* @throws DriverIOException
|
253 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectByRect(java.awt.geom.Rectangle2D)
|
254 |
*/
|
255 |
public void selectByRect(Rectangle2D rect) throws DriverIOException { |
256 |
layers.selectByRect(rect); |
257 |
invalidate(); |
258 |
} |
259 |
|
260 |
/**
|
261 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectByShape(com.iver.cit.gvsig.fmap.fshape.IGeometry,
|
262 |
* int)
|
263 |
*/
|
264 |
public void selectByShape(IGeometry g, int relationship) { |
265 |
} |
266 |
|
267 |
/**
|
268 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByPoint(java.awt.geom.Point2D,
|
269 |
* double)
|
270 |
*/
|
271 |
public Record[] queryByPoint(Point2D p, double tolerance) { |
272 |
return null; |
273 |
} |
274 |
|
275 |
/**
|
276 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByRect(java.awt.geom.Rectangle2D)
|
277 |
*/
|
278 |
public Record[] queryByRect(Rectangle2D rect) { |
279 |
return null; |
280 |
} |
281 |
|
282 |
/**
|
283 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByShape(com.iver.cit.gvsig.fmap.fshape.IGeometry,
|
284 |
* int)
|
285 |
*/
|
286 |
public Record[] queryByShape(IGeometry g, int relationship) { |
287 |
return null; |
288 |
} |
289 |
|
290 |
/**
|
291 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#getSelectionBounds()
|
292 |
*/
|
293 |
public Rectangle2D getSelectionBounds() { |
294 |
return null; |
295 |
} |
296 |
|
297 |
/**
|
298 |
* DOCUMENT ME!
|
299 |
*
|
300 |
* @param image DOCUMENT ME!
|
301 |
* @param g DOCUMENT ME!
|
302 |
* @param viewPort DOCUMENT ME!
|
303 |
* @throws DriverIOException
|
304 |
* @throws DriverException
|
305 |
* @throws DriverLoadException
|
306 |
*
|
307 |
* @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
|
308 |
* java.awt.Graphics2D, FStyle2D)
|
309 |
*/
|
310 |
public void draw(BufferedImage image, Graphics2D g, Cancellable cancel) |
311 |
throws DriverIOException, DriverLoadException, DriverException {
|
312 |
if (viewPort.getExtent() == null) return; |
313 |
|
314 |
layers.draw(image, g, viewPort, cancel); |
315 |
} |
316 |
|
317 |
/**
|
318 |
* DOCUMENT ME!
|
319 |
*
|
320 |
* @param image DOCUMENT ME!
|
321 |
* @param g DOCUMENT ME!
|
322 |
* @param viewPort DOCUMENT ME!
|
323 |
* @throws DriverIOException
|
324 |
* @throws DriverException
|
325 |
* @throws DriverLoadException
|
326 |
*
|
327 |
* @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
|
328 |
* java.awt.Graphics2D, FStyle2D)
|
329 |
*/
|
330 |
public void draw(BufferedImage image, Graphics2D g) |
331 |
throws DriverIOException, DriverLoadException, DriverException {
|
332 |
layers.draw(image, g, viewPort, new Cancellable() {
|
333 |
/**
|
334 |
* @see com.iver.cit.gvsig.fmap.operations.Cancellable#isCanceled()
|
335 |
*/
|
336 |
public boolean isCanceled() { |
337 |
return false; |
338 |
} |
339 |
}); |
340 |
} |
341 |
|
342 |
/**
|
343 |
* @return Returns the viewPort.
|
344 |
*/
|
345 |
public ViewPort getViewPort() {
|
346 |
return viewPort;
|
347 |
} |
348 |
/**
|
349 |
* @param viewPort The viewPort to set.
|
350 |
*/
|
351 |
public void setViewPort(ViewPort viewPort) { |
352 |
this.viewPort = viewPort;
|
353 |
} |
354 |
|
355 |
public class LayerListener implements LayerCollectionListener{ |
356 |
|
357 |
/**
|
358 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
359 |
*/
|
360 |
public void layerAdded(LayerCollectionEvent e) { |
361 |
// Si es la primera capa, fijamos su extent al ViewPort
|
362 |
if (getLayers().getLayersCount() == 1) |
363 |
{ |
364 |
FLayer lyr = e.getAffectedLayer(); |
365 |
try {
|
366 |
getViewPort().setExtent(lyr.getFullExtent()); |
367 |
} catch (DriverIOException e1) {
|
368 |
} |
369 |
} |
370 |
} |
371 |
|
372 |
/**
|
373 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
374 |
*/
|
375 |
public void layerMoved(LayerPositionEvent e) { |
376 |
} |
377 |
|
378 |
/**
|
379 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
380 |
*/
|
381 |
public void layerRemoved(LayerCollectionEvent e) { |
382 |
} |
383 |
|
384 |
/**
|
385 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
386 |
*/
|
387 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
388 |
} |
389 |
|
390 |
/**
|
391 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
392 |
*/
|
393 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
394 |
} |
395 |
|
396 |
/**
|
397 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
398 |
*/
|
399 |
public void layerRemoving(LayerCollectionEvent e) throws CancelationException { |
400 |
} |
401 |
|
402 |
/**
|
403 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
404 |
*/
|
405 |
public void activationChanged(LayerCollectionEvent e) throws CancelationException { |
406 |
} |
407 |
|
408 |
/**
|
409 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
410 |
*/
|
411 |
public void visibilityChanged(LayerCollectionEvent e) throws CancelationException { |
412 |
} |
413 |
|
414 |
} |
415 |
|
416 |
/**
|
417 |
* M?todo de conveniencia. Recorre las capas y te da el fullExtent
|
418 |
* @return fullExtent de todas las capas.
|
419 |
* @throws DriverIOException
|
420 |
*/
|
421 |
public Rectangle2D getFullExtent() throws DriverIOException |
422 |
{ |
423 |
return layers.getFullExtent();
|
424 |
} |
425 |
public XMLEntity getXMLEntity(){
|
426 |
XMLEntity xml=new XMLEntity();
|
427 |
xml.addChild(viewPort.getXMLEntity()); |
428 |
xml.putProperty("numLayers",layers.getLayersCount());
|
429 |
xml.addChild(layers.getXMLEntity()); |
430 |
|
431 |
return xml;
|
432 |
} |
433 |
public static FMap createFromXML(XMLEntity xml) throws DifferentVersionException, CancelationException, ClassNotFoundException, InstantiationException, IllegalAccessException, DriverLoadException, DriverIOException{ |
434 |
ViewPort vp=ViewPort.createFromXML(xml.getChild(0));
|
435 |
FMap fmap=new FMap(vp);
|
436 |
///fmap.layers=(FLayers)FLayers.createFromXML(xml.getChild(1));
|
437 |
int numLayers=xml.getIntProperty("numLayers"); |
438 |
for (int i=0;i<numLayers;i++){ |
439 |
IProjection proj=null;
|
440 |
if (xml.getChild(0).getStringProperty("proj")!=null){ |
441 |
proj=ProjectionPool.get(xml.getChild(0).getStringProperty("proj")); |
442 |
} |
443 |
FLayer layer=null;
|
444 |
if (xml.getChild(1).getChild(i).getStringProperty("file")!=null){ |
445 |
layer=LayerFactory.createLayer(xml.getChild(1).getChild(i).getStringProperty("driverName"),new File(xml.getChild(1).getChild(i).getStringProperty("file")),proj); |
446 |
}else if (true){ |
447 |
|
448 |
}else if (true){ |
449 |
|
450 |
} |
451 |
layer.setXMLEntity(xml.getChild(1).getChild(i));
|
452 |
fmap.getLayers().addLayer(layer); |
453 |
|
454 |
|
455 |
} |
456 |
return fmap;
|
457 |
} |
458 |
|
459 |
public void invalidate(){ |
460 |
for (Iterator iter = invalidationListeners.iterator(); iter.hasNext();) { |
461 |
InvalidationListener listener = (InvalidationListener) iter.next(); |
462 |
|
463 |
listener.invalid(); |
464 |
} |
465 |
} |
466 |
public boolean addInvalidationListener(InvalidationListener listener) { |
467 |
return invalidationListeners.add(listener);
|
468 |
} |
469 |
public boolean removeInvalidationListener(InvalidationListener listener) { |
470 |
return invalidationListeners.remove(listener);
|
471 |
} |
472 |
} |