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 / data / DefaultElevationModel.java @ 541
History | View | Annotate | Download (4.51 KB)
1 | 474 | llmarques | package org.gvsig.view3d.swing.impl.data; |
---|---|---|---|
2 | |||
3 | 541 | llmarques | import gov.nasa.worldwind.WorldWind; |
4 | 474 | llmarques | import gov.nasa.worldwind.avlist.AVKey; |
5 | import gov.nasa.worldwind.avlist.AVList; |
||
6 | 496 | llmarques | import gov.nasa.worldwind.cache.FileStore; |
7 | 474 | llmarques | import gov.nasa.worldwind.data.RasterServer; |
8 | import gov.nasa.worldwind.retrieve.RetrievalPostProcessor; |
||
9 | import gov.nasa.worldwind.retrieve.Retriever; |
||
10 | import gov.nasa.worldwind.retrieve.RetrieverFactory; |
||
11 | import gov.nasa.worldwind.terrain.BasicElevationModel; |
||
12 | import gov.nasa.worldwind.util.WWUtil; |
||
13 | |||
14 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
15 | 497 | llmarques | import org.gvsig.view3d.swing.api.MapControl3D; |
16 | 474 | llmarques | import org.gvsig.view3d.swing.impl.DefaultMapControl3D; |
17 | import org.slf4j.Logger; |
||
18 | import org.slf4j.LoggerFactory; |
||
19 | import org.w3c.dom.Element; |
||
20 | |||
21 | /**
|
||
22 | *
|
||
23 | * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
||
24 | *
|
||
25 | */
|
||
26 | public class DefaultElevationModel extends BasicElevationModel { |
||
27 | |||
28 | private static final Logger LOG = LoggerFactory |
||
29 | .getLogger(DefaultElevationModel.class); |
||
30 | |||
31 | /**
|
||
32 | *
|
||
33 | * @param params
|
||
34 | */
|
||
35 | public DefaultElevationModel(AVList params) {
|
||
36 | super(params);
|
||
37 | |||
38 | this.createRasterServer(params);
|
||
39 | } |
||
40 | |||
41 | /**
|
||
42 | *
|
||
43 | * @param domElement
|
||
44 | * @param params
|
||
45 | */
|
||
46 | public DefaultElevationModel(Element domElement, AVList params) { |
||
47 | super(domElement, params);
|
||
48 | |||
49 | this.createRasterServer(params != null ? params : (AVList) this |
||
50 | .getValue(AVKey.CONSTRUCTION_PARAMETERS)); |
||
51 | } |
||
52 | |||
53 | private void createRasterServer(AVList params) { |
||
54 | |||
55 | if (params == null) { |
||
56 | LOG.error("Can not create raster server, parameters is null");
|
||
57 | throw new IllegalArgumentException(); |
||
58 | } |
||
59 | |||
60 | 496 | llmarques | if (params.getValue(AVKey.FILE_STORE) == null) { |
61 | 541 | llmarques | setDataFileStore(WorldWind.getDataFileStore()); |
62 | 474 | llmarques | } |
63 | 496 | llmarques | |
64 | 474 | llmarques | String datasetName = params.getStringValue(AVKey.DATASET_NAME);
|
65 | if (WWUtil.isEmpty(datasetName)) {
|
||
66 | LOG.error( |
||
67 | "Can not create raster server, missing required parameter: {}",
|
||
68 | AVKey.DATASET_NAME); |
||
69 | throw new IllegalArgumentException(); |
||
70 | } |
||
71 | |||
72 | String dataCacheName = params.getStringValue(AVKey.DATA_CACHE_NAME);
|
||
73 | if (WWUtil.isEmpty(dataCacheName)) {
|
||
74 | LOG.error( |
||
75 | "Can not create raster server, missing required parameter: {}",
|
||
76 | AVKey.DATA_CACHE_NAME); |
||
77 | throw new IllegalArgumentException(); |
||
78 | } |
||
79 | |||
80 | 497 | llmarques | MapControl3D mapControl3D = |
81 | (MapControl3D) params.getValue(DefaultMapControl3D.GVSIG_MAPCONTROL3D); |
||
82 | 474 | llmarques | |
83 | 497 | llmarques | if (mapControl3D == null) { |
84 | 474 | llmarques | LOG.error( |
85 | "Can not create raster server, missing required parameter: {}",
|
||
86 | DefaultMapControl3D.GVSIG_MAPCONTROL3D); |
||
87 | throw new IllegalArgumentException(); |
||
88 | } |
||
89 | |||
90 | FLayer layer = |
||
91 | (FLayer) params.getValue(DefaultMapControl3D.GVSIG_LAYER); |
||
92 | |||
93 | if (layer == null) { |
||
94 | LOG.error( |
||
95 | "Can not create raster server, missing required parameter: {}",
|
||
96 | "GVSIG_LAYER");
|
||
97 | throw new IllegalArgumentException(); |
||
98 | } |
||
99 | |||
100 | final AVList rasterServerParams = params.copy();
|
||
101 | |||
102 | RetrieverFactory retrieverFactory = new RetrieverFactory() {
|
||
103 | |||
104 | final protected RasterServer rasterServer = |
||
105 | new DefaultRasterServer(rasterServerParams);
|
||
106 | |||
107 | public Retriever createRetriever(AVList tileParams,
|
||
108 | RetrievalPostProcessor postProcessor) { |
||
109 | 497 | llmarques | DefaultRasterServerRetriever retriever = |
110 | 474 | llmarques | new DefaultRasterServerRetriever(tileParams, rasterServer,
|
111 | postProcessor); |
||
112 | |||
113 | // copy only values that do not exist in destination AVList
|
||
114 | // from rasterServerParams (source) to retriever (destination)
|
||
115 | String[] keysToCopy = |
||
116 | new String[] { AVKey.DATASET_NAME, AVKey.DISPLAY_NAME, |
||
117 | AVKey.FILE_STORE, AVKey.BYTE_ORDER, AVKey.IMAGE_FORMAT, |
||
118 | AVKey.DATA_TYPE, AVKey.FORMAT_SUFFIX, |
||
119 | AVKey.MISSING_DATA_SIGNAL, |
||
120 | AVKey.MISSING_DATA_REPLACEMENT, AVKey.ELEVATION_MIN, |
||
121 | AVKey.ELEVATION_MAX, }; |
||
122 | |||
123 | WWUtil.copyValues(rasterServerParams, retriever, keysToCopy, |
||
124 | false);
|
||
125 | |||
126 | return retriever;
|
||
127 | } |
||
128 | }; |
||
129 | |||
130 | params.setValue(AVKey.RETRIEVER_FACTORY_LOCAL, retrieverFactory); |
||
131 | this.setValue(AVKey.RETRIEVER_FACTORY_LOCAL, retrieverFactory);
|
||
132 | } |
||
133 | } |