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