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