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