gvsig-3d / 2.1 / trunk / org.gvsig.view3d / org.gvsig.view3d.swing / org.gvsig.view3d.swing.impl / src / main / java / org / gvsig / view3d / swing / impl / DefaultMapControl3D.java @ 693
History | View | Annotate | Download (25.9 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright ? 2007-2015 gvSIG Association
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.view3d.swing.impl; |
26 |
|
27 |
import gov.nasa.worldwind.Configuration; |
28 |
import gov.nasa.worldwind.Factory; |
29 |
import gov.nasa.worldwind.Model; |
30 |
import gov.nasa.worldwind.WorldWind; |
31 |
import gov.nasa.worldwind.avlist.AVKey; |
32 |
import gov.nasa.worldwind.avlist.AVListImpl; |
33 |
import gov.nasa.worldwind.awt.WorldWindowGLJPanel; |
34 |
import gov.nasa.worldwind.globes.Earth; |
35 |
import gov.nasa.worldwind.globes.EarthFlat; |
36 |
import gov.nasa.worldwind.globes.ElevationModel; |
37 |
import gov.nasa.worldwind.layers.CompassLayer; |
38 |
import gov.nasa.worldwind.layers.Layer; |
39 |
import gov.nasa.worldwind.layers.LayerList; |
40 |
import gov.nasa.worldwind.layers.ScalebarLayer; |
41 |
import gov.nasa.worldwind.layers.SkyColorLayer; |
42 |
import gov.nasa.worldwind.layers.SkyGradientLayer; |
43 |
import gov.nasa.worldwind.layers.StarsLayer; |
44 |
import gov.nasa.worldwind.layers.ViewControlsLayer; |
45 |
import gov.nasa.worldwind.layers.ViewControlsSelectListener; |
46 |
import gov.nasa.worldwind.layers.WorldMapLayer; |
47 |
import gov.nasa.worldwind.terrain.CompoundElevationModel; |
48 |
import gov.nasa.worldwind.terrain.ZeroElevationModel; |
49 |
import gov.nasa.worldwind.util.StatusBar; |
50 |
import gov.nasa.worldwind.view.orbit.BasicOrbitView; |
51 |
import gov.nasa.worldwind.view.orbit.FlatOrbitView; |
52 |
|
53 |
import java.awt.BorderLayout; |
54 |
import java.beans.PropertyChangeEvent; |
55 |
import java.beans.PropertyChangeListener; |
56 |
import java.util.List; |
57 |
|
58 |
import javax.swing.JComponent; |
59 |
import javax.swing.JPanel; |
60 |
|
61 |
import org.gvsig.fmap.mapcontext.MapContext; |
62 |
import org.gvsig.fmap.mapcontext.layers.ExtendedPropertiesSupport; |
63 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
64 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
65 |
import org.gvsig.fmap.mapcontext.layers.operations.LayersVisitor; |
66 |
import org.gvsig.tools.exception.BaseException; |
67 |
import org.gvsig.tools.observer.BaseNotification; |
68 |
import org.gvsig.tools.observer.Notification; |
69 |
import org.gvsig.tools.observer.ObservableHelper; |
70 |
import org.gvsig.tools.observer.Observer; |
71 |
import org.gvsig.tools.task.Cancellable; |
72 |
import org.gvsig.tools.visitor.VisitCanceledException; |
73 |
import org.gvsig.view3d.lib.api.View3DLocator; |
74 |
import org.gvsig.view3d.lib.api.View3DManager; |
75 |
import org.gvsig.view3d.lib.api.properties.LayerProperties3D; |
76 |
import org.gvsig.view3d.lib.api.properties.RasterLayerProperties3D; |
77 |
import org.gvsig.view3d.lib.api.properties.VectorialLayerProperties3D; |
78 |
import org.gvsig.view3d.swing.api.MapControl3D; |
79 |
import org.gvsig.view3d.swing.api.View3DSwingLocator; |
80 |
import org.gvsig.view3d.swing.api.View3DSwingManager; |
81 |
import org.gvsig.view3d.swing.api.View3DSwingManager.TYPE; |
82 |
import org.gvsig.view3d.swing.api.exceptions.ConversionLayerException; |
83 |
import org.gvsig.view3d.swing.api.properties.GeneralProperties3D; |
84 |
import org.gvsig.view3d.swing.api.properties.MapControlProperties3D; |
85 |
import org.gvsig.view3d.swing.impl.data.DefaultLayerConverter; |
86 |
import org.gvsig.view3d.swing.impl.data.LayerConverter; |
87 |
import org.slf4j.Logger; |
88 |
import org.slf4j.LoggerFactory; |
89 |
|
90 |
/**
|
91 |
* Default implementation of {@link MapControl3D}.
|
92 |
*
|
93 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
94 |
*/
|
95 |
@SuppressWarnings("deprecation") |
96 |
public class DefaultMapControl3D extends JPanel implements MapControl3D { |
97 |
|
98 |
private static final long serialVersionUID = 2024899922367896097L; |
99 |
|
100 |
private static final Logger LOG = LoggerFactory.getLogger(DefaultMapControl3D.class); |
101 |
|
102 |
private DefaultSynchronizer synchronizer;
|
103 |
|
104 |
private ObservableHelper observableHelper;
|
105 |
|
106 |
/**
|
107 |
* Name of gvSIG MapContext property
|
108 |
*/
|
109 |
public static final String GVSIG_MAPCONTROL3D = "org.gvsig.view3d.swing.api.MapControl3D"; |
110 |
|
111 |
/**
|
112 |
* Name of gvSIG Layer property
|
113 |
*/
|
114 |
public static final String GVSIG_LAYER = "org.gvsig.fmap.mapcontext.layers.FLayer"; |
115 |
|
116 |
private MapContext mapContext;
|
117 |
|
118 |
private MapControlProperties3D properties;
|
119 |
|
120 |
private ExtendedPropertiesSupport viewProperties;
|
121 |
|
122 |
private WorldWindowGLJPanel wwd;
|
123 |
|
124 |
private PropertyChangeListener verticalExaggerationPropertyListener; |
125 |
|
126 |
private PropertyChangeListener propertiesChangeListener; |
127 |
|
128 |
private StatusBar statusBar;
|
129 |
|
130 |
private TYPE type;
|
131 |
|
132 |
private Cancellable cancellable;
|
133 |
|
134 |
/**
|
135 |
* Default constructor of {@link DefaultMapControl3D}. Initializes local
|
136 |
* fileds, sets configuration depends on {@link TYPE} and adds
|
137 |
* <code>MapContext</code> layers.
|
138 |
*
|
139 |
* @param theMapContext
|
140 |
* associated <code>MapContext</code>
|
141 |
* @param type
|
142 |
* Type of this {@link DefaultMapControl3D}. See {@link TYPE}.
|
143 |
* @param viewProperties
|
144 |
* View properties to register this <code>MapControl3D</code>
|
145 |
*/
|
146 |
public DefaultMapControl3D(MapContext theMapContext, TYPE type,
|
147 |
ExtendedPropertiesSupport viewProperties) { |
148 |
|
149 |
super(new BorderLayout()); |
150 |
|
151 |
this.mapContext = theMapContext;
|
152 |
this.type = type;
|
153 |
this.cancellable = getCancellable();
|
154 |
this.observableHelper = new ObservableHelper(); |
155 |
this.viewProperties = viewProperties;
|
156 |
|
157 |
View3DSwingManager swingManager = View3DSwingLocator.getManager(); |
158 |
this.properties = swingManager.getMapControl3DProperties(viewProperties);
|
159 |
|
160 |
// Set pre configurations before instance WWD component
|
161 |
preConfiguration(); |
162 |
|
163 |
// Instance WWD component
|
164 |
getWwd(); |
165 |
|
166 |
// Set post configurations after instance WWD component
|
167 |
postConfiguration(); |
168 |
|
169 |
super.add(getWwd(), BorderLayout.CENTER); |
170 |
|
171 |
super.add(getStatusBar(), BorderLayout.SOUTH); |
172 |
|
173 |
this.synchronizer = new DefaultSynchronizer(this, this.mapContext, getWwd()); |
174 |
|
175 |
try {
|
176 |
addGvSIGLayers(mapContext.getLayers()); |
177 |
} catch (BaseException e) {
|
178 |
LOG.info("Can't add MapControl layers", e);
|
179 |
} |
180 |
} |
181 |
|
182 |
private void preConfiguration() { |
183 |
|
184 |
// WWD Mode
|
185 |
if (type == TYPE.SPHERE) {
|
186 |
setSpherePanelConfiguration(); |
187 |
} else if (type == TYPE.FLAT) { |
188 |
setFlatPanelConfiguration(); |
189 |
} |
190 |
|
191 |
// Enable or disable anaglyph mode
|
192 |
setAnaglyphMode(this.properties.getAnaglyphMode());
|
193 |
} |
194 |
|
195 |
private void postConfiguration() { |
196 |
setGeneral3DProperties(); |
197 |
|
198 |
this.properties.addPropertyChangeListener(getPropertiesChangeListener());
|
199 |
setMapControl3DProperties(); |
200 |
|
201 |
getWwd().getSceneController().addPropertyChangeListener( |
202 |
getVerticalExaggerationPropertyListener()); |
203 |
|
204 |
getWwd().getView().getViewInputHandler().setStopOnFocusLost(false);
|
205 |
} |
206 |
|
207 |
private PropertyChangeListener getPropertiesChangeListener() { |
208 |
if (this.propertiesChangeListener == null) { |
209 |
this.propertiesChangeListener = new PropertyChangeListener() { |
210 |
|
211 |
public void propertyChange(PropertyChangeEvent evt) { |
212 |
|
213 |
String propertyName = evt.getPropertyName();
|
214 |
|
215 |
if (MapControlProperties3D.SPHERE_VERTICAL_EXAGGERATION_PROPERTY_NAME
|
216 |
.equals(propertyName) && getType() == TYPE.SPHERE) { |
217 |
setVerticalExaggeration((Double) evt.getNewValue());
|
218 |
|
219 |
} else if (MapControlProperties3D.FLAT_VERTICAL_EXAGGERATION_PROPERTY_NAME |
220 |
.equals(propertyName) && getType() == TYPE.FLAT) { |
221 |
setVerticalExaggeration((Double) evt.getNewValue());
|
222 |
|
223 |
} else if (MapControlProperties3D.BLUE_MARBEL_VISIBILITY_PROPERTY_NAME |
224 |
.equals(propertyName)) { |
225 |
boolean visibility = (Boolean) evt.getNewValue(); |
226 |
setBlueMarbelLayerVisibility(visibility); |
227 |
|
228 |
} else if (MapControlProperties3D.NASA_LANDSAT_VISIBILITY_PROPERTY_NAME |
229 |
.equals(propertyName)) { |
230 |
boolean visibility = (Boolean) evt.getNewValue(); |
231 |
setNasaLandsatLayerVisibility(visibility); |
232 |
|
233 |
} else if (MapControlProperties3D.DEFAULT_ELEVATION_VISIBILITY_PROPERTY_NAME |
234 |
.equals(propertyName)) { |
235 |
boolean visibility = (Boolean) evt.getNewValue(); |
236 |
setDefaultElevationVisibility(visibility); |
237 |
} |
238 |
} |
239 |
}; |
240 |
|
241 |
} |
242 |
return this.propertiesChangeListener; |
243 |
} |
244 |
|
245 |
private PropertyChangeListener getVerticalExaggerationPropertyListener() { |
246 |
if (this.verticalExaggerationPropertyListener == null) { |
247 |
this.verticalExaggerationPropertyListener = new PropertyChangeListener() { |
248 |
|
249 |
public void propertyChange(PropertyChangeEvent evt) { |
250 |
String propertyName = evt.getPropertyName();
|
251 |
if (propertyName.equals(AVKey.VERTICAL_EXAGGERATION)) {
|
252 |
Double value = (Double) evt.getNewValue(); |
253 |
if (getType() == TYPE.SPHERE) {
|
254 |
getProperties().setSphereVerticalExaggeration(value); |
255 |
} else if (getType() == TYPE.FLAT) { |
256 |
getProperties().setFlatVerticalExaggeration(value); |
257 |
} |
258 |
} |
259 |
} |
260 |
}; |
261 |
} |
262 |
return this.verticalExaggerationPropertyListener; |
263 |
} |
264 |
|
265 |
private void setAnaglyphMode(boolean flag) { |
266 |
if (flag) {
|
267 |
System.setProperty("gov.nasa.worldwind.stereo.mode", "redblue"); |
268 |
} else {
|
269 |
System.setProperty("gov.nasa.worldwind.stereo.mode", ""); |
270 |
} |
271 |
} |
272 |
|
273 |
private void setGeneral3DProperties() { |
274 |
|
275 |
View3DSwingManager swingManager = View3DSwingLocator.getManager(); |
276 |
GeneralProperties3D general3DProperties = swingManager.getGeneral3DProperties(); |
277 |
|
278 |
this.setAtmosphereVisibility(general3DProperties.getAtmosphereVisibility());
|
279 |
this.setMiniMapVisibility(general3DProperties.getMinimapVisibility());
|
280 |
this.setNorthIndicatorVisibility(general3DProperties.getNorthIndicatorVisibility());
|
281 |
this.setStarsBackgroundVisibility(general3DProperties.getStarsBackgroundVisibility());
|
282 |
this.setScaleVisibility(general3DProperties.getScaleVisibility());
|
283 |
} |
284 |
|
285 |
protected void addGvSIGLayer(FLayer layer) throws ConversionLayerException { |
286 |
LayerList layers = getWwd().getModel().getLayers(); |
287 |
addGvSIGLayer(layer, layers.size()); |
288 |
} |
289 |
|
290 |
protected void addGvSIGLayer(FLayer layer, int index) throws ConversionLayerException { |
291 |
|
292 |
LayerConverter converter = new DefaultLayerConverter();
|
293 |
|
294 |
View3DManager manager = View3DLocator.getManager(); |
295 |
LayerProperties3D layerProperties = manager.getLayerProperties(layer); |
296 |
|
297 |
if (layerProperties.getElevation() == false) { |
298 |
|
299 |
if ((layerProperties instanceof VectorialLayerProperties3D && ((VectorialLayerProperties3D) layerProperties) |
300 |
.getRasterized() == true) || layerProperties instanceof RasterLayerProperties3D) { |
301 |
|
302 |
Layer rasterTiledLayer = converter.convertToLayer(this, layer);
|
303 |
rasterTiledLayer.setEnabled(layer.isVisible()); |
304 |
this.synchronizer.registerLayer(layer, rasterTiledLayer);
|
305 |
getWwd().getModel().getLayers().add(index, rasterTiledLayer); |
306 |
|
307 |
} else {
|
308 |
return; // TODO Convert to 3D vector layer |
309 |
} |
310 |
} else {
|
311 |
ElevationModel elevationModel = converter.convertToElevationModel(this, layer);
|
312 |
this.synchronizer.registerLayer(layer, elevationModel);
|
313 |
CompoundElevationModel cem = |
314 |
(CompoundElevationModel) getWwd().getModel().getGlobe().getElevationModel(); |
315 |
cem.addElevationModel(elevationModel); |
316 |
} |
317 |
} |
318 |
|
319 |
private void addGvSIGLayers(FLayers layers) throws BaseException { |
320 |
if (layers == null) { |
321 |
return;
|
322 |
} |
323 |
|
324 |
layers.accept(new LayersVisitor() {
|
325 |
|
326 |
public void visit(Object obj) throws VisitCanceledException, BaseException { |
327 |
throw new UnsupportedOperationException(); |
328 |
|
329 |
} |
330 |
|
331 |
public void visit(FLayer layer) throws BaseException { |
332 |
|
333 |
if (layer.isAvailable()) {
|
334 |
addGvSIGLayer(layer); |
335 |
} |
336 |
} |
337 |
}); |
338 |
|
339 |
getWwd().redraw(); |
340 |
} |
341 |
|
342 |
private void setBlueMarbelLayerVisibility(boolean visibility) { |
343 |
|
344 |
if (visibility == getBlueMarbleLayerVisibility()) {
|
345 |
return;
|
346 |
} |
347 |
|
348 |
setWWLayerVisibility("Blue Marble May 2004", visibility);
|
349 |
getProperties().setBlueMarbleLayerVisibility(visibility); |
350 |
} |
351 |
|
352 |
private boolean getBlueMarbleLayerVisibility() { |
353 |
return isWWLayerVisible("Blue Marble May 2004"); |
354 |
} |
355 |
|
356 |
protected void setDefaultElevationVisibility(boolean visibility) { |
357 |
|
358 |
ElevationModel elevationModel = getWwd().getModel().getGlobe().getElevationModel(); |
359 |
CompoundElevationModel compoundElevationModel = (CompoundElevationModel) elevationModel; |
360 |
List<ElevationModel> elevationModels = compoundElevationModel.getElevationModels();
|
361 |
|
362 |
if (visibility == getDefaultElevationModelVisiblility()) {
|
363 |
return;
|
364 |
} |
365 |
|
366 |
if (visibility) {
|
367 |
for (ElevationModel eModel : elevationModels) {
|
368 |
if (eModel instanceof ZeroElevationModel) { |
369 |
compoundElevationModel.removeElevationModel(eModel); |
370 |
compoundElevationModel.addElevationModel(0, getDefaultElevationModel());
|
371 |
return;
|
372 |
} |
373 |
} |
374 |
|
375 |
} else {
|
376 |
for (ElevationModel eModel : elevationModels) {
|
377 |
if (eModel.getName().equals("USA 10m, World 30m, Ocean 900m")) { |
378 |
compoundElevationModel.removeElevationModel(eModel); |
379 |
compoundElevationModel.addElevationModel(0, new ZeroElevationModel()); |
380 |
return;
|
381 |
} |
382 |
} |
383 |
} |
384 |
getProperties().setDefaultElevationVisibility(visibility); |
385 |
} |
386 |
|
387 |
private boolean getDefaultElevationModelVisiblility() { |
388 |
ElevationModel elevationModel = getWwd().getModel().getGlobe().getElevationModel(); |
389 |
CompoundElevationModel compoundElevationModel = (CompoundElevationModel) elevationModel; |
390 |
List<ElevationModel> elevationModels = compoundElevationModel.getElevationModels();
|
391 |
for (ElevationModel eModel : elevationModels) {
|
392 |
if (eModel.getName().equals("USA 10m, World 30m, Ocean 900m")) { |
393 |
return true; |
394 |
} |
395 |
} |
396 |
return false; |
397 |
} |
398 |
|
399 |
private ElevationModel getDefaultElevationModel() {
|
400 |
Factory elevationFactory = |
401 |
(Factory) WorldWind.createConfigurationComponent(AVKey.ELEVATION_MODEL_FACTORY); |
402 |
String defaultModelFile =
|
403 |
Configuration.getStringValue(AVKey.EARTH_ELEVATION_MODEL_CONFIG_FILE);
|
404 |
|
405 |
CompoundElevationModel elevationModel = |
406 |
(CompoundElevationModel) elevationFactory.createFromConfigSource(defaultModelFile, |
407 |
new AVListImpl());
|
408 |
|
409 |
return elevationModel.getElevationModels().get(0); |
410 |
} |
411 |
|
412 |
private void setNasaLandsatLayerVisibility(boolean visibility) { |
413 |
|
414 |
if (visibility == getNasaLandsatLayerVisibility()) {
|
415 |
return;
|
416 |
} |
417 |
|
418 |
setWWLayerVisibility("i-cubed Landsat", visibility);
|
419 |
getProperties().setNasaLandsatVisibility(visibility); |
420 |
} |
421 |
|
422 |
private boolean getNasaLandsatLayerVisibility() { |
423 |
return isWWLayerVisible("i-cubed Landsat"); |
424 |
} |
425 |
|
426 |
@SuppressWarnings("rawtypes") |
427 |
private void setWWLayerVisibility(Class layerClazz, boolean visiblity) { |
428 |
List<Layer> layersByClass = getWwd().getModel().getLayers().getLayersByClass(layerClazz);
|
429 |
|
430 |
for (Layer layer : layersByClass) {
|
431 |
layer.setEnabled(visiblity); |
432 |
} |
433 |
}; |
434 |
|
435 |
private void setWWLayerVisibility(String layerName, boolean visibilty) { |
436 |
Layer layer = getWwd().getModel().getLayers().getLayerByName(layerName); |
437 |
if (layer != null) { |
438 |
layer.setEnabled(visibilty); |
439 |
} |
440 |
}; |
441 |
|
442 |
private void addNavigation() { |
443 |
|
444 |
ViewControlsLayer controlsLayer = new ViewControlsLayer();
|
445 |
|
446 |
Model model = getWwd().getModel(); |
447 |
model.getLayers().add(controlsLayer); |
448 |
|
449 |
getWwd().addSelectListener(new ViewControlsSelectListener(wwd, controlsLayer));
|
450 |
} |
451 |
|
452 |
public JComponent asJComponent() { |
453 |
return this; |
454 |
} |
455 |
|
456 |
public void dispose() { |
457 |
|
458 |
Thread disposeThread = new Thread(new Runnable() { |
459 |
|
460 |
public void run() { |
461 |
Notification beforeDisposeNotification =
|
462 |
new BaseNotification(MapControl3D.BEFORE_DISPOSE_MAPCONTEX3D_NOTIFICATION, null); |
463 |
|
464 |
observableHelper.notifyObservers(DefaultMapControl3D.this, |
465 |
beforeDisposeNotification); |
466 |
|
467 |
if (beforeDisposeNotification.isCanceled()) {
|
468 |
LOG.warn("Dispose action canceled by some observer");
|
469 |
return;
|
470 |
} |
471 |
|
472 |
if(WorldWind.getRetrievalService().hasActiveTasks()){
|
473 |
WorldWind.getRetrievalService().shutdown(true);
|
474 |
} |
475 |
|
476 |
if(WorldWind.getRemoteRetrievalService().hasActiveTasks()){
|
477 |
WorldWind.getRemoteRetrievalService().shutdown(true);
|
478 |
} |
479 |
|
480 |
// Remove change properties listener
|
481 |
getWwd().getSceneController().removePropertyChangeListener( |
482 |
getVerticalExaggerationPropertyListener()); |
483 |
properties.removePropertyChangeListener(getPropertiesChangeListener()); |
484 |
|
485 |
// Dispose WWD component
|
486 |
disposeWwd(); |
487 |
|
488 |
// Remove properties from view
|
489 |
if (getType() == TYPE.SPHERE) {
|
490 |
viewProperties.getExtendedProperties().remove("sphereMapControl3D");
|
491 |
} else if (getType() == TYPE.FLAT) { |
492 |
viewProperties.getExtendedProperties().remove("flatMapControl3D");
|
493 |
} |
494 |
|
495 |
synchronizer.dispose(); |
496 |
synchronizer = null;
|
497 |
properties = null;
|
498 |
mapContext = null;
|
499 |
|
500 |
Notification afterDisposeNotification =
|
501 |
new BaseNotification(MapControl3D.AFTER_DISPOSE_MAPCONTEX3D_NOTIFICATION, null); |
502 |
|
503 |
observableHelper |
504 |
.notifyObservers(DefaultMapControl3D.this, afterDisposeNotification); |
505 |
} |
506 |
}, "Dispose World Wind thread");
|
507 |
|
508 |
disposeThread.start(); |
509 |
} |
510 |
|
511 |
public Cancellable getCancellable() {
|
512 |
if (this.cancellable == null) { |
513 |
this.cancellable = new Cancellable() { |
514 |
|
515 |
private boolean cancel = false; |
516 |
|
517 |
public void setCanceled(boolean canceled) { |
518 |
this.cancel = canceled;
|
519 |
} |
520 |
|
521 |
public boolean isCanceled() { |
522 |
return cancel;
|
523 |
} |
524 |
}; |
525 |
} |
526 |
|
527 |
return this.cancellable; |
528 |
} |
529 |
|
530 |
public MapContext getMapContext() {
|
531 |
return this.mapContext; |
532 |
} |
533 |
|
534 |
private StatusBar getStatusBar() {
|
535 |
if (statusBar == null) { |
536 |
statusBar = new StatusBar();
|
537 |
this.add(statusBar, BorderLayout.PAGE_END); |
538 |
statusBar.setEventSource(wwd); |
539 |
} |
540 |
return statusBar;
|
541 |
} |
542 |
|
543 |
public TYPE getType() {
|
544 |
return this.type; |
545 |
} |
546 |
|
547 |
public double getVerticalExaggeration() { |
548 |
return getWwd().getSceneController().getVerticalExaggeration();
|
549 |
} |
550 |
|
551 |
private WorldWindowGLJPanel getWwd() {
|
552 |
if (this.wwd == null) { |
553 |
intializeWWPanel(); |
554 |
} |
555 |
return this.wwd; |
556 |
} |
557 |
|
558 |
private void disposeWwd() { |
559 |
if (getWwd() != null) { |
560 |
this.wwd = null; |
561 |
} |
562 |
} |
563 |
|
564 |
public void setAtmosphereVisibility(boolean visibility) { |
565 |
if (getType() == TYPE.SPHERE) {
|
566 |
setWWLayerVisibility(SkyGradientLayer.class, visibility); |
567 |
} else if (getType() == TYPE.FLAT) { |
568 |
setWWLayerVisibility(SkyColorLayer.class, visibility); |
569 |
} |
570 |
} |
571 |
|
572 |
public void setMiniMapVisibility(boolean visiblity) { |
573 |
setWWLayerVisibility(WorldMapLayer.class, visiblity); |
574 |
} |
575 |
|
576 |
public void setNorthIndicatorVisibility(boolean visibility) { |
577 |
setWWLayerVisibility(CompassLayer.class, visibility); |
578 |
} |
579 |
|
580 |
public void setScaleVisibility(boolean visibility) { |
581 |
setWWLayerVisibility(ScalebarLayer.class, visibility); |
582 |
} |
583 |
|
584 |
public void setStarsBackgroundVisibility(boolean visibility) { |
585 |
setWWLayerVisibility(StarsLayer.class, visibility); |
586 |
} |
587 |
|
588 |
private void intializeWWPanel() { |
589 |
wwd = new WorldWindowGLJPanel();
|
590 |
|
591 |
// Create the default model as described in the current worldwind
|
592 |
// properties.
|
593 |
Model m = (Model) WorldWind.createConfigurationComponent(AVKey.MODEL_CLASS_NAME); |
594 |
getWwd().setModel(m); |
595 |
|
596 |
// Add view control layer
|
597 |
addNavigation(); |
598 |
} |
599 |
|
600 |
public void reloadLayers() { |
601 |
|
602 |
this.wwd.getModel().getLayers().removeAll();
|
603 |
Model auxModel = (Model) WorldWind.createConfigurationComponent(AVKey.MODEL_CLASS_NAME); |
604 |
this.wwd.getModel().setLayers(auxModel.getLayers());
|
605 |
setGeneral3DProperties(); |
606 |
setMapControl3DProperties(); |
607 |
addNavigation(); |
608 |
|
609 |
if (this.mapContext != null && this.mapContext.getLayers() != null) { |
610 |
try {
|
611 |
addGvSIGLayers(mapContext.getLayers()); |
612 |
} catch (BaseException e) {
|
613 |
LOG.error("Can't add MapContext layers of {}", mapContext.getLayers(), e);
|
614 |
} |
615 |
} |
616 |
} |
617 |
|
618 |
private void setFlatPanelConfiguration() { |
619 |
Configuration.setValue(AVKey.GLOBE_CLASS_NAME, EarthFlat.class.getName());
|
620 |
Configuration.setValue(AVKey.VIEW_CLASS_NAME, FlatOrbitView.class.getName());
|
621 |
} |
622 |
|
623 |
private void setMapControl3DProperties() { |
624 |
|
625 |
double verticalExaggeration = 0; |
626 |
if (getType() == TYPE.SPHERE) {
|
627 |
verticalExaggeration = this.properties.getSphereVerticalExaggeration();
|
628 |
} else if (getType() == TYPE.FLAT) { |
629 |
verticalExaggeration = this.properties.getFlatVerticalExaggeration();
|
630 |
} |
631 |
setVerticalExaggeration(verticalExaggeration); |
632 |
|
633 |
boolean visibility = this.properties.getBlueMarbleLayerVisibility(); |
634 |
setBlueMarbelLayerVisibility(visibility); |
635 |
|
636 |
visibility = this.properties.getNasaLandsatLayerVisibility();
|
637 |
setNasaLandsatLayerVisibility(visibility); |
638 |
|
639 |
visibility = this.properties.getDefaultElevationVisibility();
|
640 |
setDefaultElevationVisibility(visibility); |
641 |
|
642 |
boolean anaglyphMode = this.properties.getAnaglyphMode(); |
643 |
if (anaglyphMode) {
|
644 |
|
645 |
} |
646 |
} |
647 |
|
648 |
private void setSpherePanelConfiguration() { |
649 |
Configuration.setValue(AVKey.GLOBE_CLASS_NAME, Earth.class.getName());
|
650 |
Configuration.setValue(AVKey.VIEW_CLASS_NAME, BasicOrbitView.class.getName());
|
651 |
} |
652 |
|
653 |
private void setVerticalExaggeration(double verticalExaggeration) { |
654 |
|
655 |
if (getVerticalExaggeration() == verticalExaggeration) {
|
656 |
return;
|
657 |
} |
658 |
|
659 |
getWwd().getSceneController().setVerticalExaggeration(verticalExaggeration); |
660 |
|
661 |
if (getType() == TYPE.SPHERE) {
|
662 |
getProperties().setSphereVerticalExaggeration(verticalExaggeration); |
663 |
} else if (getType() == TYPE.FLAT) { |
664 |
getProperties().setFlatVerticalExaggeration(verticalExaggeration); |
665 |
} |
666 |
} |
667 |
|
668 |
public void synchronizeViewPorts() { |
669 |
this.synchronizer.synchronizeViewPorts();
|
670 |
} |
671 |
|
672 |
public void addObserver(Observer o) { |
673 |
if (observableHelper != null) { |
674 |
observableHelper.addObserver(o); |
675 |
} |
676 |
} |
677 |
|
678 |
public void deleteObserver(Observer o) { |
679 |
if (observableHelper != null) { |
680 |
observableHelper.deleteObserver(o); |
681 |
} |
682 |
|
683 |
} |
684 |
|
685 |
public void deleteObservers() { |
686 |
if (observableHelper != null) { |
687 |
observableHelper.deleteObservers(); |
688 |
} |
689 |
} |
690 |
|
691 |
public boolean getAtmosphereVisibility() { |
692 |
if (isWWLayerVisible(SkyGradientLayer.class) || isWWLayerVisible(SkyColorLayer.class)) {
|
693 |
return true; |
694 |
} |
695 |
return false; |
696 |
} |
697 |
|
698 |
public boolean getMinimapVisibility() { |
699 |
if (isWWLayerVisible(WorldMapLayer.class)) {
|
700 |
return true; |
701 |
} |
702 |
return false; |
703 |
} |
704 |
|
705 |
public boolean getNorthIndicatorVisibility() { |
706 |
if (isWWLayerVisible(CompassLayer.class)) {
|
707 |
return true; |
708 |
} |
709 |
return false; |
710 |
} |
711 |
|
712 |
public boolean getStarBackgroundVisibility() { |
713 |
if (isWWLayerVisible(StarsLayer.class)) {
|
714 |
return true; |
715 |
} |
716 |
return false; |
717 |
} |
718 |
|
719 |
public boolean getScaleVisibility() { |
720 |
if (isWWLayerVisible(ScalebarLayer.class)) {
|
721 |
return true; |
722 |
} |
723 |
return false; |
724 |
} |
725 |
|
726 |
@SuppressWarnings("rawtypes") |
727 |
private boolean isWWLayerVisible(Class clazz) { |
728 |
List<Layer> layersByClass = getWwd().getModel().getLayers().getLayersByClass(clazz);
|
729 |
for (Layer layer : layersByClass) {
|
730 |
return layer.isEnabled();
|
731 |
} |
732 |
return false; |
733 |
} |
734 |
|
735 |
private boolean isWWLayerVisible(String name) { |
736 |
Layer layer = getWwd().getModel().getLayers().getLayerByName(name); |
737 |
if (layer != null) { |
738 |
return layer.isEnabled();
|
739 |
} |
740 |
return false; |
741 |
} |
742 |
|
743 |
public MapControlProperties3D getProperties() {
|
744 |
return properties;
|
745 |
} |
746 |
|
747 |
@Override
|
748 |
public Object getUnderLineComponent() { |
749 |
return this.getWwd(); |
750 |
} |
751 |
} |