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