Revision 630
2.1/branches/org.gvsig.view3d_soporte_bbdd_proyecciones/org.gvsig.view3d.app/org.gvsig.view3d.app.common/src/main/java/org/gvsig/view3d/app/mainplugin/SynchronizeView3DExtension.java | ||
---|---|---|
35 | 35 |
(ExtendedPropertiesSupport) view.getViewDocument(), |
36 | 36 |
TYPE.FLAT); |
37 | 37 |
if (mapControl3DFlat != null) { |
38 |
mapControl3DFlat.synchronizeLayers();
|
|
38 |
mapControl3DFlat.reloadLayers();
|
|
39 | 39 |
} |
40 | 40 |
|
41 | 41 |
MapControl3D mapControl3DSphere = |
... | ... | |
43 | 43 |
(ExtendedPropertiesSupport) view.getViewDocument(), |
44 | 44 |
TYPE.SPHERE); |
45 | 45 |
if (mapControl3DSphere != null) { |
46 |
mapControl3DSphere.synchronizeLayers();
|
|
46 |
mapControl3DSphere.reloadLayers();
|
|
47 | 47 |
} |
48 | 48 |
} |
49 | 49 |
} |
2.1/branches/org.gvsig.view3d_soporte_bbdd_proyecciones/org.gvsig.view3d.app/org.gvsig.view3d.app.common/src/main/java/org/gvsig/view3d/app/mainplugin/View3DExtension.java | ||
---|---|---|
31 | 31 |
import org.gvsig.app.project.documents.view.ViewDocument; |
32 | 32 |
import org.gvsig.app.project.documents.view.gui.IView; |
33 | 33 |
import org.gvsig.app.project.documents.view.legend.gui.ThemeManagerWindow; |
34 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
35 | 34 |
import org.gvsig.fmap.mapcontext.layers.ExtendedPropertiesSupport; |
36 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
37 | 35 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
38 | 36 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
39 | 37 |
import org.gvsig.propertypage.PropertiesPageManager; |
... | ... | |
142 | 140 |
.equals(actionCommand))) { |
143 | 141 |
|
144 | 142 |
View3DSwingManager manager = View3DSwingLocator.getManager(); |
145 |
MapContext mapContext = view.getMapControl().getMapContext(); |
|
146 | 143 |
TYPE type = getType(actionCommand); |
147 | 144 |
|
148 | 145 |
if (type != null) { |
149 |
|
|
150 | 146 |
MapControl3D mapControl3D = |
151 | 147 |
manager.getMapControl3D( |
152 | 148 |
(ExtendedPropertiesSupport) view.getViewDocument(), |
153 | 149 |
getType(actionCommand)); |
154 | 150 |
|
155 |
FLayers layers = mapContext.getLayers(); |
|
156 |
|
|
157 |
boolean isEPSG4326 = |
|
158 |
mapContext.getProjection().getAbrev().equals("EPSG:4326"); |
|
159 |
|
|
160 |
if (mapControl3D == null && layers.getLayersCount() > 0 |
|
161 |
&& isEPSG4326) { |
|
151 |
if (mapControl3D == null) { |
|
162 | 152 |
return true; |
163 | 153 |
} |
164 | 154 |
} |
2.1/branches/org.gvsig.view3d_soporte_bbdd_proyecciones/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/DefaultSynchronizer.java | ||
---|---|---|
1 | 1 |
package org.gvsig.view3d.swing.impl; |
2 | 2 |
|
3 | 3 |
import gov.nasa.worldwind.WorldWindow; |
4 |
import gov.nasa.worldwind.avlist.AVKey; |
|
5 |
import gov.nasa.worldwind.avlist.AVList; |
|
6 | 4 |
import gov.nasa.worldwind.geom.Angle; |
7 | 5 |
import gov.nasa.worldwind.geom.Box; |
8 | 6 |
import gov.nasa.worldwind.geom.Position; |
9 | 7 |
import gov.nasa.worldwind.geom.Sector; |
10 | 8 |
import gov.nasa.worldwind.globes.ElevationModel; |
11 | 9 |
import gov.nasa.worldwind.layers.Layer; |
10 |
import gov.nasa.worldwind.layers.LayerList; |
|
12 | 11 |
import gov.nasa.worldwind.terrain.CompoundElevationModel; |
13 | 12 |
import gov.nasa.worldwind.view.orbit.OrbitView; |
14 | 13 |
|
15 | 14 |
import java.awt.geom.Point2D; |
16 |
import java.util.ArrayList; |
|
17 |
import java.util.HashMap; |
|
18 |
import java.util.List; |
|
19 | 15 |
import java.util.Map; |
20 |
import java.util.Map.Entry;
|
|
16 |
import java.util.WeakHashMap;
|
|
21 | 17 |
|
22 |
import org.gvsig.fmap.dal.exception.DataException;
|
|
18 |
import org.gvsig.fmap.crs.CRSFactory;
|
|
23 | 19 |
import org.gvsig.fmap.geom.primitive.Envelope; |
24 | 20 |
import org.gvsig.fmap.mapcontext.MapContext; |
25 | 21 |
import org.gvsig.fmap.mapcontext.ViewPort; |
... | ... | |
35 | 31 |
import org.gvsig.fmap.mapcontext.layers.LayerEvent; |
36 | 32 |
import org.gvsig.fmap.mapcontext.layers.LayerListener; |
37 | 33 |
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent; |
38 |
import org.gvsig.fmap.mapcontext.layers.operations.LayersVisitor; |
|
39 |
import org.gvsig.tools.exception.BaseException; |
|
40 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
41 | 34 |
import org.gvsig.view3d.lib.api.View3DLocator; |
42 |
import org.gvsig.view3d.lib.api.View3DManager; |
|
43 | 35 |
import org.gvsig.view3d.lib.api.properties.LayerProperties3D; |
44 | 36 |
import org.gvsig.view3d.swing.api.View3DSwingLocator; |
45 | 37 |
import org.gvsig.view3d.swing.api.View3DSwingManager; |
38 |
import org.gvsig.view3d.swing.api.exceptions.ConversionLayerException; |
|
46 | 39 |
import org.gvsig.view3d.swing.api.properties.GeneralProperties3D; |
47 | 40 |
import org.gvsig.view3d.swing.api.properties.MapControlProperties3D; |
48 |
import org.gvsig.view3d.swing.impl.data.DefaultTiledImageLayer; |
|
49 | 41 |
import org.slf4j.Logger; |
50 | 42 |
import org.slf4j.LoggerFactory; |
51 | 43 |
|
44 |
/** |
|
45 |
* This entity manages layer collection and layer events to synchronize WW |
|
46 |
* layers. |
|
47 |
* |
|
48 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
|
49 |
* |
|
50 |
*/ |
|
52 | 51 |
public class DefaultSynchronizer { |
53 | 52 |
|
54 |
private static final Logger LOG = LoggerFactory |
|
55 |
.getLogger(DefaultSynchronizer.class); |
|
53 |
private static final Logger LOG = LoggerFactory.getLogger(DefaultSynchronizer.class); |
|
56 | 54 |
|
57 |
private Map<FLayer, LAYER_SYNCHRONIZE_STATUS> tiledlayerRegister = |
|
58 |
new HashMap<FLayer, LAYER_SYNCHRONIZE_STATUS>(); |
|
55 |
private Map<FLayer, Object> register = new WeakHashMap<FLayer, Object>(); |
|
59 | 56 |
|
60 |
private Map<FLayer, LAYER_SYNCHRONIZE_STATUS> elevationModelLayerRegister = |
|
61 |
new HashMap<FLayer, LAYER_SYNCHRONIZE_STATUS>(); |
|
62 |
|
|
63 | 57 |
private DefaultMapControl3D mapControl3D; |
64 | 58 |
private MapContext mapContext; |
65 | 59 |
private WorldWindow wwd; |
66 |
|
|
67 |
private Object synchronizingLayerLock = new Object(); |
|
68 | 60 |
|
69 |
protected DefaultSynchronizer(DefaultMapControl3D theMapControl3D, |
|
70 |
MapContext theMapContext, WorldWindow wwd) {
|
|
61 |
protected DefaultSynchronizer(DefaultMapControl3D theMapControl3D, MapContext theMapContext,
|
|
62 |
WorldWindow wwd) { |
|
71 | 63 |
|
72 | 64 |
this.mapControl3D = theMapControl3D; |
73 | 65 |
this.mapContext = theMapContext; |
74 | 66 |
this.wwd = wwd; |
75 | 67 |
|
76 |
intializeRegisters(); |
|
77 |
|
|
78 | 68 |
addLayerCollectionListener(mapContext.getLayers()); |
79 |
addLayerListener(mapContext.getLayers()); |
|
80 | 69 |
addViewPortListener(mapContext.getViewPort()); |
70 |
addLayerListener(mapContext.getLayers()); |
|
81 | 71 |
} |
82 | 72 |
|
83 |
private void intializeRegisters() { |
|
84 |
|
|
85 |
FLayers layers = mapContext.getLayers(); |
|
86 |
|
|
87 |
try { |
|
88 |
layers.accept(new LayersVisitor() { |
|
89 |
|
|
90 |
public void visit(Object obj) throws VisitCanceledException, |
|
91 |
BaseException { |
|
92 |
throw new UnsupportedOperationException(); |
|
93 |
|
|
94 |
} |
|
95 |
|
|
96 |
public void visit(FLayer layer) throws BaseException { |
|
97 |
|
|
98 |
View3DManager manager = View3DLocator.getManager(); |
|
99 |
LayerProperties3D layerProperties = |
|
100 |
manager.getLayerProperties(layer); |
|
101 |
|
|
102 |
if (layerProperties.getElevation() == true) { |
|
103 |
elevationModelLayerRegister.put(layer, |
|
104 |
LAYER_SYNCHRONIZE_STATUS.CLEAN); |
|
105 |
} else { |
|
106 |
tiledlayerRegister.put(layer, |
|
107 |
LAYER_SYNCHRONIZE_STATUS.CLEAN); |
|
108 |
} |
|
109 |
} |
|
110 |
}); |
|
111 |
} catch (BaseException e) { |
|
112 |
LOG.error( |
|
113 |
"Can't initialize register of layers to auto synchronize.", e); |
|
114 |
mapControl3D.getProperties().setAutoLayerSynchronize(false); |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 | 73 |
private void addLayerListener(FLayer layer) { |
119 | 74 |
if (layer == null) { |
120 | 75 |
return; |
... | ... | |
131 | 86 |
layers.addLayerCollectionListener(new LayerCollectionListener() { |
132 | 87 |
|
133 | 88 |
public void layerAdded(LayerCollectionEvent e) { |
134 |
FLayer affectedLayer = e.getAffectedLayer(); |
|
135 |
affectedLayer.addLayerListener(getLayerListener()); |
|
136 |
updateLayerState(affectedLayer, LAYER_SYNCHRONIZE_STATUS.ADD); |
|
89 |
|
|
137 | 90 |
if (mapControl3D.getProperties().getAutoLayerSynchronize()) { |
138 |
synchronizeLayers(); |
|
91 |
FLayer affectedLayer = e.getAffectedLayer(); |
|
92 |
try { |
|
93 |
addLayer(affectedLayer); |
|
94 |
// Add layer listener to new layer |
|
95 |
addLayerListener(affectedLayer); |
|
96 |
} catch (ConversionLayerException e1) { |
|
97 |
LOG.error("Synchronizer can not add {} layer to 3D view", |
|
98 |
affectedLayer.getName()); |
|
99 |
return; |
|
100 |
} |
|
139 | 101 |
} |
140 | 102 |
} |
141 | 103 |
|
142 |
public void layerAdding(LayerCollectionEvent e) |
|
143 |
throws CancelationException { |
|
104 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
|
144 | 105 |
} |
145 | 106 |
|
146 | 107 |
public void layerMoved(LayerPositionEvent e) { |
147 |
FLayer affectedLayer = e.getAffectedLayer(); |
|
148 |
int oldPos = e.getOldPos(); |
|
149 |
int newPos = e.getNewPos(); |
|
150 |
moveLayer(affectedLayer, oldPos, newPos); |
|
151 |
} |
|
152 | 108 |
|
153 |
public void layerMoving(LayerPositionEvent e) |
|
154 |
throws CancelationException { |
|
109 |
if (mapControl3D.getProperties().getAutoLayerSynchronize()) { |
|
110 |
FLayer affectedLayer = e.getAffectedLayer(); |
|
111 |
int oldPos = e.getOldPos(); |
|
112 |
int newPos = e.getNewPos(); |
|
113 |
|
|
114 |
// Only move layer is layer has changed position. |
|
115 |
if (oldPos != newPos) { |
|
116 |
try { |
|
117 |
moveLayer(affectedLayer, oldPos, newPos); |
|
118 |
} catch (ConversionLayerException e1) { |
|
119 |
LOG.error("Synchronizer can not move {} layer", affectedLayer.getName()); |
|
120 |
return; |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
155 | 124 |
} |
156 | 125 |
|
157 |
public void layerRemoved(LayerCollectionEvent e) {
|
|
126 |
public void layerMoving(LayerPositionEvent e) throws CancelationException {
|
|
158 | 127 |
} |
159 | 128 |
|
160 |
public void layerRemoving(LayerCollectionEvent e) |
|
161 |
throws CancelationException { |
|
162 |
FLayer affectedLayer = e.getAffectedLayer(); |
|
163 |
updateLayerState(affectedLayer, LAYER_SYNCHRONIZE_STATUS.REMOVE); |
|
129 |
public void layerRemoved(LayerCollectionEvent e) { |
|
164 | 130 |
if (mapControl3D.getProperties().getAutoLayerSynchronize()) { |
165 |
synchronizeLayers(); |
|
131 |
FLayer affectedLayer = e.getAffectedLayer(); |
|
132 |
removeLayer(affectedLayer); |
|
166 | 133 |
} |
167 | 134 |
} |
168 | 135 |
|
169 |
public void visibilityChanged(LayerCollectionEvent e) |
|
170 |
throws CancelationException { |
|
136 |
public void layerRemoving(LayerCollectionEvent e) throws CancelationException { |
|
171 | 137 |
} |
138 |
|
|
139 |
public void visibilityChanged(LayerCollectionEvent e) throws CancelationException { |
|
140 |
|
|
141 |
if (mapControl3D.getProperties().getAutoLayerSynchronize()) { |
|
142 |
FLayer affectedLayer = e.getAffectedLayer(); |
|
143 |
|
|
144 |
if (getTileImageLayer(affectedLayer) != null) { |
|
145 |
getTileImageLayer(affectedLayer).setEnabled(affectedLayer.isVisible()); |
|
146 |
} |
|
147 |
} |
|
148 |
} |
|
172 | 149 |
}); |
173 | 150 |
} |
174 | 151 |
|
... | ... | |
179 | 156 |
} |
180 | 157 |
|
181 | 158 |
public void drawValueChanged(LayerEvent e) { |
182 |
FLayer layer = e.getSource(); |
|
183 |
updateLayerState(layer, LAYER_SYNCHRONIZE_STATUS.DIRTY); |
|
184 | 159 |
|
185 |
MapControlProperties3D properties = |
|
186 |
mapControl3D.getProperties(); |
|
187 |
if (properties.getAutoLayerSynchronize()) { |
|
188 |
synchronizeLayers(); |
|
160 |
if (mapControl3D.getProperties().getAutoLayerSynchronize()) { |
|
161 |
FLayer layer = e.getSource(); |
|
162 |
LayerProperties3D layerProperties = View3DLocator.getManager().getLayerProperties(layer); |
|
163 |
|
|
164 |
// If load mode change reload layer. FIXME: Change this when there are more load modes. |
|
165 |
if (layerProperties.getElevation() == false && getElevationModel(layer) != null){ |
|
166 |
reloadLayer(layer, wwd.getModel().getLayers().size()); |
|
167 |
return; |
|
168 |
} else if( layerProperties.getElevation() == true && getTileImageLayer(layer) != null) { |
|
169 |
CompoundElevationModel compoundElevation = |
|
170 |
(CompoundElevationModel) wwd.getModel().getGlobe().getElevationModel(); |
|
171 |
reloadLayer(layer, compoundElevation.getElevationModels().size()); |
|
172 |
return; |
|
173 |
} |
|
174 |
|
|
175 |
// Set expire time to invalidate tile cache layer. |
|
176 |
if (getTileImageLayer(layer) != null) { |
|
177 |
getTileImageLayer(layer).setExpiryTime(System.currentTimeMillis()); |
|
178 |
} else if (getElevationModel(layer) != null) { |
|
179 |
getElevationModel(layer).setExpiryTime(System.currentTimeMillis()); |
|
180 |
} |
|
189 | 181 |
} |
190 | 182 |
} |
191 | 183 |
|
192 | 184 |
public void editionChanged(LayerEvent e) { |
185 |
// After edition finish it is necessary to reopen store to |
|
186 |
// refresh layer |
|
187 |
if (mapControl3D.getProperties().getAutoLayerSynchronize()) { |
|
188 |
FLayer layer = e.getSource(); |
|
189 |
if (!layer.isEditing()) { |
|
190 |
reloadLayer(layer); |
|
191 |
} |
|
192 |
} |
|
193 | 193 |
} |
194 | 194 |
|
195 | 195 |
public void nameChanged(LayerEvent e) { |
196 | 196 |
} |
197 | 197 |
|
198 | 198 |
public void visibilityChanged(LayerEvent e) { |
199 |
FLayer layer = e.getSource(); |
|
200 |
|
|
201 |
updateLayerState(layer, LAYER_SYNCHRONIZE_STATUS.DIRTY); |
|
202 | 199 |
if (mapControl3D.getProperties().getAutoLayerSynchronize()) { |
203 |
synchronizeLayers(); |
|
200 |
FLayer affectedLayer = e.getSource(); |
|
201 |
|
|
202 |
if (getTileImageLayer(affectedLayer) != null) { |
|
203 |
getTileImageLayer(affectedLayer).setEnabled(affectedLayer.isVisible()); |
|
204 |
} |
|
204 | 205 |
} |
205 | 206 |
} |
206 | 207 |
}; |
207 | 208 |
} |
208 | 209 |
|
210 |
private void reloadLayer(FLayer layer){ |
|
211 |
int index = getLayerIndex(layer); |
|
212 |
reloadLayer(layer, index); |
|
213 |
} |
|
214 |
|
|
215 |
private void reloadLayer(FLayer layer, int index){ |
|
216 |
removeLayer(layer); |
|
217 |
try { |
|
218 |
addLayer(layer, index); |
|
219 |
} catch (ConversionLayerException e1) { |
|
220 |
LOG.error("Can not add convert {} layer to update it after edition", |
|
221 |
layer.getName(), e1); |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
209 | 225 |
private void addViewPortListener(ViewPort viewPort) { |
210 |
|
|
226 |
|
|
211 | 227 |
viewPort.addViewPortListener(new ViewPortListener() { |
212 |
|
|
228 |
|
|
213 | 229 |
public void projectionChanged(ProjectionEvent e) { |
214 | 230 |
} |
215 |
|
|
231 |
|
|
216 | 232 |
public void extentChanged(ExtentEvent e) { |
217 |
MapControlProperties3D properties = |
|
218 |
mapControl3D.getProperties(); |
|
219 |
boolean autoViewSynchronize = |
|
220 |
properties.getAutoViewPortSynchronize(); |
|
233 |
MapControlProperties3D properties = mapControl3D.getProperties(); |
|
234 |
boolean autoViewSynchronize = properties.getAutoViewPortSynchronize(); |
|
221 | 235 |
if (autoViewSynchronize) { |
222 | 236 |
synchronizeViewPorts(); |
223 | 237 |
} |
224 | 238 |
} |
225 |
|
|
239 |
|
|
226 | 240 |
public void backColorChanged(ColorEvent e) { |
227 | 241 |
} |
228 | 242 |
}); |
229 | 243 |
} |
230 | 244 |
|
231 |
|
|
232 | 245 |
private Layer getTileImageLayer(FLayer layer) { |
233 |
List<Layer> layers = |
|
234 |
wwd.getModel().getLayers().getLayersByClass(DefaultTiledImageLayer.class); |
|
235 |
for (Layer tiledLayer : layers) { |
|
236 |
AVList constructionParams = |
|
237 |
(AVList) tiledLayer.getValue(AVKey.CONSTRUCTION_PARAMETERS); |
|
238 |
if (constructionParams != null) { |
|
239 |
FLayer likedLayer = |
|
240 |
(FLayer) constructionParams |
|
241 |
.getValue(DefaultMapControl3D.GVSIG_LAYER); |
|
242 |
if (layer.equals(likedLayer)) { |
|
243 |
return tiledLayer; |
|
244 |
} |
|
245 |
} |
|
246 |
|
|
247 |
if (this.register.get(layer) instanceof Layer) { |
|
248 |
return (Layer) this.register.get(layer); |
|
246 | 249 |
} |
250 |
|
|
247 | 251 |
return null; |
248 | 252 |
} |
249 | 253 |
|
250 | 254 |
private ElevationModel getElevationModel(FLayer layer) { |
251 |
ElevationModel elevationModel = wwd.getModel().getGlobe().getElevationModel(); |
|
252 | 255 |
|
253 |
if (elevationModel instanceof CompoundElevationModel) { |
|
254 |
CompoundElevationModel compoundModel = |
|
255 |
(CompoundElevationModel) elevationModel; |
|
256 |
List<ElevationModel> elevationModels = |
|
257 |
compoundModel.getElevationModels(); |
|
258 |
|
|
259 |
for (ElevationModel eModel : elevationModels) { |
|
260 |
if (eModel.getName().equals(layer.getName())) { |
|
261 |
return eModel; |
|
262 |
} |
|
263 |
} |
|
264 |
return null; |
|
256 |
if (this.register.get(layer) instanceof ElevationModel) { |
|
257 |
return (ElevationModel) this.register.get(layer); |
|
265 | 258 |
} |
266 | 259 |
|
267 |
if (elevationModel.getName().equals(layer.getName())) { |
|
268 |
return elevationModel; |
|
269 |
} |
|
270 | 260 |
return null; |
271 | 261 |
} |
272 | 262 |
|
273 |
private void updateLayerState(FLayer layer, LAYER_SYNCHRONIZE_STATUS status) {
|
|
263 |
protected void synchronizeViewPorts() {
|
|
274 | 264 |
|
275 |
View3DManager manager = View3DLocator.getManager();
|
|
276 |
LayerProperties3D layerProperties = manager.getLayerProperties(layer);
|
|
277 |
synchronized (synchronizingLayerLock) {
|
|
278 |
if (layerProperties.getElevation() == true) {
|
|
265 |
// Convert envelope to WorldWind sector
|
|
266 |
ViewPort viewPort = this.mapContext.getViewPort();
|
|
267 |
Envelope envelope = viewPort.getEnvelope();
|
|
268 |
Sector sector = Sector.FULL_SPHERE;
|
|
279 | 269 |
|
280 |
if (tiledlayerRegister.containsKey(layer)) { |
|
281 |
tiledlayerRegister.remove(layer); |
|
282 |
} |
|
270 |
if (envelope != null) { |
|
283 | 271 |
|
284 |
if (elevationModelLayerRegister.containsKey(layer) |
|
285 |
|| status == LAYER_SYNCHRONIZE_STATUS.ADD) { |
|
286 |
elevationModelLayerRegister.put(layer, status); |
|
287 |
} |
|
288 |
} else { |
|
289 |
|
|
290 |
if (elevationModelLayerRegister.containsKey(layer)) { |
|
291 |
elevationModelLayerRegister.remove(layer); |
|
292 |
} |
|
293 |
if (tiledlayerRegister.containsKey(layer) |
|
294 |
|| status == LAYER_SYNCHRONIZE_STATUS.ADD) { |
|
295 |
tiledlayerRegister.put(layer, status); |
|
296 |
} |
|
272 |
if (!viewPort.getProjection().equals(CRSFactory.getCRS("EPSG:4326"))) { |
|
273 |
envelope = |
|
274 |
envelope |
|
275 |
.convert(viewPort.getProjection().getCT(CRSFactory.getCRS("EPSG:4326"))); |
|
297 | 276 |
} |
298 |
} |
|
299 |
} |
|
300 | 277 |
|
301 |
protected void synchronizeLayers() { |
|
302 |
|
|
303 |
List<FLayer> removedLayers = new ArrayList<FLayer>(); |
|
304 |
|
|
305 |
synchronized (synchronizingLayerLock) { |
|
306 |
// Synchronize tiledImageLayers |
|
307 |
for (Entry<FLayer, LAYER_SYNCHRONIZE_STATUS> entry : tiledlayerRegister |
|
308 |
.entrySet()) { |
|
309 |
|
|
310 |
FLayer tiledLayer = entry.getKey(); |
|
311 |
LAYER_SYNCHRONIZE_STATUS status = |
|
312 |
tiledlayerRegister.get(tiledLayer); |
|
313 |
|
|
314 |
switch (status) { |
|
315 |
case ADD: |
|
316 |
addLayer(tiledLayer); |
|
317 |
entry.setValue(LAYER_SYNCHRONIZE_STATUS.CLEAN); |
|
318 |
break; |
|
319 |
case REMOVE: |
|
320 |
removeLayer(tiledLayer); |
|
321 |
removedLayers.add(tiledLayer); |
|
322 |
break; |
|
323 |
case DIRTY: |
|
324 |
updateLayer(tiledLayer); |
|
325 |
entry.setValue(LAYER_SYNCHRONIZE_STATUS.CLEAN); |
|
326 |
break; |
|
327 |
case CLEAN: |
|
328 |
break; |
|
329 |
} |
|
330 |
} |
|
331 |
|
|
332 |
// Synchronize elevationModelLayerRegister |
|
333 |
for (Entry<FLayer, LAYER_SYNCHRONIZE_STATUS> entry : elevationModelLayerRegister |
|
334 |
.entrySet()) { |
|
335 |
|
|
336 |
FLayer eModelLayer = entry.getKey(); |
|
337 |
LAYER_SYNCHRONIZE_STATUS status = |
|
338 |
elevationModelLayerRegister.get(eModelLayer); |
|
339 |
|
|
340 |
switch (status) { |
|
341 |
case ADD: |
|
342 |
addLayer(eModelLayer); |
|
343 |
entry.setValue(LAYER_SYNCHRONIZE_STATUS.CLEAN); |
|
344 |
break; |
|
345 |
case REMOVE: |
|
346 |
removeLayer(eModelLayer); |
|
347 |
removedLayers.add(eModelLayer); |
|
348 |
break; |
|
349 |
case DIRTY: |
|
350 |
updateLayer(eModelLayer); |
|
351 |
entry.setValue(LAYER_SYNCHRONIZE_STATUS.CLEAN); |
|
352 |
break; |
|
353 |
case CLEAN: |
|
354 |
break; |
|
355 |
} |
|
356 |
} |
|
357 |
|
|
358 |
for (FLayer fLayer : removedLayers) { |
|
359 |
if (tiledlayerRegister.containsKey(fLayer)) { |
|
360 |
tiledlayerRegister.remove(fLayer); |
|
361 |
break; |
|
362 |
} else if (elevationModelLayerRegister.containsKey(fLayer)) { |
|
363 |
elevationModelLayerRegister.remove(fLayer); |
|
364 |
break; |
|
365 |
} |
|
366 |
} |
|
278 |
sector = getSector(envelope); |
|
367 | 279 |
} |
368 |
} |
|
369 | 280 |
|
370 |
protected void synchronizeViewPorts() { |
|
371 |
|
|
372 |
// Convert envelope to WorldWind sector |
|
373 |
ViewPort viewPort = this.mapContext.getViewPort(); |
|
374 |
Envelope envelope = viewPort.getEnvelope(); |
|
375 |
Sector sector = getSector(envelope); |
|
376 |
|
|
377 | 281 |
// Create a bounding box for the specified sector in order to estimate |
378 | 282 |
// its size in model coordinates. |
379 |
Box extent = Sector.computeBoundingBox(wwd.getModel().getGlobe(), |
|
380 |
mapControl3D.getVerticalExaggeration(), sector); |
|
381 |
|
|
283 |
Box extent = |
|
284 |
Sector.computeBoundingBox(wwd.getModel().getGlobe(), |
|
285 |
mapControl3D.getVerticalExaggeration(), sector); |
|
286 |
|
|
382 | 287 |
// Estimate the distance between the center position and the eye |
383 | 288 |
// position that is necessary to cause the sector to |
384 | 289 |
// fill a viewport with the specified field of view. Note that we change |
... | ... | |
386 | 291 |
// position here, and leave the field of view constant. |
387 | 292 |
Angle fov = wwd.getView().getFieldOfView(); |
388 | 293 |
double zoom = extent.getRadius() / fov.cosHalfAngle() / fov.tanHalfAngle(); |
389 |
|
|
294 |
|
|
390 | 295 |
View3DSwingManager swingManager = View3DSwingLocator.getManager(); |
391 | 296 |
GeneralProperties3D general3dProperties = swingManager.getGeneral3DProperties(); |
392 |
|
|
393 |
if(general3dProperties.getViewPortAnimation()){
|
|
297 |
|
|
298 |
if (general3dProperties.getViewPortAnimation()) {
|
|
394 | 299 |
wwd.getView().goTo(new Position(sector.getCentroid(), 0d), zoom); |
395 | 300 |
} else { |
396 |
((OrbitView) wwd.getView()).setCenterPosition(new Position(sector |
|
397 |
.getCentroid(), 0d)); |
|
301 |
((OrbitView) wwd.getView()).setCenterPosition(new Position(sector.getCentroid(), 0d)); |
|
398 | 302 |
((OrbitView) wwd.getView()).setZoom(zoom); |
399 | 303 |
wwd.redraw(); |
400 | 304 |
} |
... | ... | |
409 | 313 |
p2 = new Point2D.Double(envelope.getMaximum(0), envelope.getMaximum(1)); |
410 | 314 |
|
411 | 315 |
double minLatitude = |
412 |
Double.isInfinite(p1.getY()) || p1.getY() < Angle.NEG90.degrees |
|
413 |
? Angle.NEG90.degrees : p1.getY();
|
|
316 |
Double.isInfinite(p1.getY()) || p1.getY() < Angle.NEG90.degrees ? Angle.NEG90.degrees
|
|
317 |
: p1.getY(); |
|
414 | 318 |
double maxLatitude = |
415 |
Double.isInfinite(p2.getY()) || p2.getY() > Angle.POS90.degrees |
|
416 |
? Angle.POS90.degrees : p2.getY();
|
|
319 |
Double.isInfinite(p2.getY()) || p2.getY() > Angle.POS90.degrees ? Angle.POS90.degrees
|
|
320 |
: p2.getY(); |
|
417 | 321 |
double minLongitude = |
418 |
Double.isInfinite(p1.getX()) || p1.getX() < Angle.NEG180.degrees |
|
419 |
? Angle.NEG180.degrees : p1.getX();
|
|
322 |
Double.isInfinite(p1.getX()) || p1.getX() < Angle.NEG180.degrees ? Angle.NEG180.degrees
|
|
323 |
: p1.getX(); |
|
420 | 324 |
double maxLongitude = |
421 |
Double.isInfinite(p2.getX()) || p2.getX() > Angle.POS180.degrees |
|
422 |
? Angle.POS180.degrees : p2.getX();
|
|
325 |
Double.isInfinite(p2.getX()) || p2.getX() > Angle.POS180.degrees ? Angle.POS180.degrees
|
|
326 |
: p2.getX(); |
|
423 | 327 |
|
424 | 328 |
Sector sector = |
425 |
new Sector(Sector.fromDegrees(minLatitude, maxLatitude, |
|
426 |
minLongitude, maxLongitude)); |
|
329 |
new Sector(Sector.fromDegrees(minLatitude, maxLatitude, minLongitude, maxLongitude)); |
|
427 | 330 |
|
428 | 331 |
return sector; |
429 | 332 |
} |
430 |
|
|
431 |
private void updateLayer(FLayer layer) { |
|
432 |
int index = getLayerIndex(layer); |
|
433 |
removeLayer(layer); |
|
434 |
addLayer(layer, index); |
|
435 |
} |
|
436 | 333 |
|
437 | 334 |
private int getLayerIndex(FLayer layer) { |
438 |
|
|
439 |
View3DManager manager = View3DLocator.getManager(); |
|
440 |
LayerProperties3D layerProperties = manager.getLayerProperties(layer); |
|
441 |
|
|
442 |
int index = 0; |
|
443 |
if(layerProperties.getElevation()){ |
|
444 |
ElevationModel layerEModel = getElevationModel(layer); |
|
445 |
CompoundElevationModel eModel = |
|
446 |
(CompoundElevationModel) wwd.getModel().getGlobe().getElevationModel(); |
|
447 |
if(layerEModel != null){ |
|
448 |
|
|
449 |
index = eModel.getElevationModels().indexOf(layerEModel); |
|
450 |
} else { |
|
451 |
return eModel.getElevationModels().size(); |
|
452 |
} |
|
453 |
} else { |
|
454 |
|
|
335 |
|
|
336 |
if (getTileImageLayer(layer) != null) { |
|
337 |
|
|
455 | 338 |
Layer tileImageLayer = getTileImageLayer(layer); |
456 |
if(tileImageLayer != null){ |
|
457 |
index = wwd.getModel().getLayers().indexOf(tileImageLayer); |
|
458 |
} else { |
|
459 |
return wwd.getModel().getLayers().size(); |
|
460 |
} |
|
339 |
return this.wwd.getModel().getLayers().indexOf(tileImageLayer); |
|
340 |
|
|
341 |
} else if (getElevationModel(layer) != null) { |
|
342 |
|
|
343 |
ElevationModel elevationModel = getElevationModel(layer); |
|
344 |
CompoundElevationModel compoundElevationModel = |
|
345 |
(CompoundElevationModel) wwd.getModel().getGlobe().getElevationModel(); |
|
346 |
return compoundElevationModel.getElevationModels().indexOf(elevationModel); |
|
347 |
|
|
461 | 348 |
} |
462 |
|
|
463 |
return index;
|
|
349 |
|
|
350 |
return 0;
|
|
464 | 351 |
} |
465 | 352 |
|
466 |
private void addLayer(FLayer layer) { |
|
467 |
try { |
|
468 |
this.mapControl3D.addGvSIGLayer(layer); |
|
469 |
} catch (DataException e) { |
|
470 |
LOG.error("Can't add {} to MapControl3D", layer.getName()); |
|
471 |
} |
|
353 |
private void addLayer(FLayer layer) throws ConversionLayerException { |
|
354 |
this.mapControl3D.addGvSIGLayer(layer); |
|
472 | 355 |
} |
473 | 356 |
|
474 |
private void addLayer(FLayer layer, int pos) { |
|
475 |
try { |
|
476 |
this.mapControl3D.addGvSIGLayer(layer, pos); |
|
477 |
} catch (DataException e) { |
|
478 |
LOG.error("Can't add {} to MapControl3D", layer.getName()); |
|
479 |
} |
|
357 |
private void addLayer(FLayer layer, int pos) throws ConversionLayerException { |
|
358 |
this.mapControl3D.addGvSIGLayer(layer, pos); |
|
480 | 359 |
} |
481 | 360 |
|
482 | 361 |
private void removeLayer(FLayer layer) { |
... | ... | |
491 | 370 |
} else if (tiledImageLayer != null) { |
492 | 371 |
wwd.getModel().getLayers().remove(tiledImageLayer); |
493 | 372 |
} |
373 |
|
|
374 |
this.register.remove(layer); |
|
494 | 375 |
} |
495 | 376 |
|
496 |
private void moveLayer(FLayer layer, int oldPos, int newPos) { |
|
497 |
|
|
377 |
private void moveLayer(FLayer layer, int oldPos, int newPos) throws ConversionLayerException { |
|
498 | 378 |
int index = getLayerIndex(layer); |
499 |
removeLayer(layer); |
|
500 |
addLayer(layer, index + (newPos - oldPos)); |
|
379 |
int newIndex = index + (newPos - oldPos); |
|
380 |
LayerList layerList = this.wwd.getModel().getLayers(); |
|
381 |
|
|
382 |
if (getTileImageLayer(layer) != null) { |
|
383 |
layerList.remove(getTileImageLayer(layer)); |
|
384 |
if (newIndex <= layerList.size()) { |
|
385 |
layerList.add(newIndex, getTileImageLayer(layer)); |
|
386 |
} else { |
|
387 |
LOG.warn("Error getting new index of layer. Layer will be added at {}", |
|
388 |
layerList.size()); |
|
389 |
layerList.add(getTileImageLayer(layer)); |
|
390 |
} |
|
391 |
} else if (getElevationModel(layer) != null) { |
|
392 |
CompoundElevationModel compoundEModel = |
|
393 |
(CompoundElevationModel) wwd.getModel().getGlobe().getElevationModel(); |
|
394 |
compoundEModel.removeElevationModel(getElevationModel(layer)); |
|
395 |
if (newIndex <= compoundEModel.getElevationModels().size()) { |
|
396 |
compoundEModel.addElevationModel(newIndex, getElevationModel(layer)); |
|
397 |
} else { |
|
398 |
LOG.warn("Error getting new index of layer. Layer will be added at {}", |
|
399 |
compoundEModel.getElevationModels().size()); |
|
400 |
compoundEModel.addElevationModel(getElevationModel(layer)); |
|
401 |
} |
|
402 |
} |
|
501 | 403 |
} |
502 |
} |
|
503 | 404 |
|
504 |
enum LAYER_SYNCHRONIZE_STATUS { |
|
505 |
ADD, CLEAN, DIRTY, REMOVE |
|
506 |
}; |
|
405 |
protected void registerLayer(FLayer layer, Object wwLayer) { |
|
406 |
register.put(layer, wwLayer); |
|
407 |
} |
|
408 |
} |
2.1/branches/org.gvsig.view3d_soporte_bbdd_proyecciones/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/GvSIGLayerDataRaster.java | ||
---|---|---|
40 | 40 |
import java.awt.geom.Rectangle2D; |
41 | 41 |
import java.awt.image.BufferedImage; |
42 | 42 |
|
43 |
import org.cresques.cts.ICoordTrans; |
|
44 | 43 |
import org.cresques.cts.IProjection; |
45 |
import org.gvsig.fmap.crs.CRSFactory; |
|
46 | 44 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
47 | 45 |
import org.gvsig.fmap.dal.coverage.RasterManager; |
48 | 46 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
... | ... | |
50 | 48 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
51 | 49 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
52 | 50 |
import org.gvsig.fmap.dal.coverage.exception.QueryException; |
51 |
import org.gvsig.fmap.dal.coverage.exception.WarpException; |
|
53 | 52 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
54 | 53 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
55 | 54 |
import org.gvsig.fmap.dal.exception.ReadException; |
... | ... | |
60 | 59 |
import org.gvsig.fmap.geom.primitive.Envelope; |
61 | 60 |
import org.gvsig.fmap.mapcontext.MapContext; |
62 | 61 |
import org.gvsig.fmap.mapcontext.ViewPort; |
62 |
import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException; |
|
63 | 63 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
64 | 64 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
65 | 65 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelable; |
66 | 66 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
67 |
import org.gvsig.tools.task.Cancellable; |
|
67 | 68 |
import org.gvsig.view3d.lib.api.View3DLocator; |
68 | 69 |
import org.gvsig.view3d.lib.api.View3DManager; |
69 | 70 |
import org.gvsig.view3d.lib.api.properties.LayerProperties3D; |
... | ... | |
87 | 88 |
private FLayer layer; |
88 | 89 |
|
89 | 90 |
private Extent canvasExtent; |
90 |
private Extent overlapExtent; |
|
91 | 91 |
|
92 | 92 |
/** |
93 | 93 |
* Default constructor of <code>GvSIGLayerDataRaster</code> |
... | ... | |
156 | 156 |
|
157 | 157 |
Extent canvasExtent = getExtent(canvas.getSector()); |
158 | 158 |
|
159 |
FLyrRaster rasterLayer = (FLyrRaster) this.layer; |
|
160 |
RasterDataStore dataStore = rasterLayer.getDataStore(); |
|
161 |
|
|
159 | 162 |
// Create query. Configure to get the zone request by canvas scaled to |
160 | 163 |
// tile size. |
161 | 164 |
RasterQuery query = RasterLocator.getManager().createQuery(); |
... | ... | |
163 | 166 |
query.setDrawableBands(new int[] { 0 }); |
164 | 167 |
query.setReadOnly(true); |
165 | 168 |
query.storeLastBuffer(true); |
166 |
query.setAreaOfInterest(canvasExtent, canvas.getWidth(), |
|
167 |
canvas.getHeight()); |
|
168 | 169 |
|
169 | 170 |
Buffer adjustedBuffer = null; |
170 |
FLyrRaster rasterLayer = (FLyrRaster) this.layer; |
|
171 |
RasterDataStore dataStore = rasterLayer.getDataStore(); |
|
171 |
if(rasterLayer.getCoordTrans() != null){ |
|
172 |
query.setAreaOfInterest( |
|
173 |
canvasExtent.convert(rasterLayer.getCoordTrans().getInverted()), |
|
174 |
canvas.getWidth(), canvas.getHeight()); |
|
175 |
} else { |
|
176 |
query.setAreaOfInterest(canvasExtent, canvas.getWidth(), |
|
177 |
canvas.getHeight()); |
|
178 |
} |
|
172 | 179 |
|
173 | 180 |
try { |
174 | 181 |
// For best performance, checks if canvas extent is the same than |
... | ... | |
189 | 196 |
query.toString(), dataStore.getName() }, e); |
190 | 197 |
return; |
191 | 198 |
} |
199 |
|
|
192 | 200 |
|
193 | 201 |
// For performance reasons, stores canvas extent to avoid calculate it |
194 | 202 |
// in each iteration |
195 | 203 |
setCanvasEnxent(canvas.getSector()); |
196 |
Sector overlap = this.getSector().intersection(canvas.getSector()); |
|
197 |
setOverlapExtent(overlap); |
|
198 | 204 |
|
205 |
if (this.layer.getProjection() == null){ |
|
206 |
|
|
207 |
try { |
|
208 |
adjustedBuffer = adjustedBuffer.project(null, canvasExtent, |
|
209 |
canvas.getWidth(), canvas.getHeight()); |
|
210 |
} catch (WarpException e) { |
|
211 |
LOG.error(String |
|
212 |
.format( |
|
213 |
"Error projecting buffer. [source CRS: %1s target CRS: %2s canvas extent: %3s width: %4s height: %5s]", |
|
214 |
rasterLayer.getCoordTrans().getPOrig().getAbrev(), rasterLayer.getCoordTrans() |
|
215 |
.getPDest().getAbrev(), canvasExtent, canvas.getWidth(), |
|
216 |
canvas.getHeight())); |
|
217 |
return; |
|
218 |
} |
|
219 |
|
|
220 |
} else if (rasterLayer.getCoordTrans() != null) { |
|
221 |
|
|
222 |
try { |
|
223 |
adjustedBuffer = adjustedBuffer.project(rasterLayer.getCoordTrans().getInverted(), canvasExtent, |
|
224 |
canvas.getWidth(), canvas.getHeight()); |
|
225 |
} catch (WarpException e) { |
|
226 |
LOG.error(String |
|
227 |
.format( |
|
228 |
"Error projecting buffer. [source CRS: %1s target CRS: %2s canvas extent: %3s width: %4s height: %5s]", |
|
229 |
rasterLayer.getCoordTrans().getPOrig().getAbrev(), rasterLayer.getCoordTrans() |
|
230 |
.getPDest().getAbrev(), canvasExtent, canvas.getWidth(), |
|
231 |
canvas.getHeight())); |
|
232 |
return; |
|
233 |
} |
|
234 |
} |
|
235 |
|
|
199 | 236 |
String dataType = this.getStringValue(AVKey.DATA_TYPE); |
200 | 237 |
|
201 | 238 |
for (int y = 0; y < canvas.getHeight(); y++) { |
202 | 239 |
for (int x = 0; x < canvas.getWidth(); x++) { |
203 |
|
|
204 |
Point2D rasterPoint = |
|
205 |
getRasterPoint(x, y, canvas, adjustedBuffer); |
|
206 | 240 |
|
207 |
// If raster point is not null, get value of buffer and write it |
|
208 |
// to canvas |
|
209 |
if (rasterPoint != null) { |
|
210 |
if (AVKey.INT8.equals(dataType)) { |
|
241 |
if (AVKey.INT8.equals(dataType)) { |
|
211 | 242 |
|
212 |
byte byteValue = |
|
213 |
adjustedBuffer.getElemByte( |
|
214 |
(int) rasterPoint.getY(), |
|
215 |
(int) rasterPoint.getX(), 0); |
|
243 |
byte byteValue = adjustedBuffer.getElemByte( y, x, 0); |
|
244 |
setNumberToDataRaster((ByteBufferRaster) canvas, y, x, byteValue); |
|
216 | 245 |
|
217 |
setNumberToDataRaster((ByteBufferRaster) canvas, y, x, |
|
218 |
byteValue); |
|
246 |
} else if (AVKey.INT16.equals(dataType)) { |
|
219 | 247 |
|
220 |
} else if (AVKey.INT16.equals(dataType)) { |
|
221 |
|
|
222 |
short shortValue = |
|
223 |
adjustedBuffer.getElemShort( |
|
224 |
(int) rasterPoint.getY(), |
|
225 |
(int) rasterPoint.getX(), 0); |
|
226 |
|
|
227 |
setNumberToDataRaster((ByteBufferRaster) canvas, y, x, |
|
228 |
shortValue); |
|
229 |
|
|
230 |
} else if (AVKey.INT32.equals(dataType)) { |
|
231 |
|
|
232 |
int intValue = |
|
233 |
adjustedBuffer.getElemInt((int) rasterPoint.getY(), |
|
234 |
(int) rasterPoint.getX(), 0); |
|
235 |
|
|
236 |
setNumberToDataRaster((ByteBufferRaster) canvas, y, x, |
|
237 |
intValue); |
|
238 |
|
|
239 |
} else if (AVKey.FLOAT32.equals(dataType)) { |
|
240 |
|
|
241 |
float floatValue = |
|
242 |
adjustedBuffer.getElemFloat( |
|
243 |
(int) rasterPoint.getY(), |
|
244 |
(int) rasterPoint.getX(), 0); |
|
245 |
|
|
246 |
setNumberToDataRaster((ByteBufferRaster) canvas, y, x, |
|
247 |
floatValue); |
|
248 |
|
|
249 |
} else if (AVKey.FLOAT64.equals(dataType)) { |
|
250 |
|
|
251 |
double doubleValue = |
|
252 |
adjustedBuffer.getElemDouble( |
|
253 |
(int) rasterPoint.getY(), |
|
254 |
(int) rasterPoint.getX(), 0); |
|
255 |
|
|
256 |
setNumberToDataRaster((ByteBufferRaster) canvas, y, x, |
|
257 |
doubleValue); |
|
258 |
} |
|
259 |
} else { |
|
260 |
// Invalid point, write NoData value |
|
261 |
Number noData = |
|
262 |
(Number) this.getValue(AVKey.MISSING_DATA_SIGNAL); |
|
263 |
if (AVKey.INT8.equals(dataType)) { |
|
264 |
setNumberToDataRaster((ByteBufferRaster) canvas, y, x, |
|
265 |
noData.byteValue()); |
|
266 |
} else if (AVKey.INT16.equals(dataType)) { |
|
267 |
setNumberToDataRaster((ByteBufferRaster) canvas, y, x, |
|
268 |
noData.shortValue()); |
|
269 |
} else if (AVKey.INT32.equals(dataType)) { |
|
270 |
setNumberToDataRaster((ByteBufferRaster) canvas, y, x, |
|
271 |
noData.intValue()); |
|
272 |
} else if (AVKey.FLOAT32.equals(dataType)) { |
|
273 |
setNumberToDataRaster((ByteBufferRaster) canvas, y, x, |
|
274 |
noData.floatValue()); |
|
275 |
} else if (AVKey.FLOAT64.equals(dataType)) { |
|
276 |
setNumberToDataRaster((ByteBufferRaster) canvas, y, x, |
|
277 |
noData.doubleValue()); |
|
278 |
} |
|
279 |
} |
|
280 |
} |
|
281 |
} |
|
282 |
} |
|
248 |
short shortValue = adjustedBuffer.getElemShort(y, x, 0); |
|
249 |
setNumberToDataRaster((ByteBufferRaster) canvas, y, x, shortValue); |
|
283 | 250 |
|
284 |
private Point2D getRasterPoint(int x, int y, DataRaster canvas, |
|
285 |
Buffer adjustedBuffer) { |
|
286 |
|
|
287 |
// Gets coordiantes of pixel raster |
|
288 |
Point2D worldPoint = |
|
289 |
canvasExtent.rasterToWorld(new Point2D.Double(x, y), |
|
290 |
getCellSize(canvas.getSector(), canvas.getWidth())); |
|
251 |
} else if (AVKey.INT32.equals(dataType)) { |
|
291 | 252 |
|
292 |
if (layer instanceof FLyrRaster) { |
|
293 |
// Gets pixel of adjusted buffer |
|
294 |
Sector overlap = this.getSector().intersection(canvas.getSector()); |
|
295 |
Point2D rasterPoint = |
|
296 |
overlapExtent.worldToRaster(worldPoint, |
|
297 |
getCellSize(overlap, adjustedBuffer.getWidth())); |
|
253 |
int intValue = adjustedBuffer.getElemInt(y, x, 0); |
|
254 |
setNumberToDataRaster((ByteBufferRaster) canvas, y, x, intValue); |
|
298 | 255 |
|
299 |
if (isPointOfBuffer(rasterPoint, adjustedBuffer)) { |
|
300 |
return rasterPoint; |
|
256 |
} else if (AVKey.FLOAT32.equals(dataType)) { |
|
257 |
|
|
258 |
float floatValue = adjustedBuffer.getElemFloat(y, x, 0); |
|
259 |
setNumberToDataRaster((ByteBufferRaster) canvas, y, x, floatValue); |
|
260 |
|
|
261 |
} else if (AVKey.FLOAT64.equals(dataType)) { |
|
262 |
|
|
263 |
double doubleValue = adjustedBuffer.getElemDouble(y, x, 0); |
|
264 |
setNumberToDataRaster((ByteBufferRaster) canvas, y, x, doubleValue); |
|
265 |
} |
|
301 | 266 |
} |
302 | 267 |
} |
303 |
return null; |
|
304 | 268 |
} |
305 | 269 |
|
306 | 270 |
private void setCanvasEnxent(Sector canvasSector) { |
307 | 271 |
this.canvasExtent = getExtent(canvasSector); |
308 | 272 |
} |
309 | 273 |
|
310 |
private void setOverlapExtent(Sector overlap) { |
|
311 |
this.overlapExtent = getExtent(overlap); |
|
312 |
} |
|
313 |
|
|
314 | 274 |
private Extent getExtent(Sector sector){ |
315 | 275 |
Rectangle2D rectangleDegrees = sector.toRectangleDegrees(); |
316 | 276 |
RasterManager rasterManager = RasterLocator.getManager(); |
... | ... | |
319 | 279 |
return dataStructFactory.createExtent(rectangleDegrees); |
320 | 280 |
} |
321 | 281 |
|
322 |
private double getCellSize(Sector sector, int width) { |
|
323 |
|
|
324 |
Rectangle2D rectangleDegrees = sector.toRectangleDegrees(); |
|
325 |
|
|
326 |
return rectangleDegrees.getWidth() / width; |
|
327 |
} |
|
328 |
|
|
329 |
private boolean isPointOfBuffer(Point2D rasterPoint, Buffer buffer) { |
|
330 |
if (layer instanceof FLyrRaster) { |
|
331 |
double x = rasterPoint.getX(); |
|
332 |
double y = rasterPoint.getY(); |
|
333 |
return x > -1 && y > -1 && x < buffer.getWidth() |
|
334 |
&& y < buffer.getHeight() ? true : false; |
|
335 |
} |
|
336 |
return false; |
|
337 |
} |
|
338 |
|
|
339 | 282 |
private void setNumberToDataRaster(ByteBufferRaster byteBuferRaster, |
340 | 283 |
int line, int col, Number value) { |
341 | 284 |
byteBuferRaster.setDoubleAtPosition(line, col, value.doubleValue()); |
... | ... | |
354 | 297 |
if (!canvas.getSector().intersects(getSector())) { |
355 | 298 |
return; |
356 | 299 |
} |
357 |
|
|
300 |
|
|
301 |
if (!layer.isAvailable()){ |
|
302 |
try { |
|
303 |
layer.reload(); |
|
304 |
if(!layer.isAvailable()){ |
|
305 |
throw new ReloadLayerException(layer.getName(), null); |
|
306 |
} |
|
307 |
} catch (ReloadLayerException e) { |
|
308 |
LOG.error( |
|
309 |
String.format("%1s layer is no available... canceling drawing process", |
|
310 |
layer.getName()), e); |
|
311 |
return; |
|
312 |
} |
|
313 |
} |
|
314 |
|
|
358 | 315 |
Sector overlap = this.getSector().intersection(canvas.getSector()); |
359 |
|
|
316 |
|
|
360 | 317 |
ViewPort viewPort = |
361 | 318 |
new ViewPort(mapControl3D.getMapContext().getProjection()); |
362 | 319 |
|
... | ... | |
370 | 327 |
|
371 | 328 |
try { |
372 | 329 |
|
373 |
IProjection projection =
|
|
374 |
mapControl3D.getMapContext().getProjection();
|
|
330 |
Point2D p1 = new Point2D.Double(degrees[2], degrees[0]);
|
|
331 |
Point2D p2 = new Point2D.Double(degrees[3], degrees[1]);
|
|
375 | 332 |
|
376 |
ICoordTrans ct = CRSFactory.getCRS("EPSG:4326").getCT(projection); |
|
377 |
Point2D p1 = |
|
378 |
convert(ct, new Point2D.Double(degrees[2], degrees[0])); |
|
379 |
Point2D p2 = |
|
380 |
convert(ct, new Point2D.Double(degrees[3], degrees[1])); |
|
381 |
|
|
382 | 333 |
envelope = |
383 | 334 |
geoManager.createEnvelope(Math.min(p1.getX(), p2.getX()), |
384 | 335 |
Math.min(p1.getY(), p2.getY()), |
... | ... | |
444 | 395 |
|
445 | 396 |
try { |
446 | 397 |
layer.draw(image, (Graphics2D) image.getGraphics(), viewPort, |
447 |
mapControl3D.getCancellable(), getScale(viewPort)); |
|
398 |
new Cancellable() { |
|
399 |
|
|
400 |
boolean canceled = false; |
|
401 |
|
|
402 |
@Override |
|
403 |
public void setCanceled(boolean canceled) { |
|
404 |
this.canceled = canceled; |
|
405 |
|
|
406 |
} |
|
407 |
|
|
408 |
@Override |
|
409 |
public boolean isCanceled() { |
|
410 |
return canceled; |
|
411 |
} |
|
412 |
}, getScale(viewPort)); |
|
448 | 413 |
|
449 | 414 |
if (layer instanceof FLyrVect && layer instanceof ILabelable) { |
450 | 415 |
|
... | ... | |
466 | 431 |
LOG.warn("Can't draw required zone of layer {}, can't read legend", |
467 | 432 |
layer.getName()); |
468 | 433 |
return; |
469 |
} finally { |
|
470 |
if (mapControl3D.getCancellable().isCanceled()) { |
|
471 |
return; |
|
472 |
} |
|
473 |
} |
|
434 |
} |
|
435 |
|
|
474 | 436 |
BufferedImageRaster bufferedImageRaster = |
475 | 437 |
new BufferedImageRaster(overlap, image); |
476 | 438 |
bufferedImageRaster.drawOnTo(canvas); |
477 | 439 |
|
478 | 440 |
} |
479 | 441 |
|
480 |
private Point2D convert(ICoordTrans ct, Point2D srcPoint) { |
|
481 |
if (ct == null) { |
|
482 |
return srcPoint; |
|
483 |
} |
|
484 |
return ct.convert(srcPoint, null); |
|
485 |
} |
|
486 |
|
|
487 | 442 |
private java.awt.geom.AffineTransform computeSourceToDestTransform( |
488 | 443 |
int sourceWidth, int sourceHeight, Sector sourceSector, int destWidth, |
489 | 444 |
int destHeight, Sector destSector) { |
2.1/branches/org.gvsig.view3d_soporte_bbdd_proyecciones/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/DefaultLayerConverter.java | ||
---|---|---|
39 | 39 |
import java.security.MessageDigest; |
40 | 40 |
import java.security.NoSuchAlgorithmException; |
41 | 41 |
|
42 |
import org.cresques.cts.ICoordTrans; |
|
43 | 42 |
import org.cresques.cts.IProjection; |
44 | 43 |
import org.gvsig.fmap.crs.CRSFactory; |
44 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
45 | 45 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
46 |
import org.gvsig.fmap.dal.coverage.grid.render.VisualPropertyListener; |
|
46 | 47 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
47 | 48 |
import org.gvsig.fmap.dal.exception.DataException; |
48 | 49 |
import org.gvsig.fmap.geom.primitive.Envelope; |
50 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
51 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
|
49 | 52 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
50 | 53 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
51 | 54 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
55 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
|
52 | 56 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
57 |
import org.gvsig.raster.fmap.layers.ILayerState; |
|
58 |
import org.gvsig.raster.fmap.layers.NotAvailableStateException; |
|
53 | 59 |
import org.gvsig.view3d.lib.api.View3DLocator; |
54 | 60 |
import org.gvsig.view3d.lib.api.View3DManager; |
55 | 61 |
import org.gvsig.view3d.lib.api.properties.LayerProperties3D; |
56 | 62 |
import org.gvsig.view3d.swing.api.MapControl3D; |
63 |
import org.gvsig.view3d.swing.api.exceptions.ConversionLayerException; |
|
57 | 64 |
import org.gvsig.view3d.swing.impl.DefaultMapControl3D; |
58 | 65 |
import org.slf4j.Logger; |
59 | 66 |
import org.slf4j.LoggerFactory; |
... | ... | |
74 | 81 |
private final int DEFAULT_TILE_HEIGHT = 512; |
75 | 82 |
|
76 | 83 |
public Layer convertToLayer(MapControl3D mapControl, FLayer layer) |
77 |
throws DataException { |
|
84 |
throws ConversionLayerException { |
|
85 |
|
|
86 |
IProjection projectionLayer = layer.getProjection(); |
|
87 |
if(projectionLayer == null){ |
|
88 |
projectionLayer = mapControl.getMapContext().getProjection(); |
|
89 |
} |
|
90 |
|
|
91 |
if (!projectionLayer.equals(CRSFactory.getCRS("ESPG:4326"))) { |
|
92 |
|
|
93 |
// Create new layer and configure it to be drawn projected on the fly |
|
94 |
try { |
|
95 |
layer = createNewProjectedOnTheFlyLayer(layer, projectionLayer); |
|
96 |
} catch (LoadLayerException e) { |
|
97 |
throw new ConversionLayerException("Can not create layer and set" |
|
98 |
+ " project on the fly configuration", e); |
|
99 |
} |
|
100 |
} |
|
78 | 101 |
|
79 | 102 |
AVList params = new AVListImpl(); |
80 | 103 |
|
... | ... | |
97 | 120 |
} |
98 | 121 |
|
99 | 122 |
public ElevationModel convertToElevationModel(MapControl3D mapControl, |
100 |
FLayer layer) { |
|
123 |
FLayer layer) throws ConversionLayerException { |
|
124 |
|
|
125 |
IProjection projectionLayer = layer.getProjection(); |
|
126 |
if(projectionLayer == null){ |
|
127 |
projectionLayer = mapControl.getMapContext().getProjection(); |
|
128 |
} |
|
129 |
|
|
130 |
if (!projectionLayer.equals(CRSFactory.getCRS("ESPG:4326"))) { |
|
131 |
try { |
|
132 |
layer = createNewProjectedOnTheFlyLayer(layer, projectionLayer); |
|
133 |
} catch (LoadLayerException e) { |
|
134 |
throw new ConversionLayerException("Can not create layer and set" |
|
135 |
+ " project on the fly configuration", e); |
|
136 |
} |
|
137 |
} |
|
101 | 138 |
|
102 | 139 |
AVList params = new AVListImpl(); |
103 | 140 |
|
... | ... | |
118 | 155 |
new DefaultElevationModel(doc.getDocumentElement(), paramsLayer); |
119 | 156 |
return elevationModel; |
120 | 157 |
} |
158 |
|
|
159 |
private FLayer createNewProjectedOnTheFlyLayer(FLayer layer, IProjection projectionLayer) |
|
160 |
throws LoadLayerException { |
|
161 |
|
|
162 |
LayerProperties3D oldLayerProperties = |
|
163 |
View3DLocator.getManager().getLayerProperties(layer); |
|
164 |
|
|
165 |
FLayer newLayer = null; |
|
166 |
DataStoreParameters parameters = null; |
|
167 |
if (layer instanceof FLyrVect) { |
|
168 |
FLyrVect layerVect = (FLyrVect) layer; |
|
169 |
parameters = layerVect.getFeatureStore().getParameters(); |
|
170 |
} else if (layer instanceof FLyrRaster) { |
|
171 |
FLyrRaster layerRaster = (FLyrRaster) layer; |
|
172 |
parameters = layerRaster.getDataStore().getParameters(); |
|
173 |
} |
|
121 | 174 |
|
175 |
newLayer = |
|
176 |
MapContextLocator.getMapContextManager().createLayer(layer.getName(), parameters); |
|
177 |
newLayer.setCoordTrans(projectionLayer.getCT(CRSFactory.getCRS("EPSG:4326"))); |
|
178 |
|
|
179 |
// Set the same legend/render to new layer |
|
180 |
if(newLayer instanceof FLyrVect){ |
|
181 |
((FLyrVect) newLayer).setLegend((IVectorLegend) ((FLyrVect)layer).getLegend()); |
|
182 |
} else if (newLayer instanceof FLyrRaster){ |
|
183 |
|
|
184 |
// Set layer initialized and opened to avoid render configurations changes |
|
185 |
FLyrRaster rasterLayer = (FLyrRaster) newLayer; |
|
186 |
rasterLayer.setLayerInitialized(true); |
|
187 |
if(rasterLayer instanceof ILayerState){ |
|
188 |
try { |
|
189 |
((ILayerState) rasterLayer).enableOpen(); |
|
190 |
} catch (NotAvailableStateException e) { |
|
191 |
throw new LoadLayerException(rasterLayer.getName(), e); |
|
192 |
} |
|
193 |
} |
|
194 |
|
|
195 |
rasterLayer.getDataStore().setRender(((FLyrRaster) layer).getRender()); |
|
196 |
|
|
197 |
// Add layer to listen visual property changes. This is necessary |
|
198 |
// because we are initializing layer manually to avoid render filters changes. |
|
199 |
if(rasterLayer instanceof VisualPropertyListener){ |
|
200 |
rasterLayer.getRender().addVisualPropertyListener((VisualPropertyListener) rasterLayer); |
|
201 |
} |
|
202 |
} |
|
203 |
|
|
204 |
View3DLocator.getManager().setLayerProperties(newLayer, oldLayerProperties); |
|
205 |
return newLayer; |
|
206 |
} |
|
207 |
|
|
122 | 208 |
private String getUniqueCacheId(FLayer layer) { |
123 | 209 |
// TODO This is not valid. We have to take in account more properties |
124 | 210 |
// to get unique cache id |
... | ... | |
378 | 464 |
private Sector getSector(FLayer layer, IProjection projection) |
379 | 465 |
throws DataException { |
380 | 466 |
|
381 |
ICoordTrans ct = projection.getCT(CRSFactory.getCRS("EPSG:4326")); |
|
382 | 467 |
Point2D p1 = null; |
383 | 468 |
Point2D p2 = null; |
384 | 469 |
Envelope envelope = layer.getFullEnvelope(); |
385 | 470 |
|
386 |
p1 = |
|
387 |
convert( |
|
388 |
ct, |
|
389 |
new Point2D.Double(envelope.getMinimum(0), envelope |
|
390 |
.getMinimum(1))); |
|
391 |
p2 = |
|
392 |
convert( |
|
393 |
ct, |
|
394 |
new Point2D.Double(envelope.getMaximum(0), envelope |
|
395 |
.getMaximum(1))); |
|
471 |
p1 = new Point2D.Double(envelope.getMinimum(0), envelope |
|
472 |
.getMinimum(1)); |
|
473 |
p2 = new Point2D.Double(envelope.getMaximum(0), envelope |
|
474 |
.getMaximum(1)); |
|
396 | 475 |
|
397 | 476 |
double minLatitude = |
398 | 477 |
Double.isInfinite(p1.getY()) || p1.getY() < Angle.NEG90.degrees |
... | ... | |
464 | 543 |
private LatLon computeDesiredTileDelta(Sector sector) { |
465 | 544 |
return LatLon.fromDegrees(sector.getDeltaLatDegrees(), sector.getDeltaLonDegrees()); |
466 | 545 |
} |
467 |
|
|
468 |
private Point2D convert(ICoordTrans ct, Point2D point) { |
|
469 |
if (ct == null) { |
|
470 |
return point; |
|
471 |
} |
|
472 |
|
|
473 |
return ct.convert(point, null); |
|
474 |
} |
|
475 |
|
|
476 | 546 |
} |
2.1/branches/org.gvsig.view3d_soporte_bbdd_proyecciones/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/LayerConverter.java | ||
---|---|---|
27 | 27 |
import gov.nasa.worldwind.globes.ElevationModel; |
28 | 28 |
import gov.nasa.worldwind.layers.Layer; |
29 | 29 |
|
30 |
import org.gvsig.fmap.dal.exception.DataException; |
|
31 | 30 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
32 | 31 |
import org.gvsig.view3d.swing.api.MapControl3D; |
32 |
import org.gvsig.view3d.swing.api.exceptions.ConversionLayerException; |
|
33 | 33 |
|
34 | 34 |
/** |
35 | 35 |
* Factory to convert {@link FLayer} to {@link Layer} or {@link ElevationModel}. |
... | ... | |
49 | 49 |
* @param layer |
50 | 50 |
* <code>FLayer</code> to be converted. |
51 | 51 |
* @return An instance of {@link DefaultTiledImageLayer}. |
52 |
* @throws DataException |
|
53 |
* if there are some problems getting some information of |
|
54 |
* <code>FLayer</code>. |
|
52 |
* @throws ConversionLayerException |
|
53 |
* If there are some error converting layer to be loaded |
|
55 | 54 |
*/ |
56 | 55 |
public Layer convertToLayer(MapControl3D mapControl, FLayer layer) |
57 |
throws DataException;
|
|
56 |
throws ConversionLayerException;
|
|
58 | 57 |
|
59 | 58 |
/** |
60 | 59 |
* Converts {@link FLayer} to {@link ElevationModel}. |
61 |
* <code>ElevationModel</code> properties are definied by 3D properties of
|
|
60 |
* <code>ElevationModel</code> properties are defined by 3D properties of |
|
62 | 61 |
* The type of <code>WW ElevationModel</code> is defined by the 3D |
63 | 62 |
* properties of <code>FLayer</code>. If there are some parameters undefined |
64 | 63 |
* is set to default value. |
... | ... | |
68 | 67 |
* @param layer |
69 | 68 |
* <code>FLayer</code> to be converted. |
70 | 69 |
* @return An instance of {@link DefaultTiledImageLayer}. |
71 |
* @throws DataException |
|
72 |
* if there are some problems getting some information of |
|
73 |
* <code>FLayer</code>. |
|
70 |
* @throws ConversionLayerException |
|
71 |
* If there are some error converting layer to be loaded |
|
74 | 72 |
*/ |
75 | 73 |
public ElevationModel convertToElevationModel(MapControl3D mapControl, |
76 |
FLayer layer); |
|
74 |
FLayer layer) throws ConversionLayerException;
|
|
77 | 75 |
} |
2.1/branches/org.gvsig.view3d_soporte_bbdd_proyecciones/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/DefaultMapControl3D.java | ||
---|---|---|
31 | 31 |
import gov.nasa.worldwind.avlist.AVKey; |
32 | 32 |
import gov.nasa.worldwind.avlist.AVListImpl; |
33 | 33 |
import gov.nasa.worldwind.awt.WorldWindowGLJPanel; |
34 |
import gov.nasa.worldwind.geom.Sector; |
|
35 | 34 |
import gov.nasa.worldwind.globes.Earth; |
36 | 35 |
import gov.nasa.worldwind.globes.EarthFlat; |
37 | 36 |
import gov.nasa.worldwind.globes.ElevationModel; |
... | ... | |
59 | 58 |
import javax.swing.JComponent; |
60 | 59 |
import javax.swing.JPanel; |
61 | 60 |
|
62 |
import org.gvsig.fmap.dal.exception.DataException; |
|
63 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
64 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
65 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
66 |
import org.gvsig.fmap.geom.GeometryManager; |
|
67 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
|
68 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
69 | 61 |
import org.gvsig.fmap.mapcontext.MapContext; |
70 | 62 |
import org.gvsig.fmap.mapcontext.layers.ExtendedPropertiesSupport; |
71 | 63 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
... | ... | |
87 | 79 |
import org.gvsig.view3d.swing.api.View3DSwingLocator; |
88 | 80 |
import org.gvsig.view3d.swing.api.View3DSwingManager; |
89 | 81 |
import org.gvsig.view3d.swing.api.View3DSwingManager.TYPE; |
82 |
import org.gvsig.view3d.swing.api.exceptions.ConversionLayerException; |
|
90 | 83 |
import org.gvsig.view3d.swing.api.properties.GeneralProperties3D; |
91 | 84 |
import org.gvsig.view3d.swing.api.properties.MapControlProperties3D; |
92 | 85 |
import org.gvsig.view3d.swing.impl.data.DefaultLayerConverter; |
... | ... | |
242 | 235 |
|
243 | 236 |
} |
244 | 237 |
|
245 |
protected void addGvSIGLayer(FLayer layer) throws DataException {
|
|
238 |
protected void addGvSIGLayer(FLayer layer) throws ConversionLayerException {
|
|
246 | 239 |
LayerList layers = getWwd().getModel().getLayers(); |
247 | 240 |
addGvSIGLayer(layer, layers.size()); |
248 | 241 |
} |
249 | 242 |
|
250 |
protected void addGvSIGLayer(FLayer layer, int index) throws DataException { |
|
251 |
|
|
252 |
if(!isValidLayer(layer)){ |
|
253 |
LOG.warn( |
|
254 |
"Invalid layer {}. Make sure layer has valid projection. 3D plugins only accepts EPSG:4326", |
|
255 |
layer); |
|
256 |
return; |
|
257 |
} |
|
258 |
|
|
243 |
protected void addGvSIGLayer(FLayer layer, int index) throws ConversionLayerException { |
|
244 |
|
|
259 | 245 |
LayerConverter converter = new DefaultLayerConverter(); |
260 | 246 |
|
261 | 247 |
View3DManager manager = View3DLocator.getManager(); |
... | ... | |
269 | 255 |
|
270 | 256 |
Layer rasterTiledLayer = converter.convertToLayer(this, layer); |
271 | 257 |
rasterTiledLayer.setEnabled(layer.isVisible()); |
258 |
this.synchronizer.registerLayer(layer, rasterTiledLayer); |
|
272 | 259 |
getWwd().getModel().getLayers().add(index, rasterTiledLayer); |
260 |
|
|
273 | 261 |
} else { |
274 | 262 |
return; //TODO Convert to 3D vectorial layer |
275 | 263 |
} |
276 | 264 |
} else { |
277 | 265 |
ElevationModel elevationModel = |
278 | 266 |
converter.convertToElevationModel(this, layer); |
267 |
this.synchronizer.registerLayer(layer, elevationModel); |
|
279 | 268 |
CompoundElevationModel cem = |
280 | 269 |
(CompoundElevationModel) getWwd().getModel().getGlobe() |
281 | 270 |
.getElevationModel(); |
... | ... | |
283 | 272 |
} |
284 | 273 |
} |
285 | 274 |
|
286 |
private boolean isValidLayer(FLayer layer) { |
|
287 |
|
|
288 |
// Checks if layer envelope is valid or not. |
|
289 |
GeometryManager geoManager = GeometryLocator.getGeometryManager(); |
|
290 |
double[] degreesArray = Sector.FULL_SPHERE.asDegreesArray(); |
|
291 |
Envelope fullSphereEnvelope = null; |
|
292 |
|
|
293 |
try { |
|
294 |
fullSphereEnvelope = |
|
295 |
geoManager.createEnvelope(degreesArray[2], degreesArray[0], |
|
296 |
degreesArray[3], degreesArray[1], SUBTYPES.GEOM2D); |
|
297 |
|
|
298 |
Envelope fullEnvelope = layer.getFullEnvelope(); |
|
299 |
// return fullSphereEnvelope.contains(fullEnvelope); |
|
300 |
|
|
301 |
return (fullEnvelope.getMinimum(1)>=-90 & fullEnvelope.getMinimum(1)<=90 && fullEnvelope.getMaximum(1)>=-90 & fullEnvelope.getMaximum(1)<=90); |
|
302 |
} catch (CreateEnvelopeException e) { |
|
303 |
LOG.error( |
|
304 |
"Can't create envelope with this parameters {} {} {} {} {}", |
|
305 |
new Object[] { degreesArray[2], degreesArray[3], |
|
306 |
degreesArray[0], degreesArray[1], SUBTYPES.GEOM2D }); |
|
307 |
return false; |
|
308 |
} catch (ReadException e) { |
|
309 |
LOG.error("Can't get envelope of {}. Can't determinate if layer is valid or not."); |
|
310 |
return false; |
|
311 |
} |
|
312 |
} |
|
313 |
|
|
314 | 275 |
private void addGvSIGLayers(FLayers layers) throws BaseException { |
315 | 276 |
if (layers == null) { |
316 | 277 |
return; |
... | ... | |
598 | 559 |
} |
599 | 560 |
|
600 | 561 |
public void reloadLayers() { |
601 |
getWwd().getModel().getLayers().removeAll(); |
|
602 | 562 |
|
563 |
this.wwd.getModel().getLayers().removeAll(); |
|
564 |
Model auxModel = (Model) WorldWind.createConfigurationComponent(AVKey.MODEL_CLASS_NAME); |
|
565 |
this.wwd.getModel().setLayers(auxModel.getLayers()); |
|
566 |
setGeneral3DProperties(); |
|
567 |
setMapControl3DProperties(); |
|
568 |
addNavigation(); |
|
569 |
|
|
603 | 570 |
if (this.mapContext != null && this.mapContext.getLayers() != null) { |
604 | 571 |
try { |
605 | 572 |
addGvSIGLayers(mapContext.getLayers()); |
606 | 573 |
} catch (BaseException e) { |
607 |
LOG.error("Can't add MapContext layers of {}", |
|
608 |
mapContext.getLayers(), e); |
|
574 |
LOG.error("Can't add MapContext layers of {}", mapContext.getLayers(), e); |
|
609 | 575 |
} |
610 | 576 |
} |
611 | 577 |
} |
... | ... | |
661 | 627 |
} |
662 | 628 |
} |
663 | 629 |
|
664 |
public void synchronizeLayers() { |
|
665 |
this.synchronizer.synchronizeLayers(); |
|
666 |
} |
|
667 |
|
|
668 | 630 |
public void synchronizeViewPorts() { |
669 | 631 |
this.synchronizer.synchronizeViewPorts(); |
670 | 632 |
} |
2.1/branches/org.gvsig.view3d_soporte_bbdd_proyecciones/org.gvsig.view3d.swing/org.gvsig.view3d.swing.api/src/main/java/org/gvsig/view3d/swing/api/exceptions/ConversionLayerException.java | ||
---|---|---|
1 |
package org.gvsig.view3d.swing.api.exceptions; |
|
2 |
|
|
3 |
import org.gvsig.tools.exception.BaseException; |
|
4 |
|
|
5 |
|
|
6 |
/** |
|
7 |
* Exception to indicate that a layer can not be converted to WW Layer to be added to WW view. |
|
8 |
* |
|
9 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
|
10 |
* |
|
11 |
*/ |
|
12 |
public class ConversionLayerException extends BaseException { |
|
13 |
|
|
14 |
/** |
|
15 |
* |
|
16 |
*/ |
Also available in: Unified diff