gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d / org.gvsig.gvsig3d.lib / org.gvsig.gvsig3d.lib.impl / src / main / java / org / gvsig / gvsig3d / impl / map3d / MapContext3DImpl.java @ 306
History | View | Annotate | Download (45 KB)
1 | 166 | jzarzoso | /* 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 | package org.gvsig.gvsig3d.impl.map3d; |
||
23 | |||
24 | 262 | jzarzoso | import java.awt.Color; |
25 | import java.awt.Dimension; |
||
26 | 166 | jzarzoso | import java.awt.Graphics2D; |
27 | 262 | jzarzoso | import java.awt.Image; |
28 | 166 | jzarzoso | import java.awt.geom.AffineTransform; |
29 | import java.awt.image.BufferedImage; |
||
30 | 269 | jzarzoso | import java.awt.image.DataBuffer; |
31 | 166 | jzarzoso | import java.awt.image.ImagingOpException; |
32 | 262 | jzarzoso | import java.awt.image.RenderedImage; |
33 | 166 | jzarzoso | import java.io.File; |
34 | 262 | jzarzoso | import java.io.FileOutputStream; |
35 | 166 | jzarzoso | import java.io.IOException; |
36 | import java.util.Hashtable; |
||
37 | 264 | jzarzoso | import java.util.Vector; |
38 | 166 | jzarzoso | |
39 | 299 | jzarzoso | import javax.imageio.ImageIO; |
40 | |||
41 | 166 | jzarzoso | import org.cresques.cts.IProjection; |
42 | 264 | jzarzoso | import org.gvsig.fmap.dal.coverage.RasterLibrary; |
43 | import org.gvsig.fmap.dal.coverage.RasterLocator; |
||
44 | 269 | jzarzoso | import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
45 | 306 | jzarzoso | import org.gvsig.fmap.dal.coverage.exception.FilePaletteException; |
46 | 265 | jzarzoso | import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
47 | import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
||
48 | import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
||
49 | import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
||
50 | import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
||
51 | 269 | jzarzoso | import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
52 | 262 | jzarzoso | import org.gvsig.fmap.dal.exception.ReadException; |
53 | import org.gvsig.fmap.geom.Geometry; |
||
54 | import org.gvsig.fmap.geom.GeometryLocator; |
||
55 | import org.gvsig.fmap.geom.GeometryManager; |
||
56 | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
||
57 | import org.gvsig.fmap.geom.exception.CreateGeometryException; |
||
58 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
59 | 306 | jzarzoso | import org.gvsig.fmap.mapcontext.MapContext; |
60 | 237 | jzarzoso | import org.gvsig.fmap.mapcontext.ViewPort; |
61 | 306 | jzarzoso | import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
62 | 166 | jzarzoso | import org.gvsig.fmap.mapcontext.layers.FLayer; |
63 | 257 | jzarzoso | import org.gvsig.fmap.mapcontext.layers.FLayers; |
64 | 260 | jzarzoso | import org.gvsig.fmap.mapcontext.layers.FLyrDefault; |
65 | 166 | jzarzoso | import org.gvsig.fmap.mapcontext.layers.LayerEvent; |
66 | 257 | jzarzoso | import org.gvsig.fmap.mapcontext.layers.LayerListener; |
67 | 166 | jzarzoso | import org.gvsig.fmap.mapcontext.layers.SelectionEvent; |
68 | import org.gvsig.fmap.mapcontext.layers.SingleLayerIterator; |
||
69 | 257 | jzarzoso | import org.gvsig.fmap.mapcontext.layers.operations.Classifiable; |
70 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
71 | 166 | jzarzoso | import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent; |
72 | 277 | jzarzoso | import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent; |
73 | import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
||
74 | 264 | jzarzoso | import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener; |
75 | 306 | jzarzoso | import org.gvsig.gvsig3d.impl.layers.FLayers3DImpl; |
76 | 166 | jzarzoso | import org.gvsig.gvsig3d.map3d.Layer3DProps; |
77 | import org.gvsig.gvsig3d.map3d.MapContext3D; |
||
78 | import org.gvsig.gvsig3d.map3d.layers.FLayers3D; |
||
79 | import org.gvsig.osgvp.core.osg.Matrix; |
||
80 | import org.gvsig.osgvp.core.osg.Node; |
||
81 | import org.gvsig.osgvp.core.osg.Vec3; |
||
82 | import org.gvsig.osgvp.core.osg.Vec4; |
||
83 | import org.gvsig.osgvp.exceptions.image.ImageConversionException; |
||
84 | 282 | jzarzoso | import org.gvsig.osgvp.exceptions.image.LoadImageException; |
85 | 166 | jzarzoso | import org.gvsig.osgvp.exceptions.node.ChildIndexOutOfBoundsExceptions; |
86 | import org.gvsig.osgvp.exceptions.node.NodeException; |
||
87 | 262 | jzarzoso | import org.gvsig.osgvp.terrain.Extent; |
88 | 166 | jzarzoso | import org.gvsig.osgvp.terrain.JavaDataDriver; |
89 | import org.gvsig.osgvp.terrain.Layer; |
||
90 | import org.gvsig.osgvp.terrain.LayerManager; |
||
91 | import org.gvsig.osgvp.terrain.RequestDataEvent; |
||
92 | import org.gvsig.osgvp.terrain.Terrain; |
||
93 | 257 | jzarzoso | import org.gvsig.osgvp.terrain.Terrain.CoordinateSystemType; |
94 | 166 | jzarzoso | import org.gvsig.osgvp.terrain.TerrainViewer; |
95 | 269 | jzarzoso | import org.gvsig.osgvp.terrain.TextureLayer; |
96 | 166 | jzarzoso | import org.gvsig.osgvp.terrain.UpdateDataEvent; |
97 | 262 | jzarzoso | import org.gvsig.osgvp.terrain.exceptions.LayerManagementException; |
98 | 166 | jzarzoso | import org.gvsig.osgvp.viewer.Camera; |
99 | import org.gvsig.osgvp.viewer.IViewerContainer; |
||
100 | 264 | jzarzoso | import org.gvsig.raster.cache.tile.TileCache; |
101 | import org.gvsig.raster.cache.tile.TileCacheLibrary; |
||
102 | import org.gvsig.raster.cache.tile.TileCacheLocator; |
||
103 | import org.gvsig.raster.cache.tile.TileCacheManager; |
||
104 | 265 | jzarzoso | import org.gvsig.raster.cache.tile.provider.CacheStruct; |
105 | import org.gvsig.raster.fmap.layers.DefaultFLyrRaster; |
||
106 | 299 | jzarzoso | import org.gvsig.raster.impl.provider.DefaultRasterProvider; |
107 | import org.gvsig.raster.netcdf.io.NetCDFDataParameters; |
||
108 | 265 | jzarzoso | import org.gvsig.raster.tilecache.io.TileProvider; |
109 | 306 | jzarzoso | import org.gvsig.tools.ToolsLocator; |
110 | import org.gvsig.tools.dynobject.DynStruct; |
||
111 | 288 | jzarzoso | import org.gvsig.tools.locator.LocatorException; |
112 | 306 | jzarzoso | import org.gvsig.tools.persistence.PersistenceManager; |
113 | 166 | jzarzoso | import org.gvsig.tools.task.Cancellable; |
114 | 306 | jzarzoso | import org.gvsig.tools.util.Callable; |
115 | 166 | jzarzoso | |
116 | 262 | jzarzoso | import com.sun.media.jai.codec.ImageCodec; |
117 | import com.sun.media.jai.codec.ImageEncoder; |
||
118 | import com.sun.media.jai.codec.PNGEncodeParam; |
||
119 | import com.sun.media.jai.codec.TIFFEncodeParam; |
||
120 | |||
121 | 166 | jzarzoso | /**
|
122 | * @author gvSIG Team
|
||
123 | * @version $Id$
|
||
124 | *
|
||
125 | */
|
||
126 | 237 | jzarzoso | public class MapContext3DImpl extends MapContext3D { |
127 | 166 | jzarzoso | |
128 | 265 | jzarzoso | private Terrain _terrain;
|
129 | 237 | jzarzoso | private IViewerContainer _canvas3d;
|
130 | private TerrainViewer _terrainViewer;
|
||
131 | private LayerManager _terrainLayerManager;
|
||
132 | private JavaDataDriver _terrainDataManager = null; |
||
133 | 166 | jzarzoso | |
134 | 237 | jzarzoso | private Hashtable<FLayer, Layer> _terrainFLayerMap = new Hashtable<FLayer, Layer>(); |
135 | private Hashtable<String, FLayer> _terrainLayerMap = new Hashtable<String, FLayer>(); |
||
136 | 166 | jzarzoso | |
137 | 265 | jzarzoso | private Hashtable<DefaultFLyrRaster, CacheStruct> _cachedLayers = new Hashtable<DefaultFLyrRaster, CacheStruct>(); |
138 | |||
139 | 237 | jzarzoso | private IProjection _viewProjection;
|
140 | private float _verticalExaggeration; |
||
141 | private boolean _bEmptyView = true; |
||
142 | private boolean _bListenToLegend = true; |
||
143 | private boolean _bLoading = false; |
||
144 | private TerrainViewer _canvasoff = null; |
||
145 | private boolean _renewCanvasOff = false; |
||
146 | 166 | jzarzoso | |
147 | 237 | jzarzoso | TerrainViewer _printViewer = null;
|
148 | Layer _testRasterLayer = null;
|
||
149 | 166 | jzarzoso | |
150 | 237 | jzarzoso | private boolean visibilityChange = false; |
151 | 166 | jzarzoso | |
152 | 265 | jzarzoso | TileCacheManager tileMan = TileCacheLocator.getManager(); |
153 | TileCache tileCache = tileMan.getTileCache(RasterLibrary.pathTileCache); |
||
154 | |||
155 | 260 | jzarzoso | public MapContext3DImpl() {
|
156 | } |
||
157 | 166 | jzarzoso | |
158 | 237 | jzarzoso | public MapContext3DImpl(ViewPort vp) {
|
159 | super(vp);
|
||
160 | } |
||
161 | 260 | jzarzoso | |
162 | public MapContext3DImpl(FLayers fLayers, ViewPort vp) {
|
||
163 | |||
164 | super(fLayers, vp);
|
||
165 | |||
166 | 257 | jzarzoso | } |
167 | 166 | jzarzoso | |
168 | 237 | jzarzoso | public void draw(BufferedImage image, Graphics2D g, Cancellable cancel, |
169 | double scale) {
|
||
170 | 166 | jzarzoso | |
171 | 237 | jzarzoso | if (_canvas3d == null || _canvas3d.getOSGViewer() == null) |
172 | return;
|
||
173 | double x = getViewPort().getOffset().getX();
|
||
174 | double y = getViewPort().getOffset().getY();
|
||
175 | double w = image.getWidth();
|
||
176 | double h = image.getHeight();
|
||
177 | 166 | jzarzoso | |
178 | 237 | jzarzoso | if (_canvasoff == null) { |
179 | try {
|
||
180 | _canvasoff = new TerrainViewer();
|
||
181 | _canvasoff.setUpViewerInBackground(0, 0, 512, 512); |
||
182 | 166 | jzarzoso | |
183 | 237 | jzarzoso | Terrain planetView3D = ((TerrainViewer) _canvas3d |
184 | .getOSGViewer()).getTerrain(0);
|
||
185 | Terrain terrain = new Terrain();
|
||
186 | terrain.setCoordinateSystemType(planetView3D |
||
187 | .getCoordinateSystemType()); |
||
188 | terrain.setCoordinateSystemName(planetView3D |
||
189 | .getCoordinateSystemName()); |
||
190 | terrain.setCoordinateSystemFormat(planetView3D |
||
191 | .getCoordinateSystemFormat()); |
||
192 | 269 | jzarzoso | terrain.setExtent(planetView3D.xMin(), planetView3D.yMin(), |
193 | planetView3D.xMax(), planetView3D.yMax()); |
||
194 | 237 | jzarzoso | terrain.setTerrainName(planetView3D.getTerrainName()); |
195 | 166 | jzarzoso | |
196 | 237 | jzarzoso | terrain.init(); |
197 | terrain.setLayerManager(_terrainLayerManager); |
||
198 | 166 | jzarzoso | |
199 | 237 | jzarzoso | _canvasoff.addTerrain(terrain); |
200 | _canvasoff.addFeature((((TerrainViewer) _canvas3d |
||
201 | .getOSGViewer()).getFeatures())); |
||
202 | Vec4 color = ((TerrainViewer) _canvas3d.getOSGViewer()) |
||
203 | .getClearColor(); |
||
204 | _canvasoff.setClearColor(color.x(), color.y(), color.z(), |
||
205 | color.w()); |
||
206 | this.setRenewCanvasOff(false); |
||
207 | } catch (NodeException e) {
|
||
208 | // TODO Auto-generated catch block
|
||
209 | e.printStackTrace(); |
||
210 | } |
||
211 | 166 | jzarzoso | |
212 | 237 | jzarzoso | } |
213 | 166 | jzarzoso | |
214 | 237 | jzarzoso | Camera refCam = _canvas3d.getOSGViewer().getCamera(); |
215 | Matrix refView = refCam.getViewMatrix(); |
||
216 | Matrix refProy = refCam.getProjectionMatrix(); |
||
217 | Matrix.Perspective pers = refProy.getPerspective(); |
||
218 | Camera viewCam = new Camera();
|
||
219 | viewCam.setProjectionMatrixAsPerspective(pers.fovy, w / h, pers.zNear, |
||
220 | pers.zFar); |
||
221 | viewCam.setViewMatrix(refView); |
||
222 | _canvasoff.setViewport(0, 0, (int) w, (int) h); |
||
223 | _canvasoff.setCamera(viewCam); |
||
224 | _canvasoff.takeScreenshotToMemory(); |
||
225 | _canvasoff.frame(); |
||
226 | 166 | jzarzoso | |
227 | 262 | jzarzoso | org.gvsig.osgvp.core.osg.Image OSGimage = _canvasoff |
228 | .getScreenshotImage(); |
||
229 | 166 | jzarzoso | |
230 | 237 | jzarzoso | BufferedImage img = null; |
231 | try {
|
||
232 | img = OSGimage.getBufferedImage(); |
||
233 | } catch (ImageConversionException e1) {
|
||
234 | // TODO Auto-generated catch block
|
||
235 | e1.printStackTrace(); |
||
236 | } catch (IOException e1) { |
||
237 | // TODO Auto-generated catch block
|
||
238 | e1.printStackTrace(); |
||
239 | } |
||
240 | 166 | jzarzoso | |
241 | 237 | jzarzoso | double scalex = w / img.getWidth(null); |
242 | double scaley = h / img.getHeight(null); |
||
243 | try {
|
||
244 | AffineTransform xform = AffineTransform.getScaleInstance(scalex, |
||
245 | scaley); |
||
246 | AffineTransform xpos = AffineTransform.getTranslateInstance(x, y); |
||
247 | xpos.concatenate(xform); |
||
248 | g.drawRenderedImage(img, xpos); |
||
249 | } catch (ImagingOpException e) { |
||
250 | 166 | jzarzoso | |
251 | 237 | jzarzoso | } |
252 | 166 | jzarzoso | |
253 | 237 | jzarzoso | } |
254 | 166 | jzarzoso | |
255 | 237 | jzarzoso | public void CreateOSGLayer(FLayer layer, Layer3DProps props3d) { |
256 | // if (_terrain == null || _viewProjection == null)
|
||
257 | // return;
|
||
258 | //
|
||
259 | // OSGCacheService cacheService = (OSGCacheService) props3D
|
||
260 | // .getCacheService();
|
||
261 | // if (cacheService == null) {
|
||
262 | // cacheService = new OSGCacheService(_canvas3d, _terrain, props3D
|
||
263 | // .getCacheName(), layer, _viewProjection);
|
||
264 | // cacheService.setCacheRootDir(Layer3DProps.m_cacheDir);
|
||
265 | // props3D.setCacheService(cacheService);
|
||
266 | // }
|
||
267 | //
|
||
268 | // // use VectorCacheService to add features to planet
|
||
269 | // cacheService.AddFeaturesToTerrain();
|
||
270 | 166 | jzarzoso | |
271 | 237 | jzarzoso | } |
272 | 166 | jzarzoso | |
273 | 237 | jzarzoso | public void DeleteOSGLayer(FLayer layer, Layer3DProps props3d) { |
274 | // if (_terrain == null || _viewProjection == null)
|
||
275 | // return;
|
||
276 | //
|
||
277 | // OSGCacheService cacheService = (OSGCacheService) props3D
|
||
278 | // .getCacheService();
|
||
279 | // if (cacheService != null) {
|
||
280 | // // use VectorCacheService to delete features to terrain
|
||
281 | // cacheService.DeleteFeaturesToTerrain();
|
||
282 | // }
|
||
283 | 166 | jzarzoso | |
284 | 237 | jzarzoso | } |
285 | 166 | jzarzoso | |
286 | 237 | jzarzoso | public void PrintDebugLayers() { |
287 | if (_terrainLayerManager != null) { |
||
288 | System.out.println("==========================="); |
||
289 | System.out.println("Total terrain layers: " |
||
290 | + _terrainLayerManager.getNumLayers()); |
||
291 | System.out.println("==========================="); |
||
292 | } |
||
293 | SingleLayerIterator lyrIterator = new SingleLayerIterator(layers);
|
||
294 | int pos = 0; |
||
295 | while (lyrIterator.hasNext()) {
|
||
296 | FLayer layer = lyrIterator.next(); |
||
297 | System.out.println(" Layer " + layer.getName()); |
||
298 | Layer3DProps props3D = getLayer3DProps(layer); |
||
299 | System.out.println(" Type " + props3D.getType()); |
||
300 | System.out.println(" Order " + pos); |
||
301 | pos++; |
||
302 | } |
||
303 | 166 | jzarzoso | |
304 | 237 | jzarzoso | } |
305 | 166 | jzarzoso | |
306 | 237 | jzarzoso | public void activationChanged(LayerEvent e) { |
307 | 166 | jzarzoso | |
308 | 237 | jzarzoso | } |
309 | 166 | jzarzoso | |
310 | 237 | jzarzoso | public void addCurrentLayers() { |
311 | 166 | jzarzoso | |
312 | 237 | jzarzoso | SingleLayerIterator lyrIterator = new SingleLayerIterator(layers);
|
313 | while (lyrIterator.hasNext()) {
|
||
314 | FLayer layer = lyrIterator.next(); |
||
315 | Layer3DProps props = getLayer3DProps(layer); |
||
316 | addLayerToTerrain(layer, false);
|
||
317 | } |
||
318 | 166 | jzarzoso | |
319 | 237 | jzarzoso | } |
320 | 166 | jzarzoso | |
321 | 237 | jzarzoso | public void addLayerToTerrain(FLayer layer, boolean bVerifyLegend) { |
322 | 166 | jzarzoso | |
323 | 262 | jzarzoso | System.out.println("ADD LAYER TO TERRAIN METHOD!"); |
324 | Envelope layerEnvelope = null;
|
||
325 | try {
|
||
326 | layerEnvelope = layer.getFullEnvelope(); |
||
327 | } catch (ReadException e1) {
|
||
328 | // TODO Auto-generated catch block
|
||
329 | e1.printStackTrace(); |
||
330 | } |
||
331 | 264 | jzarzoso | |
332 | 262 | jzarzoso | Layer3DProps props = getLayer3DProps(layer); |
333 | |||
334 | GeometryManager geoMan; |
||
335 | |||
336 | geoMan = GeometryLocator.getGeometryManager(); |
||
337 | |||
338 | if (layerEnvelope == null) { |
||
339 | |||
340 | try {
|
||
341 | layerEnvelope = geoMan.createEnvelope(Geometry.SUBTYPES.GEOM2D); |
||
342 | if (_terrain.getCoordinateSystemType() == Terrain.CoordinateSystemType.GEOCENTRIC) {
|
||
343 | layerEnvelope.setLowerCorner(geoMan.createPoint(-180.0,
|
||
344 | -90.0, Geometry.SUBTYPES.GEOM2D));
|
||
345 | layerEnvelope.setUpperCorner(geoMan.createPoint(360.0,
|
||
346 | 180.0, Geometry.SUBTYPES.GEOM2D));
|
||
347 | } |
||
348 | |||
349 | else {
|
||
350 | |||
351 | layerEnvelope.setLowerCorner(geoMan |
||
352 | .createPoint(-20000000.0, -10000000.00, |
||
353 | Geometry.SUBTYPES.GEOM2D)); |
||
354 | layerEnvelope.setUpperCorner(geoMan.createPoint(40000000.0,
|
||
355 | 20000000.0, Geometry.SUBTYPES.GEOM2D));
|
||
356 | |||
357 | } |
||
358 | } catch (CreateEnvelopeException e) {
|
||
359 | // TODO Auto-generated catch block
|
||
360 | e.printStackTrace(); |
||
361 | } catch (CreateGeometryException e) {
|
||
362 | // TODO Auto-generated catch block
|
||
363 | e.printStackTrace(); |
||
364 | } |
||
365 | |||
366 | } |
||
367 | |||
368 | Extent extent = null;
|
||
369 | if (_terrain.getCoordinateSystemType() == CoordinateSystemType.PROJECTED) {
|
||
370 | |||
371 | extent = new Extent(layerEnvelope.getLowerCorner().getX(),
|
||
372 | layerEnvelope.getLowerCorner().getY(), layerEnvelope |
||
373 | .getUpperCorner().getX(), layerEnvelope |
||
374 | .getUpperCorner().getY()); |
||
375 | |||
376 | } else {
|
||
377 | extent = new Extent(Math.toRadians(layerEnvelope.getLowerCorner() |
||
378 | .getX()), Math.toRadians(layerEnvelope.getLowerCorner()
|
||
379 | .getY()), Math.toRadians(layerEnvelope.getUpperCorner()
|
||
380 | .getX()), Math.toRadians(layerEnvelope.getUpperCorner()
|
||
381 | .getY())); |
||
382 | |||
383 | } |
||
384 | |||
385 | 269 | jzarzoso | TextureLayer rlayer = new TextureLayer();
|
386 | 262 | jzarzoso | rlayer.setEnabled(layer.isVisible()); |
387 | // Here we use extent because the older osgvp version. The new will be
|
||
388 | // named envelope
|
||
389 | rlayer.setExtent(extent); |
||
390 | 265 | jzarzoso | rlayer.setOpacity(getLayer3DProps(layer).getOpacity()); |
391 | 262 | jzarzoso | rlayer.setDataDriver(_terrainDataManager); |
392 | 273 | jzarzoso | rlayer.setMaxLevel(100);
|
393 | rlayer.setMaxResolution(100);
|
||
394 | 237 | jzarzoso | // _logger.warn("computed optimum level = "
|
395 | // + computeOptimumLevel(layer, 20, 256));
|
||
396 | 274 | jzarzoso | // rlayer.setMaxResolution(computeOptimumLevel(layer, 21, 256));
|
397 | 262 | jzarzoso | try {
|
398 | _terrainLayerManager.addLayer(rlayer); |
||
399 | } catch (LayerManagementException e) {
|
||
400 | // TODO Auto-generated catch block
|
||
401 | e.printStackTrace(); |
||
402 | } |
||
403 | _terrainFLayerMap.put(layer, rlayer); |
||
404 | _terrainLayerMap.put(rlayer.getLayerID(), layer); |
||
405 | 277 | jzarzoso | props.setTerrainLayer(rlayer); |
406 | 262 | jzarzoso | // Refresh cache for vector rasterized layers
|
407 | 237 | jzarzoso | // if (layer.getClass().equals(FLyrVect.class)) {
|
408 | // refreshLayerInTerrain(props3D, true);
|
||
409 | // }
|
||
410 | 262 | jzarzoso | |
411 | 237 | jzarzoso | // if (bVerifyLegend) {
|
412 | // _bListenToLegend = false;
|
||
413 | // props3D.VerifyLegend(_terrain.getTerrainName());
|
||
414 | // _bListenToLegend = true;
|
||
415 | // }
|
||
416 | // }
|
||
417 | 166 | jzarzoso | |
418 | 237 | jzarzoso | } |
419 | 166 | jzarzoso | |
420 | 237 | jzarzoso | public int computeOptimumLevel(FLayer layer, int maxLevel, double tileSize) { |
421 | int level = maxLevel;
|
||
422 | 268 | jzarzoso | if (!(layer instanceof DefaultFLyrRaster)) |
423 | return level;
|
||
424 | 237 | jzarzoso | //
|
425 | // Rectangle2D ext = null;
|
||
426 | // try {
|
||
427 | // ext = layer.getFullExtent();
|
||
428 | // } catch (ReadDriverException e1) {
|
||
429 | // NotificationManager.addError("Error al obtener el extent", e1);
|
||
430 | // }
|
||
431 | //
|
||
432 | // ArrayList attr = ((FLyrRasterSE) layer).getAttributes();
|
||
433 | // if (attr == null) {
|
||
434 | // return level;
|
||
435 | // }
|
||
436 | // int width = 0, height = 0;
|
||
437 | // for (int i = 0; i < attr.size(); i++) {
|
||
438 | // Object[] a = (Object[]) attr.get(i);
|
||
439 | // if (a[0].toString().equals("Width"))
|
||
440 | // width = ((Integer) a[1]).intValue();
|
||
441 | // if (a[0].toString().equals("Height"))
|
||
442 | // height = ((Integer) a[1]).intValue();
|
||
443 | // }
|
||
444 | //
|
||
445 | // if (ext != null && width != 0 && height != 0) {
|
||
446 | //
|
||
447 | // Extent destinationExtents = _terrain.getExtent();
|
||
448 | // double xMax = destinationExtents.xMax();
|
||
449 | // double xMin = destinationExtents.xMin();
|
||
450 | // double yMax = destinationExtents.yMax();
|
||
451 | // double yMin = destinationExtents.yMin();
|
||
452 | // int terrainType = _terrain.getCoordinateSystemType();
|
||
453 | // if (terrainType == Terrain.CoordinateSystemType.GEOCENTRIC) {
|
||
454 | // xMax = Math.toDegrees(xMax);
|
||
455 | // xMin = Math.toDegrees(xMin);
|
||
456 | // yMax = Math.toDegrees(yMax);
|
||
457 | // yMin = Math.toDegrees(yMin);
|
||
458 | // }
|
||
459 | //
|
||
460 | // double destination_xRange = xMax - xMin;
|
||
461 | // double destination_yRange = yMax - yMin;
|
||
462 | // double AR = destination_xRange / destination_yRange;
|
||
463 | // int C1 = 1;
|
||
464 | // int R1 = 1;
|
||
465 | //
|
||
466 | // boolean swapAxis = AR < 1.0;
|
||
467 | // if (swapAxis)
|
||
468 | // AR = 1.0 / AR;
|
||
469 | //
|
||
470 | // double lower_AR = Math.floor(AR);
|
||
471 | // double upper_AR = Math.ceil(AR);
|
||
472 | //
|
||
473 | // if (AR < Math.sqrt(lower_AR * upper_AR)) {
|
||
474 | // C1 = (int) (lower_AR);
|
||
475 | // R1 = 1;
|
||
476 | // } else {
|
||
477 | // C1 = (int) (upper_AR);
|
||
478 | // R1 = 1;
|
||
479 | // }
|
||
480 | //
|
||
481 | // if (swapAxis) {
|
||
482 | // // std::swap(C1,R1);
|
||
483 | // int t = C1;
|
||
484 | // C1 = R1;
|
||
485 | // R1 = t;
|
||
486 | // }
|
||
487 | //
|
||
488 | // double source_xRange = ext.getMaxX() - ext.getMinX();
|
||
489 | // double source_yRange = ext.getMaxY() - ext.getMinY();
|
||
490 | //
|
||
491 | // float sourceResolutionX = ((float) source_xRange) / (float) width;
|
||
492 | // float sourceResolutionY = ((float) source_yRange) / (float) height;
|
||
493 | //
|
||
494 | // //
|
||
495 | // log(osg::NOTICE,"Source %s resX %f resY %f",source->getFileName().c_str(),
|
||
496 | // // sourceResolutionX, sourceResolutionX);
|
||
497 | //
|
||
498 | // int k_cols =
|
||
499 | // (int) (Math.ceil(1.0
|
||
500 | // + Math.log(destination_xRange
|
||
501 | // / (C1 * sourceResolutionX * tileSize)) / Math.log(2.0)));
|
||
502 | // int k_rows =
|
||
503 | // (int) (Math.ceil(1.0
|
||
504 | // + Math.log(destination_yRange
|
||
505 | // / (R1 * sourceResolutionY * tileSize)) / Math.log(2.0)));
|
||
506 | // level = Math.max(k_cols, k_rows);
|
||
507 | // level = Math.min(level, maxLevel);
|
||
508 | // level = Math.max(level, 0);
|
||
509 | // }
|
||
510 | return level;
|
||
511 | } |
||
512 | 166 | jzarzoso | |
513 | 237 | jzarzoso | public IViewerContainer getCanvas3d() {
|
514 | return _canvas3d;
|
||
515 | } |
||
516 | 166 | jzarzoso | |
517 | 237 | jzarzoso | public JavaDataDriver getDataManager() {
|
518 | return _terrainDataManager;
|
||
519 | } |
||
520 | 166 | jzarzoso | |
521 | 237 | jzarzoso | public Layer3DProps getLayer3DProps(FLayer layer) {
|
522 | 260 | jzarzoso | Layer3DProps props3D = (Layer3DProps) layer |
523 | .getProperty("3DLayerExtension");
|
||
524 | 237 | jzarzoso | //
|
525 | // // Create instance of props for osg layers.
|
||
526 | 260 | jzarzoso | if (props3D == null) { |
527 | 265 | jzarzoso | props3D = new Layer3DPropsImpl(layer);
|
528 | 260 | jzarzoso | // if (layer instanceof FLyrVect) {
|
529 | // FLyrVect nLayer = (FLyrVect) layer;
|
||
530 | // Driver driver;
|
||
531 | // try {
|
||
532 | // driver = nLayer.getRecordset().getDriver();
|
||
533 | // if (driver instanceof GvsigDriverOSG) {
|
||
534 | // props3D.setChooseType(false);
|
||
535 | // props3D.setType(Layer3DProps.layer3DOSG);
|
||
536 | // }
|
||
537 | // } catch (ReadDriverException e) {
|
||
538 | // // TODO Auto-generated catch block
|
||
539 | // e.printStackTrace();
|
||
540 | // }
|
||
541 | //
|
||
542 | // }
|
||
543 | // // Set the properties
|
||
544 | props3D.setLayer(layer); |
||
545 | //
|
||
546 | // props3D.initCacheName(_terrain.getCoordinateSystemType(),
|
||
547 | // _viewProjection, Terrain.CoordinateSystemType.GEOCENTRIC);
|
||
548 | FLyrDefault baseLayer = (FLyrDefault) layer; |
||
549 | baseLayer.setProperty("3DLayerExtension", props3D);
|
||
550 | props3D.setVerticalEx(getVerticalExaggeration()); |
||
551 | } else {
|
||
552 | if (_bLoading)
|
||
553 | props3D.setChooseType(false);
|
||
554 | props3D.setLayer(layer); |
||
555 | } |
||
556 | 237 | jzarzoso | //
|
557 | 265 | jzarzoso | return props3D;
|
558 | 166 | jzarzoso | |
559 | 268 | jzarzoso | // return null;
|
560 | 237 | jzarzoso | } |
561 | 166 | jzarzoso | |
562 | 237 | jzarzoso | public LayerManager getLayerManager() {
|
563 | return _terrainLayerManager;
|
||
564 | } |
||
565 | 166 | jzarzoso | |
566 | 237 | jzarzoso | public Node getSpecialNode() {
|
567 | Node specialNode = null;
|
||
568 | try {
|
||
569 | specialNode = _terrainViewer.getFeature(0);
|
||
570 | } catch (ChildIndexOutOfBoundsExceptions e) {
|
||
571 | 166 | jzarzoso | |
572 | 237 | jzarzoso | } |
573 | return specialNode;
|
||
574 | } |
||
575 | 166 | jzarzoso | |
576 | 237 | jzarzoso | public Terrain getTerrain() {
|
577 | return _terrain;
|
||
578 | } |
||
579 | 166 | jzarzoso | |
580 | 237 | jzarzoso | public float getVerticalExaggeration() { |
581 | return _verticalExaggeration;
|
||
582 | } |
||
583 | 166 | jzarzoso | |
584 | 237 | jzarzoso | public IProjection getViewProjection() {
|
585 | return _viewProjection;
|
||
586 | } |
||
587 | 166 | jzarzoso | |
588 | 237 | jzarzoso | public void invalidateVectorLayer(Layer3DProps props) { |
589 | 282 | jzarzoso | // TODO Auto-generated method stub
|
590 | // if (_terrain == null || _viewProjection == null)
|
||
591 | // return;
|
||
592 | //
|
||
593 | // VectorCacheService cacheService = (VectorCacheService) props
|
||
594 | // .getCacheService();
|
||
595 | // if (cacheService != null) {
|
||
596 | // // use VectorCacheService to add features to terrain
|
||
597 | // cacheService.refreshFeaturesToTerrain();
|
||
598 | // }
|
||
599 | 166 | jzarzoso | |
600 | 237 | jzarzoso | } |
601 | 166 | jzarzoso | |
602 | 237 | jzarzoso | public boolean isRenewCanvasOff() { |
603 | return _renewCanvasOff;
|
||
604 | } |
||
605 | 166 | jzarzoso | |
606 | 237 | jzarzoso | public void layerAdded(FLayers3D parent, FLayer layer) { |
607 | 260 | jzarzoso | |
608 | 306 | jzarzoso | System.out.println("A?adida capa. Evento Capturado"); |
609 | 260 | jzarzoso | // to add group layers to 3D, just add recursively child data layers
|
610 | if (layer instanceof FLayers) { |
||
611 | FLayers group = (FLayers) layer; |
||
612 | for (int iChild = 0; iChild < group.getLayersCount(); iChild++) { |
||
613 | layerAdded((FLayers3D) group, group.getLayer(iChild)); |
||
614 | } |
||
615 | getLayer3DProps(layer).setHooked(true);
|
||
616 | return;
|
||
617 | } |
||
618 | //
|
||
619 | if (layer instanceof Classifiable) { |
||
620 | Classifiable legendLyr = (Classifiable) layer; |
||
621 | 282 | jzarzoso | // legendLyr.addLegendListener((LegendListener) this);
|
622 | 260 | jzarzoso | this.addLayerListener(this); |
623 | } |
||
624 | layer.addLayerListener((LayerListener) this);
|
||
625 | |||
626 | 262 | jzarzoso | // listener to manage the selection for the layers
|
627 | // if (layer.getClass().equals(FLyrVect.class)) {
|
||
628 | // FLyrVect lyr = (FLyrVect) layer;
|
||
629 | // refreshLayerVectorsVisibility(lyr);
|
||
630 | // try {
|
||
631 | // SelectableDataSource recordSet = lyr.getRecordset();
|
||
632 | // if (recordSet != null) {
|
||
633 | // SelectionSupport selectionSupport = recordSet
|
||
634 | // .getSelectionSupport();
|
||
635 | // selectionSupport.addSelectionListener(this);
|
||
636 | // }
|
||
637 | // } catch (ReadDriverException e) {
|
||
638 | // // TODO Auto-generated catch block
|
||
639 | // e.printStackTrace();
|
||
640 | // }
|
||
641 | // }
|
||
642 | 260 | jzarzoso | |
643 | 262 | jzarzoso | // if (!_bLoading)
|
644 | 306 | jzarzoso | |
645 | // If DefaultFLayerRaster we must init the layer for the persistence to
|
||
646 | // work
|
||
647 | if (layer instanceof DefaultFLyrRaster) { |
||
648 | try {
|
||
649 | ((DefaultFLyrRaster) layer).init(); |
||
650 | } catch (LoadLayerException e) {
|
||
651 | // TODO Auto-generated catch block
|
||
652 | e.printStackTrace(); |
||
653 | } catch (FilePaletteException e) {
|
||
654 | // TODO Auto-generated catch block
|
||
655 | e.printStackTrace(); |
||
656 | } |
||
657 | } |
||
658 | 262 | jzarzoso | addLayerToTerrain(layer, true);
|
659 | 260 | jzarzoso | |
660 | // Only do this the first time to add layer
|
||
661 | 262 | jzarzoso | // if (_bEmptyView && !_bLoading) {
|
662 | // if (layers.getLayersCount() > 0) {
|
||
663 | 268 | jzarzoso | // try {
|
664 | try {
|
||
665 | 265 | jzarzoso | zoomToEnvelope(layer.getFullEnvelope()); |
666 | } catch (ReadException e) {
|
||
667 | // TODO Auto-generated catch block
|
||
668 | e.printStackTrace(); |
||
669 | } |
||
670 | 268 | jzarzoso | // } catch (ExpansionFileReadException e) {
|
671 | // e.printStackTrace();
|
||
672 | // } catch (ReadDriverException e) {
|
||
673 | // e.printStackTrace();
|
||
674 | // }
|
||
675 | 262 | jzarzoso | // _bEmptyView = false;
|
676 | // }
|
||
677 | // }
|
||
678 | 260 | jzarzoso | //
|
679 | // // PrintDebugLayers();
|
||
680 | 166 | jzarzoso | |
681 | 268 | jzarzoso | // if (layer instanceof DefaultFLyrRaster) {
|
682 | //
|
||
683 | // if (!_cachedLayers.containsKey(layer)) {
|
||
684 | //
|
||
685 | // System.out.println("Rellenando Hasmap en metodo layeradded");
|
||
686 | // _cachedLayers.put((DefaultFLyrRaster) layer,
|
||
687 | // getCacheStruct((DefaultFLyrRaster) layer));
|
||
688 | //
|
||
689 | // }
|
||
690 | //
|
||
691 | // }
|
||
692 | 265 | jzarzoso | |
693 | 237 | jzarzoso | } |
694 | 166 | jzarzoso | |
695 | 265 | jzarzoso | private CacheStruct getCacheStruct(DefaultFLyrRaster layer) {
|
696 | |||
697 | 274 | jzarzoso | // System.out.println("Creando estructura de cache");
|
698 | 265 | jzarzoso | |
699 | // Se obtiene el datastore de la capa
|
||
700 | RasterDataStore dataStore = layer.getDataStore(); |
||
701 | |||
702 | // Creais la estructura de cach?
|
||
703 | TileCacheManager manager = TileCacheLocator.getManager(); |
||
704 | |||
705 | 271 | jzarzoso | int coordinates = CacheStruct.FLAT;
|
706 | 265 | jzarzoso | |
707 | 271 | jzarzoso | if (_terrain.getCoordinateSystemType() == Terrain.CoordinateSystemType.GEOGRAPHIC)
|
708 | coordinates = CacheStruct.GEOGRAFIC; |
||
709 | |||
710 | 299 | jzarzoso | DefaultRasterProvider provider = (DefaultRasterProvider) dataStore |
711 | .getProvider(); |
||
712 | 265 | jzarzoso | |
713 | provider.setProjection(layer.getProjection()); |
||
714 | |||
715 | // El epsg suele tener la forma EPSG:4326
|
||
716 | String epsg = null; |
||
717 | IProjection proj = provider.getProjection(); |
||
718 | if (proj != null) |
||
719 | epsg = proj.getAbrev(); |
||
720 | |||
721 | CacheStruct struct = manager.createCacheStructure( |
||
722 | coordinates, |
||
723 | TileCacheLibrary.DEFAULT_LEVELS, |
||
724 | provider.getExtent().toRectangle2D(), // Rectangle2D con el
|
||
725 | // extent de
|
||
726 | // vuestra capa. Pedir a
|
||
727 | // la capa
|
||
728 | provider.getCellSize(), // Rectangle2D con el tama?o de pixel de
|
||
729 | // vuestra capa. Pedir a la capa
|
||
730 | TileCacheLibrary.DEFAULT_TILESIZE, |
||
731 | 268 | jzarzoso | TileCacheLibrary.DEFAULT_TILESIZE, provider.getFullName(), // Nombre
|
732 | // de
|
||
733 | // la
|
||
734 | // capa
|
||
735 | |||
736 | 265 | jzarzoso | TileCacheLibrary.DEFAULT_STRUCTURE, // Dejarlo as?
|
737 | RasterLibrary.pathTileCache, // Dejarlo as?
|
||
738 | 271 | jzarzoso | "tif", epsg, provider.getFileSize());
|
739 | 265 | jzarzoso | |
740 | return struct;
|
||
741 | |||
742 | } |
||
743 | |||
744 | 262 | jzarzoso | private void refreshLayerVectorsVisibility(FLayer lyr) { |
745 | // if (_terrain == null || _viewProjection == null)
|
||
746 | // return;
|
||
747 | //
|
||
748 | // Layer3DProps props3D = getLayer3DProps(lyr);
|
||
749 | //
|
||
750 | // VectorCacheService cacheService = (VectorCacheService) props3D
|
||
751 | // .getCacheService();
|
||
752 | // if (cacheService != null) {
|
||
753 | // // use VectorCacheService to add features to terrain
|
||
754 | // cacheService.refreshFeaturesToTerrain(lyr.isVisible());
|
||
755 | // props3D.drawVersion = lyr.getDrawVersion();
|
||
756 | // }
|
||
757 | |||
758 | } |
||
759 | |||
760 | 237 | jzarzoso | public void layerMoved(FLayers3D parent, FLayer layer, int oldPos, |
761 | int newPos) {
|
||
762 | 264 | jzarzoso | if (layer instanceof FLayers) { |
763 | FLayers group = (FLayers) layer; |
||
764 | if (newPos > oldPos) {
|
||
765 | for (int iChild = group.getLayersCount() - 1; iChild >= 0; iChild--) |
||
766 | layerMoved((FLayers3D) group, group.getLayer(iChild), |
||
767 | oldPos, newPos); |
||
768 | } else {
|
||
769 | for (int iChild = 0; iChild < group.getLayersCount(); iChild++) |
||
770 | layerMoved((FLayers3D) group, group.getLayer(iChild), |
||
771 | oldPos, newPos); |
||
772 | } |
||
773 | return;
|
||
774 | } |
||
775 | |||
776 | Layer3DProps props3D = getLayer3DProps(layer); |
||
777 | 299 | jzarzoso | refreshLayerInTerrain(props3D, false);
|
778 | |||
779 | 264 | jzarzoso | int type = props3D.getType();
|
780 | |||
781 | // Now reorder in layer manager only for terrain layer types
|
||
782 | if ((type == Layer3DProps.layer3DOSG)
|
||
783 | || ((type == Layer3DProps.layer3DVector))) |
||
784 | return;
|
||
785 | |||
786 | // Obtain the old position in the layer
|
||
787 | Layer terrainLayer = _terrainFLayerMap.get(layer); |
||
788 | Vector<Integer> terrainOldPos = null; |
||
789 | try {
|
||
790 | terrainOldPos = _terrainLayerManager.getOrder(terrainLayer); |
||
791 | } catch (LayerManagementException e) {
|
||
792 | // TODO Auto-generated catch block
|
||
793 | e.printStackTrace(); |
||
794 | } |
||
795 | |||
796 | int terrainNewPos = 0; |
||
797 | // Compute the new position.
|
||
798 | SingleLayerIterator lyrIterator = new SingleLayerIterator(layers);
|
||
799 | while (lyrIterator.hasNext()) {
|
||
800 | FLayer auxLayer = lyrIterator.next(); |
||
801 | if (auxLayer == layer)
|
||
802 | break;
|
||
803 | Layer3DProps auxProps3D = getLayer3DProps(auxLayer); |
||
804 | if ((auxProps3D.getType() != Layer3DProps.layer3DOSG)
|
||
805 | && (auxProps3D.getType() != Layer3DProps.layer3DVector)) { |
||
806 | terrainNewPos++; |
||
807 | } |
||
808 | |||
809 | } |
||
810 | |||
811 | if ((terrainOldPos == null) || (terrainOldPos.size() == 0)) |
||
812 | return;
|
||
813 | if (terrainOldPos.get(0) != terrainNewPos) |
||
814 | try {
|
||
815 | _terrainLayerManager.moveLayer(terrainOldPos.get(0),
|
||
816 | terrainNewPos); |
||
817 | } catch (LayerManagementException e) {
|
||
818 | // TODO Auto-generated catch block
|
||
819 | e.printStackTrace(); |
||
820 | } |
||
821 | 282 | jzarzoso | //
|
822 | // System.out.println("En el toc antes era el " + oldPos +
|
||
823 | // " y ahora el "
|
||
824 | // + newPos);
|
||
825 | // System.out.println("En el terrain antes era el " + terrainOldPos
|
||
826 | // + " y ahora el " + terrainNewPos);
|
||
827 | 264 | jzarzoso | |
828 | 237 | jzarzoso | // PrintDebugLayers();
|
829 | 166 | jzarzoso | |
830 | 237 | jzarzoso | } |
831 | 166 | jzarzoso | |
832 | 237 | jzarzoso | public void layerRemoved(FLayers3D parent, FLayer layer) { |
833 | System.out.println("Removed layer"); |
||
834 | 260 | jzarzoso | |
835 | 237 | jzarzoso | // to remove group layers to 3D, just remove recursively child data
|
836 | // layers
|
||
837 | 264 | jzarzoso | if (layer instanceof FLayers) { |
838 | FLayers group = (FLayers) layer; |
||
839 | for (int iChild = 0; iChild < group.getLayersCount(); iChild++) { |
||
840 | layerRemoved((FLayers3D) group, group.getLayer(iChild)); |
||
841 | } |
||
842 | getLayer3DProps(layer).setHooked(false);
|
||
843 | return;
|
||
844 | } |
||
845 | |||
846 | if (layer instanceof Classifiable) { |
||
847 | Classifiable legendLyr = (Classifiable) layer; |
||
848 | legendLyr.removeLegendListener((LegendListener) this);
|
||
849 | } |
||
850 | |||
851 | layer.removeLayerListener((LayerListener) this);
|
||
852 | |||
853 | removeLayerToTerrain(layer); |
||
854 | |||
855 | // All layers are removed
|
||
856 | if (layers.getLayersCount() == 0) { |
||
857 | _bEmptyView = true;
|
||
858 | } |
||
859 | |||
860 | 237 | jzarzoso | // PrintDebugLayers();
|
861 | 166 | jzarzoso | |
862 | 237 | jzarzoso | } |
863 | 166 | jzarzoso | |
864 | 237 | jzarzoso | public void legendChanged(LegendChangedEvent e) { |
865 | 264 | jzarzoso | if (!_bListenToLegend)
|
866 | return;
|
||
867 | if ((e == null) && (!visibilityChange)) { |
||
868 | // find layer whose legend changed
|
||
869 | FLayer found = null;
|
||
870 | SingleLayerIterator lyrIterator = new SingleLayerIterator(layers);
|
||
871 | 277 | jzarzoso | Layer3DProps props3D = getLayer3DProps(layers); |
872 | 264 | jzarzoso | while (lyrIterator.hasNext()) {
|
873 | FLayer lyr = lyrIterator.next(); |
||
874 | if (lyr instanceof FLyrVect) { |
||
875 | FLyrVect lyrVect = (FLyrVect) lyr; |
||
876 | 282 | jzarzoso | System.out
|
877 | .println("Changeando la simbologia de la capa vectorial: "
|
||
878 | + lyrVect); |
||
879 | 277 | jzarzoso | long newDrawVersion = layers.getDrawVersion();
|
880 | Layer3DProps vectProps = getLayer3DProps(lyrVect); |
||
881 | 264 | jzarzoso | if ((newDrawVersion - props3D.getDrawVersion()) >= 1) { |
882 | props3D.setDrawVersion(lyrVect.getDrawVersion()); |
||
883 | 277 | jzarzoso | refreshLayerInTerrain(vectProps, true);
|
884 | 264 | jzarzoso | refreshLayerVectorsVisibility(lyrVect); |
885 | _bListenToLegend = false;
|
||
886 | // props3D.VerifyLegend(_terrain.getTerrainName());
|
||
887 | _bListenToLegend = true;
|
||
888 | 166 | jzarzoso | |
889 | 264 | jzarzoso | } |
890 | } |
||
891 | } |
||
892 | |||
893 | // IWindow f = PluginServices.getMDIManager().getActiveWindow();
|
||
894 | // if (f instanceof BaseView) {
|
||
895 | // BaseView view3D = (BaseView) f;
|
||
896 | // view3D.getTOC().refresh();
|
||
897 | // }
|
||
898 | } |
||
899 | visibilityChange = false;
|
||
900 | |||
901 | 237 | jzarzoso | } |
902 | 166 | jzarzoso | |
903 | 237 | jzarzoso | public UpdateDataEvent loadData(RequestDataEvent rde) {
|
904 | 260 | jzarzoso | |
905 | 257 | jzarzoso | if (_terrainLayerMap.size() == 0) |
906 | return null; |
||
907 | if (rde == null) |
||
908 | return null; |
||
909 | 262 | jzarzoso | if (rde.getExtent() == null || rde.getLayer() == null |
910 | || rde.getLayerManager() == null)
|
||
911 | 257 | jzarzoso | return null; |
912 | |||
913 | UpdateDataEvent ude = new UpdateDataEvent();
|
||
914 | ude.copyDataFromRequest(rde); |
||
915 | |||
916 | String layerID = rde.getLayer().getLayerID();
|
||
917 | FLayer layer = (FLayer) _terrainLayerMap.get(layerID); |
||
918 | if (layer == null) |
||
919 | return null; |
||
920 | if (!layer.isVisible())
|
||
921 | return null; |
||
922 | |||
923 | 299 | jzarzoso | boolean hasCache = false; |
924 | |||
925 | 257 | jzarzoso | double minX, minY, width, height;
|
926 | |||
927 | if (_terrain.getCoordinateSystemType() == CoordinateSystemType.PROJECTED) {
|
||
928 | minX = rde.getExtent().xMin(); |
||
929 | minY = rde.getExtent().yMin(); |
||
930 | width = rde.getExtent().xMax() - rde.getExtent().xMin(); |
||
931 | height = rde.getExtent().yMax() - rde.getExtent().yMin(); |
||
932 | } else {
|
||
933 | minX = Math.toDegrees(rde.getExtent().xMin());
|
||
934 | minY = Math.toDegrees(rde.getExtent().yMin());
|
||
935 | width = Math.toDegrees(rde.getExtent().xMax()
|
||
936 | - rde.getExtent().xMin()); |
||
937 | height = Math.toDegrees(rde.getExtent().yMax()
|
||
938 | - rde.getExtent().yMin()); |
||
939 | } |
||
940 | 274 | jzarzoso | |
941 | 289 | jzarzoso | // if (minX == 0 && minY == 0 && width == 0 && height == 0) {
|
942 | //
|
||
943 | // // System.out.println("KLONNNNN");
|
||
944 | // ude.setFailData();
|
||
945 | // return ude;
|
||
946 | //
|
||
947 | // }
|
||
948 | 288 | jzarzoso | |
949 | 274 | jzarzoso | // System.out.println("Valores que vienen de la peticion: " + minX + " "
|
950 | // + minY + " " + width + " " + height);
|
||
951 | 262 | jzarzoso | GeometryManager geoMan; |
952 | 257 | jzarzoso | |
953 | 262 | jzarzoso | geoMan = GeometryLocator.getGeometryManager(); |
954 | 257 | jzarzoso | |
955 | 262 | jzarzoso | Envelope envelope; |
956 | try {
|
||
957 | envelope = geoMan.createEnvelope(Geometry.SUBTYPES.GEOM2D); |
||
958 | envelope.setLowerCorner(geoMan.createPoint(minX, minY, |
||
959 | Geometry.SUBTYPES.GEOM2D)); |
||
960 | envelope.setUpperCorner(geoMan.createPoint(minX + width, minY |
||
961 | + height, Geometry.SUBTYPES.GEOM2D)); |
||
962 | 264 | jzarzoso | |
963 | 302 | jzarzoso | DefaultFLyrRaster rLayer; |
964 | 299 | jzarzoso | |
965 | 269 | jzarzoso | if (layer instanceof DefaultFLyrRaster) { |
966 | |||
967 | 306 | jzarzoso | rLayer = (DefaultFLyrRaster) layer; |
968 | |||
969 | 299 | jzarzoso | if (rLayer.getDataStore().getInternalParameters() instanceof NetCDFDataParameters) |
970 | 269 | jzarzoso | |
971 | 299 | jzarzoso | hasCache = false;
|
972 | |||
973 | 306 | jzarzoso | else {
|
974 | 299 | jzarzoso | hasCache = true;
|
975 | 306 | jzarzoso | } |
976 | 299 | jzarzoso | } |
977 | |||
978 | if (hasCache) {
|
||
979 | |||
980 | 302 | jzarzoso | rLayer = (DefaultFLyrRaster) layer; |
981 | 269 | jzarzoso | boolean exists = _cachedLayers.containsKey(rLayer);
|
982 | |||
983 | if (!exists) {
|
||
984 | |||
985 | _cachedLayers.put(rLayer, getCacheStruct(rLayer)); |
||
986 | |||
987 | } |
||
988 | |||
989 | CacheStruct cacheStruct = _cachedLayers.get(rLayer); |
||
990 | |||
991 | RasterQuery query = RasterLocator.getManager().createQuery(); |
||
992 | |||
993 | org.gvsig.fmap.dal.coverage.datastruct.Extent extent = RasterLocator |
||
994 | .getManager().getDataStructFactory() |
||
995 | .createExtent(minX, minY + height, minX + width, minY); |
||
996 | |||
997 | 271 | jzarzoso | query.setTileParameters(rde.getTileLevel(), rde.getTileX(), |
998 | 269 | jzarzoso | rde.getTileY(), extent, cacheStruct); |
999 | |||
1000 | 299 | jzarzoso | // query.setAreaOfInterest(extent, 512, 512);
|
1001 | |||
1002 | 289 | jzarzoso | // System.out.println("Tile Parameters:");
|
1003 | // System.out.println("TileLevel: " + rde.getTileLevel());
|
||
1004 | // System.out.println("TileX = " + rde.getTileX());
|
||
1005 | // System.out.println("TileY = " + rde.getTileY());
|
||
1006 | // System.out.println("Extent = " + extent.getULX() + " "
|
||
1007 | // + extent.getULY() + " " + extent.getLRX() + " "
|
||
1008 | // + extent.getLRY());
|
||
1009 | 288 | jzarzoso | |
1010 | 269 | jzarzoso | try {
|
1011 | Object[] result = rLayer.getDataStore().queryArray(query); |
||
1012 | Buffer rBuff = (Buffer) result[0]; |
||
1013 | 299 | jzarzoso | Buffer transparencyBuffer;
|
1014 | 284 | jzarzoso | |
1015 | 299 | jzarzoso | if (result.length < 2) |
1016 | transparencyBuffer = null;
|
||
1017 | else
|
||
1018 | transparencyBuffer = (Buffer) result[1]; |
||
1019 | |||
1020 | 271 | jzarzoso | int numBands = rBuff.getBandCount();
|
1021 | if (transparencyBuffer != null) { |
||
1022 | 269 | jzarzoso | |
1023 | 274 | jzarzoso | // System.out
|
1024 | // .println("Tengo Transparency buffer con "
|
||
1025 | // + transparencyBuffer.getBandCount()
|
||
1026 | // + " bandas");
|
||
1027 | 271 | jzarzoso | numBands++; |
1028 | |||
1029 | } |
||
1030 | |||
1031 | 274 | jzarzoso | // System.out.println("Tile ancho: " + rBuff.getWidth()
|
1032 | // + " alto: " + rBuff.getHeight()
|
||
1033 | // + " bandas totales incluyendo alpha (si tiene): "
|
||
1034 | // + numBands);
|
||
1035 | 269 | jzarzoso | |
1036 | byte[] data = new byte[rBuff.getWidth() * rBuff.getHeight() |
||
1037 | 271 | jzarzoso | * numBands]; |
1038 | 269 | jzarzoso | |
1039 | int dataType = convertDataType(rBuff.getDataType());
|
||
1040 | 271 | jzarzoso | int pixelFormat = convertPixelFormat(numBands);
|
1041 | 269 | jzarzoso | |
1042 | int cont = 0; |
||
1043 | |||
1044 | for (int i = 0; i < rBuff.getWidth(); i++) { |
||
1045 | |||
1046 | for (int j = 0; j < rBuff.getHeight(); j++) { |
||
1047 | |||
1048 | for (int k = 0; k < rBuff.getBandCount(); k++) { |
||
1049 | |||
1050 | switch (rBuff.getDataType()) {
|
||
1051 | case Buffer.TYPE_BYTE: |
||
1052 | data[cont] = (byte) (rBuff.getElemByte(i,
|
||
1053 | j, k)); |
||
1054 | cont++; |
||
1055 | break;
|
||
1056 | case Buffer.TYPE_DOUBLE: |
||
1057 | data[cont] = (byte) (Math.round(rBuff |
||
1058 | 299 | jzarzoso | .getElemDouble(i, j, k))); |
1059 | 269 | jzarzoso | cont++; |
1060 | break;
|
||
1061 | case Buffer.TYPE_FLOAT: |
||
1062 | data[cont] = (byte) (Math.round(rBuff |
||
1063 | .getElemFloat(i, j, k))); |
||
1064 | cont++; |
||
1065 | break;
|
||
1066 | case Buffer.TYPE_INT: |
||
1067 | data[cont] = (byte) (rBuff.getElemInt(i, j,
|
||
1068 | k) & 0xffffffff);
|
||
1069 | cont++; |
||
1070 | break;
|
||
1071 | case Buffer.TYPE_SHORT: |
||
1072 | case Buffer.TYPE_USHORT: |
||
1073 | data[cont] = (byte) (rBuff.getElemShort(i,
|
||
1074 | j, k) & 0xffff);
|
||
1075 | cont++; |
||
1076 | break;
|
||
1077 | } |
||
1078 | 271 | jzarzoso | } |
1079 | 269 | jzarzoso | |
1080 | 271 | jzarzoso | if (transparencyBuffer != null) { |
1081 | |||
1082 | switch (transparencyBuffer.getDataType()) {
|
||
1083 | case Buffer.TYPE_BYTE: |
||
1084 | |||
1085 | if (transparencyBuffer.getElemByte(i, j, 0) == 0) |
||
1086 | data[cont] = (byte) (0); |
||
1087 | else
|
||
1088 | data[cont] = (byte) (255); |
||
1089 | cont++; |
||
1090 | break;
|
||
1091 | case Buffer.TYPE_DOUBLE: |
||
1092 | data[cont] = (byte) (Math |
||
1093 | .round(transparencyBuffer |
||
1094 | .getElemInt(i, j, 0)));
|
||
1095 | cont++; |
||
1096 | break;
|
||
1097 | case Buffer.TYPE_FLOAT: |
||
1098 | data[cont] = (byte) (Math |
||
1099 | .round(transparencyBuffer |
||
1100 | .getElemFloat(i, j, 0)));
|
||
1101 | cont++; |
||
1102 | break;
|
||
1103 | case Buffer.TYPE_INT: |
||
1104 | data[cont] = (byte) (transparencyBuffer
|
||
1105 | .getElemInt(i, j, 0) & 0xffffffff); |
||
1106 | cont++; |
||
1107 | break;
|
||
1108 | case Buffer.TYPE_SHORT: |
||
1109 | case Buffer.TYPE_USHORT: |
||
1110 | data[cont] = (byte) (transparencyBuffer
|
||
1111 | .getElemShort(i, j, 0) & 0xffff); |
||
1112 | cont++; |
||
1113 | break;
|
||
1114 | } |
||
1115 | |||
1116 | 269 | jzarzoso | } |
1117 | |||
1118 | } |
||
1119 | |||
1120 | } |
||
1121 | |||
1122 | 299 | jzarzoso | // try {
|
1123 | // BufferedImage myImage = new BufferedImage(
|
||
1124 | // rBuff.getWidth(), rBuff.getHeight(),
|
||
1125 | // BufferedImage.TYPE_4BYTE_ABGR);
|
||
1126 | // myImage = getLayerDrawImage(layer, envelope);
|
||
1127 | // String name = Integer.toString(rde.getTileLevel()) + "-"
|
||
1128 | // + Integer.toString(rde.getTileX()) + "-"
|
||
1129 | // + Integer.toString(rde.getTileY());
|
||
1130 | //
|
||
1131 | // File file = new File("/home/jzarzoso/cacheNetCDF/"
|
||
1132 | // + name + ".png");
|
||
1133 | //
|
||
1134 | // ImageIO.write(myImage, "png", file);
|
||
1135 | //
|
||
1136 | // } catch (IOException e) {
|
||
1137 | // // TODO Auto-generated catch block
|
||
1138 | // e.printStackTrace();
|
||
1139 | // }
|
||
1140 | |||
1141 | 269 | jzarzoso | ude.setRasterData( |
1142 | data, |
||
1143 | rBuff.getWidth(), |
||
1144 | rBuff.getHeight(), |
||
1145 | 271 | jzarzoso | numBands, |
1146 | 269 | jzarzoso | pixelFormat, |
1147 | org.gvsig.osgvp.core.osg.Image.DataType.GL_UNSIGNED_BYTE); |
||
1148 | |||
1149 | 299 | jzarzoso | // ude.setRasterData(getLayerDrawImage(layer, envelope));
|
1150 | |||
1151 | 269 | jzarzoso | } catch (ProcessInterruptedException e) {
|
1152 | // TODO Auto-generated catch block
|
||
1153 | e.printStackTrace(); |
||
1154 | } catch (RasterDriverException e) {
|
||
1155 | e.printStackTrace(); |
||
1156 | } catch (InvalidSetViewException e) {
|
||
1157 | // TODO Auto-generated catch block
|
||
1158 | e.printStackTrace(); |
||
1159 | 289 | jzarzoso | } catch (NullPointerException e) { |
1160 | 306 | jzarzoso | // ude.setFailData();
|
1161 | System.out.println("Problem getting the tile"); |
||
1162 | 289 | jzarzoso | return ude;
|
1163 | |||
1164 | 269 | jzarzoso | } |
1165 | |||
1166 | } |
||
1167 | |||
1168 | 299 | jzarzoso | else {
|
1169 | 271 | jzarzoso | |
1170 | 299 | jzarzoso | BufferedImage image = getLayerDrawImage(layer, envelope);
|
1171 | 271 | jzarzoso | |
1172 | 306 | jzarzoso | if (image != null) |
1173 | 299 | jzarzoso | ude.setRasterData(image); |
1174 | |||
1175 | 271 | jzarzoso | } |
1176 | |||
1177 | 262 | jzarzoso | } catch (CreateEnvelopeException e) {
|
1178 | e.printStackTrace(); |
||
1179 | } catch (CreateGeometryException e) {
|
||
1180 | e.printStackTrace(); |
||
1181 | 288 | jzarzoso | } catch (LocatorException e) {
|
1182 | // TODO Auto-generated catch block
|
||
1183 | e.printStackTrace(); |
||
1184 | 262 | jzarzoso | } |
1185 | |||
1186 | 257 | jzarzoso | return ude;
|
1187 | 260 | jzarzoso | |
1188 | 237 | jzarzoso | } |
1189 | 166 | jzarzoso | |
1190 | 269 | jzarzoso | protected int convertDataType(int type) { |
1191 | |||
1192 | switch (type) {
|
||
1193 | |||
1194 | case DataBuffer.TYPE_BYTE: |
||
1195 | return org.gvsig.osgvp.core.osg.Image.DataType.GL_BYTE;
|
||
1196 | |||
1197 | case DataBuffer.TYPE_DOUBLE: |
||
1198 | return org.gvsig.osgvp.core.osg.Image.DataType.GL_DOUBLE;
|
||
1199 | |||
1200 | case DataBuffer.TYPE_FLOAT: |
||
1201 | return org.gvsig.osgvp.core.osg.Image.DataType.GL_FLOAT;
|
||
1202 | |||
1203 | case DataBuffer.TYPE_INT: |
||
1204 | return org.gvsig.osgvp.core.osg.Image.DataType.GL_INT;
|
||
1205 | |||
1206 | case DataBuffer.TYPE_SHORT: |
||
1207 | return org.gvsig.osgvp.core.osg.Image.DataType.GL_SHORT;
|
||
1208 | |||
1209 | case DataBuffer.TYPE_USHORT: |
||
1210 | return org.gvsig.osgvp.core.osg.Image.DataType.GL_UNSIGNED_SHORT;
|
||
1211 | |||
1212 | } |
||
1213 | |||
1214 | return org.gvsig.osgvp.core.osg.Image.DataType.GL_BYTE;
|
||
1215 | |||
1216 | } |
||
1217 | |||
1218 | protected int convertPixelFormat(int type) { |
||
1219 | |||
1220 | switch (type) {
|
||
1221 | |||
1222 | case 1: |
||
1223 | return org.gvsig.osgvp.core.osg.Image.PixelFormat.GL_LUMINANCE;
|
||
1224 | |||
1225 | case 2: |
||
1226 | return org.gvsig.osgvp.core.osg.Image.PixelFormat.GL_LUMINANCE_ALPHA;
|
||
1227 | |||
1228 | case 3: |
||
1229 | return org.gvsig.osgvp.core.osg.Image.PixelFormat.GL_RGB;
|
||
1230 | |||
1231 | case 4: |
||
1232 | return org.gvsig.osgvp.core.osg.Image.PixelFormat.GL_RGBA;
|
||
1233 | |||
1234 | } |
||
1235 | |||
1236 | return org.gvsig.osgvp.core.osg.Image.PixelFormat.GL_COLOR_INDEX;
|
||
1237 | |||
1238 | } |
||
1239 | |||
1240 | 262 | jzarzoso | protected class MyCancel implements Cancellable { |
1241 | private boolean cancel = false; |
||
1242 | |||
1243 | public MyCancel() {
|
||
1244 | } |
||
1245 | |||
1246 | public void setCanceled(boolean canceled) { |
||
1247 | cancel = canceled; |
||
1248 | } |
||
1249 | |||
1250 | public boolean isCanceled() { |
||
1251 | return cancel;
|
||
1252 | } |
||
1253 | } |
||
1254 | |||
1255 | 282 | jzarzoso | private BufferedImage getLayerDrawImage(FLayer layer, Envelope envelope) { |
1256 | |||
1257 | int size = 256; |
||
1258 | BufferedImage image = new BufferedImage(size, size, |
||
1259 | BufferedImage.TYPE_4BYTE_ABGR);
|
||
1260 | |||
1261 | ViewPort vp = new ViewPort(_viewProjection);
|
||
1262 | vp.setEnvelope(envelope); // the real extent of the tile
|
||
1263 | |||
1264 | vp.setAdjustable(false);
|
||
1265 | vp.setImageSize(new Dimension(size, size)); |
||
1266 | vp.setDist1pixel(0.000000001);
|
||
1267 | |||
1268 | Graphics2D graphics = image.createGraphics();
|
||
1269 | Color backgColor = new Color(255, 255, 255, 0); // transparent |
||
1270 | // background
|
||
1271 | graphics.setColor(backgColor); |
||
1272 | graphics.fillRect(0, 0, size, size); |
||
1273 | |||
1274 | double scale = 0.5 * (layer.getMaxScale() + layer.getMinScale()); |
||
1275 | 284 | jzarzoso | |
1276 | 282 | jzarzoso | try {
|
1277 | layer.draw(image, graphics, vp, new MyCancel(), scale);
|
||
1278 | |||
1279 | } catch (Exception e) { |
||
1280 | return null; |
||
1281 | } |
||
1282 | |||
1283 | return image;
|
||
1284 | |||
1285 | } |
||
1286 | |||
1287 | 237 | jzarzoso | public void nameChanged(LayerEvent e) { |
1288 | System.out.println("Name change"); |
||
1289 | 166 | jzarzoso | |
1290 | 237 | jzarzoso | } |
1291 | 166 | jzarzoso | |
1292 | 237 | jzarzoso | public void refreshLayerInTerrain(Layer3DProps props, boolean bRemoveCache) { |
1293 | 260 | jzarzoso | |
1294 | 237 | jzarzoso | System.out.println("Refresh"); |
1295 | 274 | jzarzoso | if (props == null) |
1296 | return;
|
||
1297 | 166 | jzarzoso | |
1298 | 274 | jzarzoso | if (_terrain == null) |
1299 | return; // view not opened yet |
||
1300 | |||
1301 | // clear cache
|
||
1302 | |||
1303 | // refresh layer in terrain
|
||
1304 | int type = props.getType();
|
||
1305 | if ((type == Layer3DProps.layer3DImage)
|
||
1306 | || (type == Layer3DProps.layer3DElevation) |
||
1307 | || (type == Layer3DProps.layer3DVectorMR)) { |
||
1308 | |||
1309 | try {
|
||
1310 | _terrainLayerManager.invalidateLayer(props.getTerrainLayer()); |
||
1311 | } catch (LayerManagementException e) {
|
||
1312 | // TODO Auto-generated catch block
|
||
1313 | e.printStackTrace(); |
||
1314 | } |
||
1315 | } else if (type == Layer3DProps.layer3DVector) { |
||
1316 | invalidateVectorLayer(props); |
||
1317 | } |
||
1318 | |||
1319 | 237 | jzarzoso | } |
1320 | 166 | jzarzoso | |
1321 | 237 | jzarzoso | public boolean removeCache(File path) { |
1322 | if (path.exists()) {
|
||
1323 | File[] files = path.listFiles(); |
||
1324 | for (int i = 0; i < files.length; i++) { |
||
1325 | if (files[i].isDirectory()) {
|
||
1326 | removeCache(files[i]); |
||
1327 | } else {
|
||
1328 | files[i].delete(); |
||
1329 | } |
||
1330 | } |
||
1331 | } |
||
1332 | return (path.delete());
|
||
1333 | } |
||
1334 | 166 | jzarzoso | |
1335 | 237 | jzarzoso | public void removeLayerToTerrain(FLayer layer) { |
1336 | // TODO Auto-generated method stub
|
||
1337 | 265 | jzarzoso | Layer3DProps props3D = getLayer3DProps(layer); |
1338 | 166 | jzarzoso | |
1339 | 265 | jzarzoso | if (props3D.getType() == Layer3DProps.layer3DVector) {
|
1340 | // DeleteVectors(layer, props3D);
|
||
1341 | } else if (props3D.getType() == Layer3DProps.layer3DOSG) { |
||
1342 | DeleteOSGLayer(layer, props3D); |
||
1343 | } else {
|
||
1344 | Layer terrainLayer = _terrainFLayerMap.get(layer); |
||
1345 | if (terrainLayer != null) { |
||
1346 | 268 | jzarzoso | // FLayerCacheService cacheService = (FLayerCacheService)
|
1347 | // props3D
|
||
1348 | // .getCacheService();
|
||
1349 | // if (cacheService != null)
|
||
1350 | // try {
|
||
1351 | // cacheService.free();
|
||
1352 | // } catch (Throwable e) {
|
||
1353 | // // TODO Auto-generated catch block
|
||
1354 | // e.printStackTrace();
|
||
1355 | // }
|
||
1356 | 265 | jzarzoso | _terrainLayerMap.remove(terrainLayer.getLayerID()); |
1357 | _terrainFLayerMap.remove(layer); |
||
1358 | |||
1359 | try {
|
||
1360 | _terrainLayerManager.removeLayer(terrainLayer); |
||
1361 | } catch (LayerManagementException e) {
|
||
1362 | // TODO Auto-generated catch block
|
||
1363 | e.printStackTrace(); |
||
1364 | } |
||
1365 | } |
||
1366 | } |
||
1367 | |||
1368 | 237 | jzarzoso | } |
1369 | 166 | jzarzoso | |
1370 | 237 | jzarzoso | public void selectionChanged(SelectionEvent e) { |
1371 | // TODO Auto-generated method stub
|
||
1372 | // SingleLayerIterator lyrIterator = new SingleLayerIterator(layers);
|
||
1373 | // while (lyrIterator.hasNext()) {
|
||
1374 | // FLayer layer = lyrIterator.next();
|
||
1375 | // Layer3DProps props3D = getLayer3DProps(layer);
|
||
1376 | // if (props3D.getType() != Layer3DProps.layer3DOSG) {
|
||
1377 | // if (layer.getClass().equals(FLyrVect.class)) {
|
||
1378 | // FLyrVect lyr = (FLyrVect) layer;
|
||
1379 | //
|
||
1380 | // FBitSet selection = null;
|
||
1381 | // try {
|
||
1382 | // selection = lyr.getRecordset().getSelectionSupport()
|
||
1383 | // .getSelection();
|
||
1384 | // } catch (ReadDriverException e1) {
|
||
1385 | // // TODO Auto-generated catch block
|
||
1386 | // e1.printStackTrace();
|
||
1387 | // }
|
||
1388 | //
|
||
1389 | // if ((selection.cardinality() == 0)
|
||
1390 | // || (!(selection.isEmpty()))) {
|
||
1391 | // Layer3DProps props = Layer3DProps
|
||
1392 | // .getLayer3DProps(layer);
|
||
1393 | // refreshLayerInTerrain(props, true);
|
||
1394 | // if (layer instanceof FLyrVect) {
|
||
1395 | // FLyrVect fvect = (FLyrVect) layer;
|
||
1396 | // props.drawVersion = fvect.getDrawVersion();
|
||
1397 | // }
|
||
1398 | // }
|
||
1399 | // }
|
||
1400 | // }
|
||
1401 | // }
|
||
1402 | 166 | jzarzoso | |
1403 | 237 | jzarzoso | } |
1404 | 166 | jzarzoso | |
1405 | 237 | jzarzoso | public void setDataManager(JavaDataDriver manager) { |
1406 | 262 | jzarzoso | _terrainDataManager = manager; |
1407 | _terrainDataManager.setDataLoader(this);
|
||
1408 | 166 | jzarzoso | |
1409 | 237 | jzarzoso | } |
1410 | 166 | jzarzoso | |
1411 | 237 | jzarzoso | public void setLayerManager(LayerManager manager) { |
1412 | _terrainLayerManager = manager; |
||
1413 | 166 | jzarzoso | |
1414 | 237 | jzarzoso | } |
1415 | 166 | jzarzoso | |
1416 | 237 | jzarzoso | public void setLoading(boolean bLoading) { |
1417 | _bLoading = bLoading; |
||
1418 | 166 | jzarzoso | |
1419 | 237 | jzarzoso | } |
1420 | 166 | jzarzoso | |
1421 | 237 | jzarzoso | public void setRenewCanvasOff(boolean renewCanvasOff) { |
1422 | _renewCanvasOff = renewCanvasOff; |
||
1423 | 166 | jzarzoso | |
1424 | 237 | jzarzoso | } |
1425 | 166 | jzarzoso | |
1426 | 237 | jzarzoso | public void setTerrain(Terrain terrain) { |
1427 | if (_terrain == terrain)
|
||
1428 | return;
|
||
1429 | 166 | jzarzoso | |
1430 | 237 | jzarzoso | _terrain = terrain; |
1431 | 166 | jzarzoso | |
1432 | 237 | jzarzoso | // add layers to terrain necessary when we are loading
|
1433 | addCurrentLayers(); |
||
1434 | 166 | jzarzoso | |
1435 | 237 | jzarzoso | } |
1436 | 166 | jzarzoso | |
1437 | 237 | jzarzoso | public void setVerticalExaggeration(float verticalExaggeration) { |
1438 | _verticalExaggeration = verticalExaggeration; |
||
1439 | 166 | jzarzoso | |
1440 | 237 | jzarzoso | } |
1441 | 166 | jzarzoso | |
1442 | 237 | jzarzoso | public void setViewProjection(IProjection projection) { |
1443 | _viewProjection = projection; |
||
1444 | 166 | jzarzoso | |
1445 | 237 | jzarzoso | } |
1446 | 166 | jzarzoso | |
1447 | 237 | jzarzoso | public void setViewer(IViewerContainer canvas) { |
1448 | _canvas3d = canvas; |
||
1449 | _terrainViewer = (TerrainViewer) _canvas3d.getOSGViewer(); |
||
1450 | 166 | jzarzoso | |
1451 | 237 | jzarzoso | } |
1452 | 166 | jzarzoso | |
1453 | 237 | jzarzoso | public void visibilityChanged(LayerEvent e) { |
1454 | 274 | jzarzoso | FLayer lyr = e.getSource(); |
1455 | 166 | jzarzoso | |
1456 | 274 | jzarzoso | // if (props3D.getType() == Layer3DProps.layer3DVector) {
|
1457 | // refreshLayerVectorsVisibility(lyr);
|
||
1458 | // } else if (props3D.getType() == Layer3DProps.layer3DOSG) {
|
||
1459 | // refreshLayer3DOSGVisibility(lyr);
|
||
1460 | // } else {
|
||
1461 | refreshLayerVisibility(lyr); |
||
1462 | // }
|
||
1463 | visibilityChange = true;
|
||
1464 | |||
1465 | 237 | jzarzoso | } |
1466 | 274 | jzarzoso | |
1467 | 273 | jzarzoso | private void refreshLayerVisibility(FLayer layer) { |
1468 | 166 | jzarzoso | |
1469 | 273 | jzarzoso | Layer terrainLayer = _terrainFLayerMap.get(layer); |
1470 | terrainLayer.setEnabled(layer.isVisible()); |
||
1471 | _terrainLayerManager.updateLayers(); |
||
1472 | |||
1473 | } |
||
1474 | |||
1475 | 265 | jzarzoso | public void zoomToEnvelope(Envelope geoEnvelope) { |
1476 | if (geoEnvelope == null) |
||
1477 | 237 | jzarzoso | return;
|
1478 | 265 | jzarzoso | if ((geoEnvelope.getLength(0) == 0) || (geoEnvelope.getLength(1) == 0)) |
1479 | 237 | jzarzoso | return;
|
1480 | 166 | jzarzoso | |
1481 | 237 | jzarzoso | double maxHeight = 0.0; |
1482 | 166 | jzarzoso | |
1483 | 294 | jzarzoso | // Getting envelope positions
|
1484 | double minLat = geoEnvelope.getMinimum(0); |
||
1485 | double maxLat = geoEnvelope.getMaximum(0); |
||
1486 | 298 | jzarzoso | double cenLon = geoEnvelope.getCenter(0); |
1487 | double cenLat = geoEnvelope.getCenter(1); |
||
1488 | 166 | jzarzoso | |
1489 | 237 | jzarzoso | double elevation = 0; |
1490 | 166 | jzarzoso | |
1491 | 237 | jzarzoso | // calculate altitude
|
1492 | double avLat = 0; |
||
1493 | if (minLat > 0.0 || maxLat < 0.0) |
||
1494 | avLat = Math.min(Math.abs(minLat), Math.abs(maxLat)); |
||
1495 | 298 | jzarzoso | double avLon = Math.min(180.0, geoEnvelope.getLength(1)); |
1496 | 166 | jzarzoso | |
1497 | 237 | jzarzoso | double terrainRadius = _terrain.getRadiusEquatorial();
|
1498 | double radiusLat = terrainRadius * Math.cos(Math.toRadians(avLat)); |
||
1499 | double deltaLon = Math.sqrt(2 * radiusLat * radiusLat |
||
1500 | * (1 - Math.cos(Math.toRadians(avLon)))); |
||
1501 | double deltaLat = Math.sqrt(2 * terrainRadius * terrainRadius |
||
1502 | 298 | jzarzoso | * (1 - Math.cos(Math.toRadians(geoEnvelope.getLength(0))))); |
1503 | 166 | jzarzoso | |
1504 | 237 | jzarzoso | // Calculate XYZ positions for camera.
|
1505 | 166 | jzarzoso | |
1506 | 237 | jzarzoso | int terrainType = _terrain.getCoordinateSystemType();
|
1507 | 299 | jzarzoso | |
1508 | 294 | jzarzoso | double zoomFactor = 1.5; |
1509 | 299 | jzarzoso | if (terrainType == Terrain.CoordinateSystemType.PROJECTED)
|
1510 | 294 | jzarzoso | zoomFactor = 1.3;
|
1511 | elevation = (Math.max(deltaLon, deltaLat) * zoomFactor) + maxHeight;
|
||
1512 | 166 | jzarzoso | |
1513 | 237 | jzarzoso | Vec3 eye = new Vec3();
|
1514 | Vec3 center = new Vec3();
|
||
1515 | Vec3 up = new Vec3();
|
||
1516 | // Calculate positions for PLAIN MODE.
|
||
1517 | if (terrainType == Terrain.CoordinateSystemType.PROJECTED) {
|
||
1518 | 166 | jzarzoso | |
1519 | 298 | jzarzoso | double difx = (geoEnvelope.getMaximum(1) - geoEnvelope |
1520 | .getMinimum(1)) / 1.2d; |
||
1521 | double dify = (geoEnvelope.getMaximum(0) - geoEnvelope |
||
1522 | 268 | jzarzoso | .getMinimum(0)) / 1.2d; |
1523 | 237 | jzarzoso | double height;
|
1524 | 166 | jzarzoso | |
1525 | 237 | jzarzoso | height = Math.sqrt(difx * difx + dify * dify);
|
1526 | double fullWindowFactor = 1.7; |
||
1527 | // EYE
|
||
1528 | eye.setX(cenLon); |
||
1529 | eye.setY(cenLat); |
||
1530 | eye.setZ(height * fullWindowFactor); |
||
1531 | // CENTER
|
||
1532 | center.setX(cenLon); |
||
1533 | center.setY(cenLat); |
||
1534 | center.setZ(0.0);
|
||
1535 | // UP
|
||
1536 | up.setX(0.0);
|
||
1537 | up.setY(1.0);
|
||
1538 | up.setZ(0.0);
|
||
1539 | } else
|
||
1540 | // Calculate positions for SPHERICAL MODE.
|
||
1541 | if (terrainType == Terrain.CoordinateSystemType.GEOCENTRIC) {
|
||
1542 | // EYE
|
||
1543 | 298 | jzarzoso | Vec3 aux = new Vec3(cenLon, cenLat, elevation);
|
1544 | 237 | jzarzoso | eye = _terrain.convertLatLongHeightToXYZ(aux); |
1545 | // CENTER
|
||
1546 | center.setX(0.0);
|
||
1547 | center.setY(0.0);
|
||
1548 | center.setZ(0.0);
|
||
1549 | // UP
|
||
1550 | up.setX(0.0);
|
||
1551 | up.setY(0.0);
|
||
1552 | up.setZ(1.0);
|
||
1553 | } |
||
1554 | Camera cam = new Camera();
|
||
1555 | cam.setViewByLookAt(eye, center, up); |
||
1556 | 166 | jzarzoso | |
1557 | 237 | jzarzoso | _terrainViewer.setCamera(cam); |
1558 | 166 | jzarzoso | |
1559 | 237 | jzarzoso | } |
1560 | 166 | jzarzoso | |
1561 | 277 | jzarzoso | public void editionChanged(LayerEvent e) { |
1562 | 237 | jzarzoso | // TODO Auto-generated method stub
|
1563 | 282 | jzarzoso | |
1564 | 237 | jzarzoso | } |
1565 | 166 | jzarzoso | |
1566 | 277 | jzarzoso | public void drawValueChanged(LayerEvent e) { |
1567 | 237 | jzarzoso | // TODO Auto-generated method stub
|
1568 | 282 | jzarzoso | |
1569 | 277 | jzarzoso | } |
1570 | 260 | jzarzoso | |
1571 | 277 | jzarzoso | public boolean symbolChanged(SymbolLegendEvent e) { |
1572 | |||
1573 | System.out.println("Symbol changed"); |
||
1574 | return false; |
||
1575 | 237 | jzarzoso | } |
1576 | 166 | jzarzoso | |
1577 | 277 | jzarzoso | public void legendCleared(LegendClearEvent event) { |
1578 | 237 | jzarzoso | // TODO Auto-generated method stub
|
1579 | 282 | jzarzoso | |
1580 | 277 | jzarzoso | } |
1581 | 260 | jzarzoso | |
1582 | 306 | jzarzoso | public static class RegisterPersistence implements Callable { |
1583 | |||
1584 | public Object call() throws Exception { |
||
1585 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
1586 | if (manager.getDefinition(MapContext.class) == null) { |
||
1587 | MapContext.registerPersistent(); |
||
1588 | } |
||
1589 | DynStruct definition = manager.addDefinition( |
||
1590 | MapContext3DImpl.class, "MapContext3DImpl",
|
||
1591 | "MapContext3DImpl Persistence definition", null, null); |
||
1592 | definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, |
||
1593 | "MapContext");
|
||
1594 | |||
1595 | return Boolean.TRUE; |
||
1596 | } |
||
1597 | } |
||
1598 | |||
1599 | 166 | jzarzoso | } |