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 / DefaultTiledImageLayer.java @ 474
History | View | Annotate | Download (8.7 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.data; |
26 |
|
27 |
import gov.nasa.worldwind.avlist.AVKey; |
28 |
import gov.nasa.worldwind.avlist.AVList; |
29 |
import gov.nasa.worldwind.data.RasterServer; |
30 |
import gov.nasa.worldwind.geom.Angle; |
31 |
import gov.nasa.worldwind.geom.Extent; |
32 |
import gov.nasa.worldwind.geom.Sector; |
33 |
import gov.nasa.worldwind.layers.BasicTiledImageLayer; |
34 |
import gov.nasa.worldwind.layers.TextureTile; |
35 |
import gov.nasa.worldwind.render.DrawContext; |
36 |
import gov.nasa.worldwind.retrieve.RetrievalPostProcessor; |
37 |
import gov.nasa.worldwind.retrieve.Retriever; |
38 |
import gov.nasa.worldwind.retrieve.RetrieverFactory; |
39 |
import gov.nasa.worldwind.util.Logging; |
40 |
import gov.nasa.worldwind.util.WWUtil; |
41 |
|
42 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
43 |
import org.gvsig.view3d.swing.api.MapControl3D; |
44 |
import org.gvsig.view3d.swing.impl.DefaultMapControl3D; |
45 |
import org.slf4j.Logger; |
46 |
import org.slf4j.LoggerFactory; |
47 |
import org.w3c.dom.Element; |
48 |
|
49 |
/**
|
50 |
* Default implementation of {@link BasicTiledImageLayer}. This class represents
|
51 |
* a tiled raster layer. Manages creation of tiles, visibility of tiles, levels
|
52 |
* of details, resolution...
|
53 |
*
|
54 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
55 |
*/
|
56 |
public class DefaultTiledImageLayer extends BasicTiledImageLayer { |
57 |
|
58 |
private static final Logger LOG = LoggerFactory |
59 |
.getLogger(DefaultTiledImageLayer.class); |
60 |
|
61 |
/**
|
62 |
* Default constructor from parameters.
|
63 |
*
|
64 |
* @param params
|
65 |
* parameters of {@link DefaultTiledImageLayer}
|
66 |
*/
|
67 |
public DefaultTiledImageLayer(AVList params) {
|
68 |
|
69 |
super(params);
|
70 |
|
71 |
this.createRasterServer(params);
|
72 |
} |
73 |
|
74 |
/**
|
75 |
* Default constructor form {@link Element}. Requerided parameters:
|
76 |
*
|
77 |
* <ul>
|
78 |
* <li>AVKey.DATASET_NAME</li>
|
79 |
* <li>AVKey.DATA_CACHE_NAME</li>
|
80 |
* <li>DefaultMapControl3D.GVSIG_MAPCONTROL3D</li>
|
81 |
* <li>DefaultMapControl3D.GVSIG_LAYER</li>
|
82 |
* </ul>
|
83 |
*
|
84 |
* @param domElement
|
85 |
* element that contains parameters values.
|
86 |
* @param params
|
87 |
* Additional parameters. If there are some parameter not defined
|
88 |
* at {@link Element}, it is getted from additional parameters.
|
89 |
*/
|
90 |
public DefaultTiledImageLayer(Element domElement, AVList params) { |
91 |
super(domElement, params);
|
92 |
|
93 |
this.createRasterServer(params != null ? params : (AVList) this |
94 |
.getValue(AVKey.CONSTRUCTION_PARAMETERS)); |
95 |
} |
96 |
|
97 |
private void createRasterServer(AVList params) { |
98 |
|
99 |
if (params == null) { |
100 |
LOG.error("Can not create raster server, parameters is null");
|
101 |
throw new IllegalArgumentException(); |
102 |
} |
103 |
|
104 |
if (this.getDataFileStore() == null) { |
105 |
LOG.error("Can not create raster server, file store is null");
|
106 |
throw new IllegalArgumentException(); |
107 |
} |
108 |
|
109 |
String datasetName = params.getStringValue(AVKey.DATASET_NAME);
|
110 |
if (WWUtil.isEmpty(datasetName)) {
|
111 |
LOG.error( |
112 |
"Can not create raster server, missing required parameter: {}",
|
113 |
AVKey.DATASET_NAME); |
114 |
throw new IllegalArgumentException(); |
115 |
} |
116 |
|
117 |
String dataCacheName = params.getStringValue(AVKey.DATA_CACHE_NAME);
|
118 |
if (WWUtil.isEmpty(dataCacheName)) {
|
119 |
LOG.error( |
120 |
"Can not create raster server, missing required parameter: {}",
|
121 |
AVKey.DATA_CACHE_NAME); |
122 |
throw new IllegalArgumentException(); |
123 |
} |
124 |
|
125 |
MapControl3D mapControl3D = |
126 |
(MapControl3D) params |
127 |
.getValue(DefaultMapControl3D.GVSIG_MAPCONTROL3D); |
128 |
|
129 |
if (mapControl3D == null) { |
130 |
LOG.error( |
131 |
"Can not create raster server, missing required parameter: {}",
|
132 |
DefaultMapControl3D.GVSIG_MAPCONTROL3D); |
133 |
throw new IllegalArgumentException(); |
134 |
} |
135 |
|
136 |
FLayer layer = |
137 |
(FLayer) params.getValue(DefaultMapControl3D.GVSIG_LAYER); |
138 |
|
139 |
if (layer == null) { |
140 |
LOG.error( |
141 |
"Can not create raster server, missing required parameter: {}",
|
142 |
"GVSIG_LAYER");
|
143 |
throw new IllegalArgumentException(); |
144 |
} |
145 |
|
146 |
final AVList rasterServerParams = params.copy();
|
147 |
|
148 |
rasterServerParams.setValue(AVKey.FILE_STORE, this.getDataFileStore());
|
149 |
|
150 |
RetrieverFactory retrieverFactory = new RetrieverFactory() {
|
151 |
|
152 |
final protected RasterServer rasterServer = |
153 |
new DefaultRasterServer(rasterServerParams);
|
154 |
|
155 |
public Retriever createRetriever(AVList tileParams,
|
156 |
RetrievalPostProcessor postProcessor) { |
157 |
|
158 |
DefaultRasterServerRetriever retriever = |
159 |
new DefaultRasterServerRetriever(tileParams,
|
160 |
this.rasterServer, postProcessor);
|
161 |
|
162 |
// copy only values that do not exist in destination AVList
|
163 |
// from rasterServerParams (source) to retriever (destination)
|
164 |
|
165 |
String[] keysToCopy = |
166 |
new String[] { AVKey.DATASET_NAME, AVKey.DISPLAY_NAME, |
167 |
AVKey.FILE_STORE, AVKey.IMAGE_FORMAT, |
168 |
AVKey.FORMAT_SUFFIX }; |
169 |
|
170 |
WWUtil.copyValues(rasterServerParams, retriever, keysToCopy, |
171 |
false);
|
172 |
|
173 |
return retriever;
|
174 |
} |
175 |
}; |
176 |
|
177 |
params.setValue(AVKey.RETRIEVER_FACTORY_LOCAL, retrieverFactory); |
178 |
this.setValue(AVKey.RETRIEVER_FACTORY_LOCAL, retrieverFactory);
|
179 |
|
180 |
} |
181 |
|
182 |
protected boolean isTileVisible(DrawContext dc, TextureTile tile) { |
183 |
|
184 |
if (tile.getSector().isWithinLatLonLimits()) {
|
185 |
return tile.getExtent(dc).intersects(
|
186 |
dc.getView().getFrustumInModelCoordinates()) |
187 |
&& (dc.getVisibleSector() == null || dc.getVisibleSector()
|
188 |
.intersects(tile.getSector())); |
189 |
} else {
|
190 |
|
191 |
// Try to fix extend. This is necessary to avoid problems getting if
|
192 |
// some tile is visible or not when the tile has corrupt sector like
|
193 |
// 180.0000001 or -90.000000004561
|
194 |
Extent extend = this.fixExtend(tile, dc);
|
195 |
return extend.intersects(dc.getView()
|
196 |
.getFrustumInModelCoordinates()) |
197 |
&& (dc.getVisibleSector() == null || dc.getVisibleSector()
|
198 |
.intersects(tile.getSector())); |
199 |
} |
200 |
} |
201 |
|
202 |
private Extent fixExtend(TextureTile tile, DrawContext dc) {
|
203 |
|
204 |
if (dc == null) { |
205 |
String msg = Logging.getMessage("nullValue.DrawContextIsNull"); |
206 |
Logging.logger().severe(msg); |
207 |
throw new IllegalArgumentException(msg); |
208 |
} |
209 |
|
210 |
if (tile.getSector().isWithinLatLonLimits()) {
|
211 |
return Sector.computeBoundingBox(dc.getGlobe(),
|
212 |
dc.getVerticalExaggeration(), tile.getSector()); |
213 |
} else {
|
214 |
|
215 |
double[] degreesArray = tile.getSector().asDegreesArray(); |
216 |
|
217 |
double minLatitude =
|
218 |
degreesArray[0] < Angle.NEG90.degrees ? Angle.NEG90.degrees
|
219 |
: degreesArray[0];
|
220 |
double maxLatitude =
|
221 |
degreesArray[1] > Angle.POS90.degrees ? Angle.POS90.degrees
|
222 |
: degreesArray[1];
|
223 |
double minLongitude =
|
224 |
degreesArray[2] < Angle.NEG180.degrees ? Angle.NEG180.degrees
|
225 |
: degreesArray[2];
|
226 |
double maxLongitude =
|
227 |
degreesArray[3] > Angle.POS180.degrees ? Angle.POS180.degrees
|
228 |
: degreesArray[3];
|
229 |
|
230 |
Sector adjustedSector = |
231 |
new Sector(Angle.fromDegrees(minLatitude),
|
232 |
Angle.fromDegrees(maxLatitude), |
233 |
Angle.fromDegrees(minLongitude), |
234 |
Angle.fromDegrees(maxLongitude)); |
235 |
|
236 |
return Sector.computeBoundingBox(dc.getGlobe(),
|
237 |
dc.getVerticalExaggeration(), adjustedSector); |
238 |
} |
239 |
} |
240 |
} |