gvsig-raster / org.gvsig.raster.wms / branches / org.gvsig.raster.wms_dataaccess_refactoring / org.gvsig.raster.wms.app.wmsclient / src / main / java / org / gvsig / raster / wms / app / wmsclient / layer / FLyrWMS.java @ 2317
History | View | Annotate | Download (36.1 KB)
1 | 1944 | nbrodin | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
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 | */
|
||
22 | |||
23 | package org.gvsig.raster.wms.app.wmsclient.layer; |
||
24 | |||
25 | import java.awt.Dimension; |
||
26 | import java.awt.Graphics2D; |
||
27 | import java.awt.Point; |
||
28 | import java.awt.Rectangle; |
||
29 | import java.awt.geom.AffineTransform; |
||
30 | import java.awt.geom.NoninvertibleTransformException; |
||
31 | import java.awt.geom.Point2D; |
||
32 | import java.awt.geom.Rectangle2D; |
||
33 | import java.awt.image.BufferedImage; |
||
34 | import java.lang.ref.WeakReference; |
||
35 | import java.util.ArrayList; |
||
36 | import java.util.HashMap; |
||
37 | import java.util.Iterator; |
||
38 | import java.util.List; |
||
39 | import java.util.Vector; |
||
40 | import java.util.prefs.Preferences; |
||
41 | |||
42 | import javax.print.attribute.PrintRequestAttributeSet; |
||
43 | import javax.swing.JOptionPane; |
||
44 | |||
45 | import org.cresques.cts.ICoordTrans; |
||
46 | import org.cresques.cts.IProjection; |
||
47 | import org.gvsig.andami.PluginServices; |
||
48 | import org.gvsig.fmap.dal.DALLocator; |
||
49 | import org.gvsig.fmap.dal.DataManager; |
||
50 | import org.gvsig.fmap.dal.DataParameters; |
||
51 | import org.gvsig.fmap.dal.DataStore; |
||
52 | import org.gvsig.fmap.dal.DataStoreParameters; |
||
53 | import org.gvsig.fmap.dal.coverage.RasterLocator; |
||
54 | import org.gvsig.fmap.dal.coverage.RasterManager; |
||
55 | import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
||
56 | import org.gvsig.fmap.dal.coverage.datastruct.ViewPortData; |
||
57 | import org.gvsig.fmap.dal.coverage.exception.FilePaletteException; |
||
58 | import org.gvsig.fmap.dal.coverage.exception.InfoByPointException; |
||
59 | import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
||
60 | 2241 | nbrodin | import org.gvsig.fmap.dal.coverage.exception.QueryException; |
61 | 1944 | nbrodin | import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
62 | import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
||
63 | import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
||
64 | import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
||
65 | import org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters; |
||
66 | import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters; |
||
67 | 2312 | nbrodin | import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
68 | 1944 | nbrodin | import org.gvsig.fmap.dal.exception.DataException; |
69 | import org.gvsig.fmap.dal.exception.InitializeException; |
||
70 | import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
||
71 | import org.gvsig.fmap.dal.exception.ReadException; |
||
72 | import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
||
73 | import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
||
74 | 1979 | nbrodin | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
75 | 1944 | nbrodin | import org.gvsig.fmap.geom.GeometryLocator; |
76 | import org.gvsig.fmap.geom.GeometryManager; |
||
77 | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
||
78 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
79 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
80 | import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
||
81 | import org.gvsig.fmap.mapcontext.exceptions.UnsupportedVersionLayerException; |
||
82 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
83 | import org.gvsig.fmap.mapcontext.layers.Tiling; |
||
84 | import org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer; |
||
85 | import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
||
86 | import org.gvsig.gui.beans.Messages; |
||
87 | import org.gvsig.raster.fmap.layers.DefaultFLyrRaster; |
||
88 | import org.gvsig.raster.fmap.layers.IRasterLayerActions; |
||
89 | import org.gvsig.raster.fmap.layers.NotAvailableStateException; |
||
90 | import org.gvsig.raster.fmap.legend.ImageLegend; |
||
91 | import org.gvsig.raster.util.CancelTaskImpl; |
||
92 | import org.gvsig.raster.wms.app.wmsclient.wmc.WebMapContextTags; |
||
93 | import org.gvsig.raster.wms.app.wmsclient.wmc.XmlBuilder; |
||
94 | import org.gvsig.raster.wms.io.RemoteWMSStyle; |
||
95 | import org.gvsig.raster.wms.io.WMSDataParameters; |
||
96 | import org.gvsig.raster.wms.io.WMSLayerNode; |
||
97 | import org.gvsig.raster.wms.io.WMSServerExplorer; |
||
98 | import org.gvsig.raster.wms.io.WMSServerExplorerParameters; |
||
99 | import org.gvsig.tools.ToolsLocator; |
||
100 | import org.gvsig.tools.dynobject.DynObjectSet; |
||
101 | import org.gvsig.tools.dynobject.DynStruct; |
||
102 | import org.gvsig.tools.persistence.PersistenceManager; |
||
103 | import org.gvsig.tools.task.Cancellable; |
||
104 | import org.gvsig.tools.task.SimpleTaskStatus; |
||
105 | import org.gvsig.tools.task.TaskStatusManager; |
||
106 | import org.slf4j.Logger; |
||
107 | import org.slf4j.LoggerFactory; |
||
108 | |||
109 | |||
110 | |||
111 | /**
|
||
112 | * FMap's WMS Layer class.
|
||
113 | *
|
||
114 | * Las capas WMS son tileadas para descargarlas del servidor. Esto quiere decir que
|
||
115 | * est?n formadas por multiples ficheros raster. Por esto la fuente de datos raster (IRasterDatasource)
|
||
116 | * de la capa FLyrWMS es un objeto de tipo CompositeDataset. Este objeto est? compuesto por un array
|
||
117 | * bidimensional de MultiRasterDataset. Cada uno de los MultiRasterDataset corresponde con un tile
|
||
118 | * salvado en disco. Estos MultiRasterDataset se crean cada vez que se repinta ya que en WMS a cada
|
||
119 | * zoom varian los ficheros fuente. La secuencia de creaci?n de un CompositeDataset ser?a la siguiente:
|
||
120 | * <UL>
|
||
121 | * <LI>Se hace una petici?n de dibujado por parte del usuario llamando al m?todo draw de FLyrWMS</LI>
|
||
122 | * <LI>Se tilea la petici?n</LI>
|
||
123 | * <LI>Cada tile se dibuja abriendo una FLyerRaster para ese tile</LI>
|
||
124 | * <LI>Si es el primer dibujado se guarda una referencia en la capa WMS a las propiedades de renderizado, orden de bandas,
|
||
125 | * transparencia, filtros aplicados, ...</LI>
|
||
126 | * <LI>Si no es el primer dibujado se asignan las propiedades de renderizado cuya referencia se guarda en la capa WMS</LI>
|
||
127 | * <LI>Se guarda el MultiRasterDataset de cada tile</LI>
|
||
128 | * <LI>Al acabar todos los tiles creamos un CompositeDataset con los MultiRasterDataset de todos los tiles</LI>
|
||
129 | * <LI>Asignamos a la capa la referencia de las propiedades de renderizado que tenemos almacenadas. De esta forma si hay
|
||
130 | * alguna modificaci?n desde el cuadro de propiedades ser? efectiva sobre los tiles que se dibujan.</LI>
|
||
131 | * </UL>
|
||
132 | *
|
||
133 | *
|
||
134 | * @author Jaume Dominguez Faus
|
||
135 | *
|
||
136 | */
|
||
137 | @SuppressWarnings("deprecation") |
||
138 | public class FLyrWMS extends DefaultFLyrRaster { |
||
139 | public static final String PERSISTENT_NAME = "FLyrWMS_Persistent"; |
||
140 | public static final String PERSISTENT_DESCRIPTION = "FLyrWMS Persistent Definition"; |
||
141 | |||
142 | private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
||
143 | private static final Logger logger = LoggerFactory.getLogger(FLyrWMS.class); |
||
144 | private boolean mustTileDraw = false; |
||
145 | private boolean mustTilePrint = true; |
||
146 | private final int maxTileDrawWidth = 1023; |
||
147 | private final int maxTileDrawHeight = 1023; |
||
148 | private final int maxTilePrintWidth = 1023; |
||
149 | private final int maxTilePrintHeight = 1023; |
||
150 | private List<WeakReference<Thread>> disableUpdateDrawVersion; |
||
151 | 2317 | nbrodin | //private Envelope fullEnvelope = null;
|
152 | 1944 | nbrodin | private boolean firstLoad = false; |
153 | private RasterManager rManager = RasterLocator.getManager();
|
||
154 | private WMSServerExplorer explorer = null; |
||
155 | private boolean deleteCache = false; |
||
156 | |||
157 | public FLyrWMS() {
|
||
158 | super();
|
||
159 | this.updateDrawVersion();
|
||
160 | try {
|
||
161 | enableAwake(); |
||
162 | } catch (NotAvailableStateException e) {
|
||
163 | logger.error("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), this, e); |
||
164 | } |
||
165 | } |
||
166 | |||
167 | public FLyrWMS(DataStoreParameters dataStoreParameters) throws Exception { |
||
168 | this();
|
||
169 | //Create the explorer and connect
|
||
170 | DataManager dataManager = DALLocator.getDataManager(); |
||
171 | WMSServerExplorerParameters explorerParams = (WMSServerExplorerParameters) |
||
172 | dataManager.createServerExplorerParameters(WMSServerExplorer.NAME); |
||
173 | explorerParams.setHost((String)dataStoreParameters.getDynValue("uri")); |
||
174 | WMSServerExplorer wmsServerExplorer = |
||
175 | (WMSServerExplorer) dataManager.openServerExplorer(WMSServerExplorer.NAME, explorerParams); |
||
176 | wmsServerExplorer.connect(null, ((RemoteStoreParameters)dataStoreParameters).isDeletingCache());
|
||
177 | |||
178 | //Set the parameters
|
||
179 | setParameters((WMSDataParameters)dataStoreParameters); |
||
180 | setExplorer(wmsServerExplorer); |
||
181 | } |
||
182 | |||
183 | public static DataStore createDataStore(String host, IProjection srs) throws InitializeException { |
||
184 | DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
||
185 | RasterDataParameters params = null;
|
||
186 | try {
|
||
187 | params = (RasterDataParameters)dataman.createServerExplorerParameters(WMSServerExplorer.NAME); |
||
188 | } catch (InitializeException e) {
|
||
189 | return null; |
||
190 | } catch (ProviderNotRegisteredException e) {
|
||
191 | return null; |
||
192 | } |
||
193 | params.setURI(host); |
||
194 | params.setSRS(srs); |
||
195 | |||
196 | try {
|
||
197 | return dataman.openStore(params.getDataStoreName(), params);
|
||
198 | } catch (ValidateDataParametersException e) {
|
||
199 | throw new InitializeException(e); |
||
200 | } catch (ProviderNotRegisteredException e) {
|
||
201 | throw new InitializeException(e); |
||
202 | } |
||
203 | } |
||
204 | |||
205 | public void setDataStore(DataStore dataStore) throws LoadLayerException { |
||
206 | this.dataStore = (RasterDataStore) dataStore;
|
||
207 | try {
|
||
208 | this.dataStore.isOpen();
|
||
209 | if(!isOpen())
|
||
210 | enableOpen(); |
||
211 | } catch (NotAvailableStateException e) {
|
||
212 | logger.error("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), this, e); |
||
213 | } |
||
214 | setProjection(this.dataStore.getProjection());
|
||
215 | } |
||
216 | |||
217 | /**
|
||
218 | * It choose the best format to load different maps if the server
|
||
219 | * supports it. This format could be png, because it supports
|
||
220 | * transparency.
|
||
221 | * @param formats
|
||
222 | * Arraywith all the formats supported by the server
|
||
223 | * @return
|
||
224 | */
|
||
225 | @SuppressWarnings("unused") |
||
226 | private String getGreatFormat(Vector<String> formats){ |
||
227 | for (int i = 0 ; i < formats.size() ; i++){ |
||
228 | String format = (String) formats.get(i); |
||
229 | if (format.equals("image/jpg")){ |
||
230 | return format;
|
||
231 | } |
||
232 | if (format.equals("image/jpeg")){ |
||
233 | return format;
|
||
234 | } |
||
235 | } |
||
236 | return (String)formats.get(0); |
||
237 | } |
||
238 | 2317 | nbrodin | |
239 | 1944 | nbrodin | public static void registerPersistent() { |
240 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
241 | 2317 | nbrodin | DynStruct definition = manager.getDefinition("FLyrWMS_Persistent");
|
242 | 1944 | nbrodin | if( definition == null ) { |
243 | 2317 | nbrodin | if (manager.getDefinition(DefaultFLyrRaster.class) == null) { |
244 | DefaultFLyrRaster.registerPersistent(); |
||
245 | 1944 | nbrodin | } |
246 | |||
247 | definition = manager.addDefinition( |
||
248 | FLyrWMS.class, |
||
249 | 2317 | nbrodin | "FLyrWMS_Persistent",
|
250 | "FLyrWMS Persistent Definition",
|
||
251 | 1944 | nbrodin | null,
|
252 | null
|
||
253 | ); |
||
254 | |||
255 | 2317 | nbrodin | definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, DefaultFLyrRaster.PERSISTENT_NAME); |
256 | 1944 | nbrodin | } |
257 | |||
258 | DefaultFLyrRaster.registerPersistence(definition); |
||
259 | } |
||
260 | |||
261 | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
||
262 | Cancellable cancel, double scale) throws ReadException { |
||
263 | TaskStatusManager manager = ToolsLocator.getTaskStatusManager(); |
||
264 | SimpleTaskStatus taskStatus = new RasterTaskStatus("Drawing " + getName() + "...", cancel); |
||
265 | manager.add(taskStatus); |
||
266 | taskStatus.setAutoremove(true);
|
||
267 | |||
268 | if(!firstLoad) {
|
||
269 | try {
|
||
270 | initFilters(); |
||
271 | 2295 | nbrodin | try {
|
272 | if(!isOpen())
|
||
273 | enableOpen(); |
||
274 | } catch (NotAvailableStateException e) {
|
||
275 | throw new ReadException("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), e); |
||
276 | } |
||
277 | 1944 | nbrodin | } catch (FilePaletteException e) {
|
278 | logger.error(e.getMessage(), this, e);
|
||
279 | } |
||
280 | firstLoad = true;
|
||
281 | } |
||
282 | |||
283 | enableStopped(); |
||
284 | |||
285 | if(recalcLevel) {
|
||
286 | double pixelSize = viewPort.getEnvelope().getLength(0) / (double)viewPort.getImageWidth(); |
||
287 | zoomLevel = dataStore.getNearestLevel(pixelSize); |
||
288 | } |
||
289 | recalcLevel = true;
|
||
290 | |||
291 | if (isWithinScale(scale)) {
|
||
292 | |||
293 | if(mustTileDraw) {
|
||
294 | Point2D p = viewPort.getOffset();
|
||
295 | Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), viewPort.getImageWidth(), viewPort.getImageHeight()); |
||
296 | Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
|
||
297 | tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
||
298 | |||
299 | for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) { |
||
300 | // drawing part
|
||
301 | try {
|
||
302 | ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
||
303 | drawTile(g, vp, taskStatus, scale); |
||
304 | } catch (LoadLayerException e) {
|
||
305 | throw new ReadException(e.getMessage(), e); |
||
306 | } catch (NoninvertibleTransformException e) { |
||
307 | throw new ReadException(e.getMessage(), e); |
||
308 | } |
||
309 | } |
||
310 | } else {
|
||
311 | try {
|
||
312 | drawTile(g, viewPort, taskStatus, scale); |
||
313 | } catch (LoadLayerException e) {
|
||
314 | setAvailable(false);
|
||
315 | logger.error("Server error:" + e.getMessage(), e);
|
||
316 | } |
||
317 | } |
||
318 | } |
||
319 | disableStopped(); |
||
320 | } |
||
321 | |||
322 | |||
323 | /**
|
||
324 | * This is the method used to draw a tile in a WMS mosaic layer.
|
||
325 | * @throws LoadLayerException
|
||
326 | * @throws ReadDriverException
|
||
327 | * @return true when a tile has been painted
|
||
328 | */
|
||
329 | private void drawTile(Graphics2D g, ViewPort vp, SimpleTaskStatus taskStatus, double scale) throws LoadLayerException, ReadException { |
||
330 | |||
331 | // Compute the query geometry
|
||
332 | // 1. Check if it is within borders
|
||
333 | Envelope envelope = getFullEnvelope(); |
||
334 | Envelope vpEnv = vp.getAdjustedExtent(); |
||
335 | if (!vpEnv.intersects(envelope)) {
|
||
336 | return;
|
||
337 | } |
||
338 | |||
339 | // 2. Compute extent to be requested.
|
||
340 | Rectangle2D bBox = new Rectangle2D.Double(); |
||
341 | Rectangle2D.intersect(getRectable2DFromEnvelope(vpEnv),
|
||
342 | getRectable2DFromEnvelope(envelope), bBox); |
||
343 | |||
344 | // 3. Compute size in pixels
|
||
345 | double scalex = vp.getAffineTransform().getScaleX();
|
||
346 | double scaley = vp.getAffineTransform().getScaleY();
|
||
347 | int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1); |
||
348 | int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1); |
||
349 | |||
350 | Dimension sz = new Dimension(wImg, hImg); |
||
351 | |||
352 | if ((wImg <= 0) || (hImg <= 0)) { |
||
353 | return;
|
||
354 | } |
||
355 | |||
356 | 2241 | nbrodin | //try {
|
357 | 1944 | nbrodin | |
358 | Rectangle2D extent = new Rectangle2D.Double(); |
||
359 | Rectangle2D.Double vpExtent = this.getRectable2DFromEnvelope(vpEnv); |
||
360 | Rectangle2D.intersect(vpExtent, bBox, extent);
|
||
361 | |||
362 | Extent ex = rManager.getDataStructFactory().createExtent( |
||
363 | vp.getAdjustedEnvelope().getMinimum(0),
|
||
364 | vp.getAdjustedEnvelope().getMaximum(1),
|
||
365 | vp.getAdjustedEnvelope().getMaximum(0),
|
||
366 | vp.getAdjustedEnvelope().getMinimum(1));
|
||
367 | ViewPortData vpData = rManager.getDataStructFactory().createViewPortData(vp.getProjection(), ex, sz ); |
||
368 | vpData.setMat(vp.getAffineTransform()); |
||
369 | |||
370 | try {
|
||
371 | getParameters().setExtent(bBox); |
||
372 | if(getParameters().isSizeFixed()) {
|
||
373 | getParameters().setWidth((int)getParameters().getFixedSize().getWidth());
|
||
374 | getParameters().setHeight((int)getParameters().getFixedSize().getHeight());
|
||
375 | } else {
|
||
376 | getParameters().setWidth(wImg); |
||
377 | getParameters().setHeight(hImg); |
||
378 | } |
||
379 | |||
380 | 2317 | nbrodin | if(getDataStore().getParameters() instanceof WMSDataParameters) { |
381 | 1944 | nbrodin | getRender().draw(g, vpData, taskStatus); |
382 | } else {
|
||
383 | Envelope adjustedExtent = vp.getAdjustedExtent(); |
||
384 | Extent e = rManager.getDataStructFactory().createExtent(adjustedExtent.getLowerCorner().getX(), |
||
385 | adjustedExtent.getUpperCorner().getY(), adjustedExtent.getUpperCorner().getX(), |
||
386 | adjustedExtent.getLowerCorner().getY()); |
||
387 | ViewPortData vp2 = rManager.getDataStructFactory().createViewPortData(vp.getProjection(), e, vp.getImageSize() ); |
||
388 | vp2.setMat(vp.getAffineTransform()); |
||
389 | getParameters().setExtent(ex.toRectangle2D()); |
||
390 | getRender().drawTiledService(g, vp2, vp.getImageSize(), taskStatus); |
||
391 | } |
||
392 | //this.updateDrawVersion();
|
||
393 | 2241 | nbrodin | |
394 | } catch (ProcessInterruptedException e) {
|
||
395 | } catch (QueryException e) {
|
||
396 | 1944 | nbrodin | setAvailable(false);
|
397 | JOptionPane.showMessageDialog(null, "Problems drawing this layer:" + e.getMessage(), Messages.getText("Error"), JOptionPane.ERROR_MESSAGE); |
||
398 | logger.info("Problems drawing this layer:" + e.getMessage(), e);
|
||
399 | } finally {
|
||
400 | taskStatus.terminate(); |
||
401 | } |
||
402 | |||
403 | 2241 | nbrodin | /*} catch (RemoteServiceException e) {
|
404 | 1944 | nbrodin | if (!taskStatus.isCancellationRequested()) {
|
405 | if (callCount < MAX_RETRY_TIMES) {
|
||
406 | logger.warn("\n[ FLyrWMS.drawFixedSize() ] Failed in trying " + callCount + "/" + MAX_RETRY_TIMES + ")\n"); // mess code
|
||
407 | drawTile(g, vp, taskStatus, scale);
|
||
408 | } else {
|
||
409 | if (!isPrinting) {
|
||
410 | this.setVisible(false);
|
||
411 | }
|
||
412 | logger.error("Server error:" + e.getMessage(), e);
|
||
413 | }
|
||
414 | }
|
||
415 | 2241 | nbrodin | }*/
|
416 | 1944 | nbrodin | return;
|
417 | } |
||
418 | |||
419 | /**
|
||
420 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
||
421 | * com.iver.cit.gvsig.fmap.ViewPort,
|
||
422 | * com.iver.cit.gvsig.fmap.operations.Cancellable)
|
||
423 | */
|
||
424 | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties) |
||
425 | throws ReadException {
|
||
426 | TaskStatusManager manager = ToolsLocator.getTaskStatusManager(); |
||
427 | SimpleTaskStatus taskStatus = new RasterTaskStatus("Printing " + getName() + "...", cancel); |
||
428 | manager.add(taskStatus); |
||
429 | taskStatus.setAutoremove(true);
|
||
430 | |||
431 | if (isVisible() && isWithinScale(scale)){
|
||
432 | if (!mustTilePrint) {
|
||
433 | draw(null, g, viewPort, cancel,scale);
|
||
434 | } else {
|
||
435 | Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipBounds());
|
||
436 | tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
||
437 | for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) { |
||
438 | // Parte que dibuja
|
||
439 | try {
|
||
440 | ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
||
441 | drawTile(g, vp, taskStatus, scale); |
||
442 | } catch (NoninvertibleTransformException e) { |
||
443 | throw new ReadException(e.getMessage(), e); |
||
444 | } catch (LoadLayerException e) {
|
||
445 | throw new ReadException(e.getMessage(), e); |
||
446 | } |
||
447 | } |
||
448 | } |
||
449 | } |
||
450 | taskStatus.terminate(); |
||
451 | } |
||
452 | |||
453 | public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
||
454 | double scale) throws ReadException { |
||
455 | draw(null, g, viewPort, cancel,scale);
|
||
456 | } |
||
457 | |||
458 | public HashMap<String, Object> getProperties() { |
||
459 | HashMap<String, Object> info = new HashMap<String, Object>(); |
||
460 | String[] layerNames = getParameters().getLayerQuery().split(","); |
||
461 | Vector<WMSLayerNode> layers = new Vector<WMSLayerNode>(layerNames.length); |
||
462 | try {
|
||
463 | //explorer.connect(null);
|
||
464 | for (int i = 0; i < layerNames.length; i++) { |
||
465 | layers.add(i, explorer.getLayer(layerNames[i])); |
||
466 | } |
||
467 | info.put("name", getName());
|
||
468 | info.put("selectedLayers", layers);
|
||
469 | info.put("host", getParameters().getURI());
|
||
470 | info.put("srs", getParameters().getSRSCode());
|
||
471 | info.put("format", getParameters().getFormat());
|
||
472 | info.put("wmsTransparency", new Boolean(getParameters().isWmsTransparent())); |
||
473 | info.put("styles", getParameters().getStyles());
|
||
474 | info.put("dimensions", getParameters().getDimensions());
|
||
475 | info.put("fixedSize", getParameters().getFixedSize());
|
||
476 | return info;
|
||
477 | } /*catch (WMSException e) {
|
||
478 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(null, "connect_error"));
|
||
479 | }*/ catch (Exception e) { |
||
480 | e.printStackTrace(); |
||
481 | } |
||
482 | return null; |
||
483 | } |
||
484 | |||
485 | /**
|
||
486 | * Creates the part of a OGC's MapContext document that would describe this
|
||
487 | * layer(s).
|
||
488 | * @param version, The desired version of the resulting document. (1.1.0)
|
||
489 | * @return String containing the xml.
|
||
490 | * @throws UnsupportedVersionLayerException
|
||
491 | */
|
||
492 | 2317 | nbrodin | @SuppressWarnings({ "unchecked", "rawtypes" }) |
493 | 1944 | nbrodin | public String toMapContext(String mapContextVersion) { |
494 | XmlBuilder xml = new XmlBuilder();
|
||
495 | |||
496 | String query = getParameters().getLayerQuery();
|
||
497 | String[] layerNames = query.split(","); |
||
498 | 2317 | nbrodin | RemoteWMSStyle[] styles = (RemoteWMSStyle[]) getParameters().getStyles().toArray(new RemoteWMSStyle[0]); |
499 | 1944 | nbrodin | for (int i = 0; i < layerNames.length; i++) { |
500 | WMSLayerNode layer = explorer.getLayer(layerNames[i]); |
||
501 | HashMap xmlAttrs = new HashMap(); |
||
502 | |||
503 | // <Layer>
|
||
504 | xmlAttrs.put(WebMapContextTags.HIDDEN, !isVisible() + "");
|
||
505 | xmlAttrs.put(WebMapContextTags.QUERYABLE, explorer.isQueryable() + "");
|
||
506 | xml.openTag(WebMapContextTags.LAYER, xmlAttrs); |
||
507 | xmlAttrs.clear(); |
||
508 | if (mapContextVersion.equals("1.1.0") || mapContextVersion.equals("1.0.0")) { |
||
509 | // <Server>
|
||
510 | xmlAttrs.put(WebMapContextTags.SERVICE, WebMapContextTags.WMS); |
||
511 | xmlAttrs.put(WebMapContextTags.VERSION, explorer.getVersion()); |
||
512 | xmlAttrs.put(WebMapContextTags.SERVER_TITLE, explorer.getServiceTitle()); |
||
513 | xml.openTag(WebMapContextTags.SERVER, xmlAttrs); |
||
514 | xmlAttrs.clear(); |
||
515 | |||
516 | // <OnlineResource>
|
||
517 | xmlAttrs.put(WebMapContextTags.XLINK_TYPE, "simple");
|
||
518 | xmlAttrs.put(WebMapContextTags.XLINK_HREF, getParameters().getURI().toString()); |
||
519 | xml.writeTag(WebMapContextTags.ONLINE_RESOURCE, xmlAttrs); |
||
520 | xmlAttrs.clear(); |
||
521 | // </OnlineResource>
|
||
522 | |||
523 | xml.closeTag(); |
||
524 | // </Server>
|
||
525 | |||
526 | // <Name>
|
||
527 | xml.writeTag(WebMapContextTags.NAME, layer.getName().trim()); |
||
528 | // </Name>
|
||
529 | |||
530 | // <Title>
|
||
531 | xml.writeTag(WebMapContextTags.TITLE, layer.getTitle().trim()); |
||
532 | //?xml.writeTag(WebMapContextTags.TITLE, getName().trim());
|
||
533 | // </Title>
|
||
534 | |||
535 | // <Abstract>
|
||
536 | if (layer.getAbstract() != null) { |
||
537 | xml.writeTag(WebMapContextTags.ABSTRACT, layer.getAbstract()); |
||
538 | // </Abstract>
|
||
539 | } |
||
540 | |||
541 | // <SRS> (a list of available SRS for the enclosing layer)
|
||
542 | String[] strings = (String[]) layer.getAllSrs().toArray(new String[0]); |
||
543 | String mySRS = strings[0]; |
||
544 | for (int j = 1; j < strings.length; j++) { |
||
545 | mySRS += ","+strings[j];
|
||
546 | } |
||
547 | xml.writeTag(WebMapContextTags.SRS, mySRS); |
||
548 | // </SRS>
|
||
549 | |||
550 | // <FormatList>
|
||
551 | xml.openTag(WebMapContextTags.FORMAT_LIST); |
||
552 | strings = explorer.getFormats(); |
||
553 | for (int j = 0; j < strings.length; j++) { |
||
554 | // <Format>
|
||
555 | String str = strings[j].trim();
|
||
556 | if (str.equals(getParameters().getFormat())) {
|
||
557 | xml.writeTag(WebMapContextTags.FORMAT, str, WebMapContextTags.CURRENT, "1");
|
||
558 | } else {
|
||
559 | xml.writeTag(WebMapContextTags.FORMAT, str); |
||
560 | // </Format>
|
||
561 | } |
||
562 | } |
||
563 | xml.closeTag(); |
||
564 | // </FormatList>
|
||
565 | |||
566 | // <StyleList>
|
||
567 | xml.openTag(WebMapContextTags.STYLE_LIST); |
||
568 | |||
569 | if (layer.getStyles().size() > 0) { |
||
570 | for (int j = 0; j < layer.getStyles().size(); j++) { |
||
571 | // <Style>
|
||
572 | RemoteWMSStyle st = layer.getStyles().get(j); |
||
573 | 2317 | nbrodin | if (st.getName().equals(styles[i].getName())) {
|
574 | 1944 | nbrodin | xmlAttrs.put(WebMapContextTags.CURRENT, "1");
|
575 | } |
||
576 | xml.openTag(WebMapContextTags.STYLE, xmlAttrs); |
||
577 | xmlAttrs.clear(); |
||
578 | |||
579 | // <Name>
|
||
580 | xml.writeTag(WebMapContextTags.NAME, st.getName()); |
||
581 | // </Name>
|
||
582 | |||
583 | // <Title>
|
||
584 | xml.writeTag(WebMapContextTags.TITLE, st.getTitle()); |
||
585 | // </Title>
|
||
586 | |||
587 | // <LegendURL width="180" format="image/gif" height="50">
|
||
588 | // <OnlineResource xlink:type="simple" xlink:href="http://globe.digitalearth.gov/globe/en/icons/colorbars/NATIONAL.gif"/>
|
||
589 | // </OnlineResource>
|
||
590 | // </LegendURL>
|
||
591 | xml.closeTag(); |
||
592 | // </Style>
|
||
593 | |||
594 | } |
||
595 | |||
596 | } else {
|
||
597 | // Create fake style (for compatibility issues)
|
||
598 | xmlAttrs.put(WebMapContextTags.CURRENT, "1");
|
||
599 | // <Style>
|
||
600 | xml.openTag(WebMapContextTags.STYLE, xmlAttrs); |
||
601 | xmlAttrs.clear(); |
||
602 | // <Name>
|
||
603 | xml.writeTag(WebMapContextTags.NAME, "default");
|
||
604 | // </Name>
|
||
605 | |||
606 | // <Title>
|
||
607 | xml.writeTag(WebMapContextTags.TITLE, "default");
|
||
608 | xml.closeTag(); |
||
609 | } |
||
610 | // </StyleList>
|
||
611 | xml.closeTag(); |
||
612 | if (mapContextVersion.compareTo("1.0.0") > 0) { |
||
613 | // <DimensionList>
|
||
614 | xml.openTag(WebMapContextTags.DIMENSION_LIST); |
||
615 | // <Dimension>
|
||
616 | // </Dimension>
|
||
617 | xml.closeTag(); |
||
618 | // </DimensionList>
|
||
619 | } |
||
620 | } else {
|
||
621 | xml.writeTag("ERROR", PluginServices.getText(this, "unsupported_map_context_version")); |
||
622 | } |
||
623 | // </Layer>
|
||
624 | xml.closeTag(); |
||
625 | } |
||
626 | return xml.getXML();
|
||
627 | } |
||
628 | |||
629 | public String getTocImageIcon() { |
||
630 | return "icon-layer-wms"; |
||
631 | } |
||
632 | |||
633 | public int[] getTileSize() { |
||
634 | int[] size = {maxTileDrawWidth, maxTileDrawHeight}; |
||
635 | return size;
|
||
636 | } |
||
637 | |||
638 | public boolean isTiled() { |
||
639 | return mustTileDraw;
|
||
640 | } |
||
641 | |||
642 | public ComposedLayer newComposedLayer() {
|
||
643 | Preferences prefs = Preferences.userRoot().node("gvsig.wms"); |
||
644 | |||
645 | /*
|
||
646 | * from java.util.prefs import Preferences
|
||
647 | * prefs = Preferences.userRoot().node("gvsig.wms")
|
||
648 | * prefs.put("useComposedLayer","true")
|
||
649 | */
|
||
650 | |||
651 | String str = prefs.get("useComposedLayer","false"); |
||
652 | Boolean useComposedLayer = Boolean.TRUE; // por defecto ya se usan |
||
653 | try {
|
||
654 | useComposedLayer = Boolean.valueOf(str);
|
||
655 | } catch (Exception e) { |
||
656 | |||
657 | } |
||
658 | if (useComposedLayer.booleanValue()) {
|
||
659 | return new ComposedLayerWMS(); |
||
660 | } else {
|
||
661 | return null; |
||
662 | } |
||
663 | } |
||
664 | |||
665 | /*
|
||
666 | * Checks if can make a single petition for the two layers to the server
|
||
667 | * @see com.iver.cit.gvsig.fmap.layers.ComposedLayerWMS#canAdd(com.iver.cit.gvsig.fmap.layers.FLayer)
|
||
668 | */
|
||
669 | boolean isComposedLayerCompatible(FLayer layer) {
|
||
670 | FLyrWMS aLayer; |
||
671 | |||
672 | if (!(layer instanceof FLyrWMS)) { |
||
673 | return false; |
||
674 | } |
||
675 | aLayer = (FLyrWMS)layer; |
||
676 | if (!getParameters().getURI().equals(aLayer.getParameters().getURI())) {
|
||
677 | return false; |
||
678 | } |
||
679 | |||
680 | 2317 | nbrodin | WMSDataParameters p = getWMSParameters(getDataStore().getParameters()); |
681 | |||
682 | 1944 | nbrodin | if (!p.getFormat().equals(aLayer.getParameters().getFormat())) {
|
683 | return false; |
||
684 | } |
||
685 | if (!p.getSRS().equals(aLayer.getParameters().getSRS())) {
|
||
686 | return false; |
||
687 | } |
||
688 | if (p.getInfoLayerQuery() != null) { |
||
689 | if (!p.getInfoLayerQuery().equals(aLayer.getParameters().getInfoLayerQuery())) {
|
||
690 | return false; |
||
691 | } |
||
692 | }else if (p.getInfoLayerQuery() != null) { |
||
693 | return false; |
||
694 | } |
||
695 | |||
696 | |||
697 | // isFixedSize es privado
|
||
698 | if ((getParameters().getFixedSize() != null) && |
||
699 | (aLayer.getParameters().getFixedSize() != null)) {
|
||
700 | if (getParameters().getFixedSize().equals(aLayer.getParameters().getFixedSize())) {
|
||
701 | return false; |
||
702 | } |
||
703 | } else if ((getParameters().getFixedSize() != null) != (aLayer.getParameters().getFixedSize() != null)) { |
||
704 | return false; |
||
705 | } |
||
706 | |||
707 | // time elevation (dimensions)
|
||
708 | if ((p.getDimensions() != null) && |
||
709 | (aLayer.getParameters().getDimensions() != null)) {
|
||
710 | if (p.getDimensions().size() != aLayer.getParameters().getDimensions().size()) {
|
||
711 | return false; |
||
712 | } else {
|
||
713 | Iterator<String> iter = p.getDimensions().iterator(); |
||
714 | while (iter.hasNext()) {
|
||
715 | if (!aLayer.getParameters().getDimensions().contains(iter.next())) {
|
||
716 | return false; |
||
717 | } |
||
718 | } |
||
719 | } |
||
720 | |||
721 | } else if ((p.getDimensions() != null) != (aLayer.getParameters().getDimensions() != null)) { |
||
722 | return false; |
||
723 | } |
||
724 | |||
725 | return true; |
||
726 | } |
||
727 | |||
728 | public boolean isActionEnabled(int action) { |
||
729 | switch (action) {
|
||
730 | case IRasterLayerActions.ZOOM_PIXEL_RESOLUTION:
|
||
731 | case IRasterLayerActions.FLYRASTER_BAR_TOOLS:
|
||
732 | case IRasterLayerActions.BANDS_FILE_LIST:
|
||
733 | case IRasterLayerActions.COLOR_TABLE:
|
||
734 | case IRasterLayerActions.GEOLOCATION:
|
||
735 | case IRasterLayerActions.PANSHARPENING:
|
||
736 | case IRasterLayerActions.SAVE_COLORINTERP:
|
||
737 | case IRasterLayerActions.SAVEAS:
|
||
738 | case IRasterLayerActions.BANDS_RGB:
|
||
739 | case IRasterLayerActions.ENHANCED:
|
||
740 | case IRasterLayerActions.STATS:
|
||
741 | case IRasterLayerActions.NODATA:
|
||
742 | return false; |
||
743 | case IRasterLayerActions.REMOTE_ACTIONS:
|
||
744 | return true; |
||
745 | } |
||
746 | |||
747 | return super.isActionEnabled(action); |
||
748 | } |
||
749 | |||
750 | public ILegend getLegend() {
|
||
751 | 1979 | nbrodin | if(getDataStore() != null) |
752 | return new ImageLegend(getDataStore().getImageLegend()); |
||
753 | return null; |
||
754 | 1944 | nbrodin | } |
755 | |||
756 | public boolean isRemote() { |
||
757 | return true; |
||
758 | } |
||
759 | |||
760 | public boolean overviewsSupport() { |
||
761 | return false; |
||
762 | } |
||
763 | |||
764 | protected void updateDrawVersion() { |
||
765 | if (this.disableUpdateDrawVersion != null){ |
||
766 | |||
767 | Thread curThread = Thread.currentThread(); |
||
768 | |||
769 | Thread aThread;
|
||
770 | |||
771 | Iterator<WeakReference<Thread>> iter = this.disableUpdateDrawVersion.iterator(); |
||
772 | while (iter.hasNext()){
|
||
773 | aThread = (Thread) ((WeakReference<?>)iter.next()).get(); |
||
774 | if (aThread == null){ |
||
775 | iter.remove(); |
||
776 | } else if(aThread.equals(curThread)){ |
||
777 | return;
|
||
778 | } |
||
779 | } |
||
780 | } |
||
781 | // Exception ex = new Exception();
|
||
782 | // ex.printStackTrace();
|
||
783 | super.updateDrawVersion();
|
||
784 | } |
||
785 | |||
786 | protected void disableUpdateDrawVersion() { |
||
787 | if (this.disableUpdateDrawVersion == null) { |
||
788 | this.disableUpdateDrawVersion = new ArrayList<WeakReference<Thread>>(); |
||
789 | } |
||
790 | this.disableUpdateDrawVersion.add(new WeakReference<Thread>(Thread.currentThread())); |
||
791 | } |
||
792 | |||
793 | protected void enableUpdateDrawVersion() { |
||
794 | if (this.disableUpdateDrawVersion == null){ |
||
795 | return;
|
||
796 | } |
||
797 | Thread curThread = Thread.currentThread(); |
||
798 | Thread aThread;
|
||
799 | |||
800 | Iterator<WeakReference<Thread>> iter = this.disableUpdateDrawVersion.iterator(); |
||
801 | while (iter.hasNext()) {
|
||
802 | aThread = (Thread) ((WeakReference<?>)iter.next()).get(); |
||
803 | if (aThread == null) { |
||
804 | iter.remove(); |
||
805 | } else if(aThread.equals(curThread)) { |
||
806 | iter.remove(); |
||
807 | break;
|
||
808 | } |
||
809 | } |
||
810 | |||
811 | } |
||
812 | |||
813 | private Rectangle2D.Double getRectable2DFromEnvelope(Envelope env) { |
||
814 | return new Rectangle2D.Double(env.getMinimum(0), env.getMinimum(1), env |
||
815 | .getLength(0), env.getLength(1)); |
||
816 | } |
||
817 | |||
818 | 2317 | nbrodin | /*private Envelope getEnvelopeFromRectable2D(Rectangle2D rect) {
|
819 | 1944 | nbrodin | try {
|
820 | return geomManager.createEnvelope(rect.getMinX(), rect.getMinY(),
|
||
821 | rect.getMaxX(), rect.getMaxY(),
|
||
822 | SUBTYPES.GEOM2D);
|
||
823 | } catch (CreateEnvelopeException e) {
|
||
824 | logger.error("Error creating the envelope", e);
|
||
825 | }
|
||
826 | return null;
|
||
827 | 2317 | nbrodin | }*/
|
828 | 1944 | nbrodin | |
829 | @Override
|
||
830 | public String getFileFormat() { |
||
831 | return "WMS"; |
||
832 | } |
||
833 | |||
834 | @Override
|
||
835 | public FLayer getFileLayer() throws RasterDriverException { |
||
836 | /*if(getDataStore() instanceof DefaultRemoteRasterStore) {
|
||
837 | RemoteRasterProvider prov = (RemoteRasterProvider)((DefaultRemoteRasterStore)getDataStore()).getProvider(0);
|
||
838 | File file = null;
|
||
839 | |||
840 | if(getParameters().isSizeFixed()) {
|
||
841 | file = prov.getFileLayer();
|
||
842 | } else {
|
||
843 | file = prov.getLastRequest();
|
||
844 | }
|
||
845 | |||
846 | if(file == null)
|
||
847 | return null;
|
||
848 | |||
849 | try {
|
||
850 | return DefaultFLyrRaster.createLayer("tmp", file);
|
||
851 | } catch (LoadLayerException e) {
|
||
852 | throw new RasterDriverException(e.getMessage(), e);
|
||
853 | }
|
||
854 | }*/
|
||
855 | return null; |
||
856 | } |
||
857 | |||
858 | /**
|
||
859 | * Devuelve el envelope en la proyeccion de la vista
|
||
860 | */
|
||
861 | public Envelope getFullEnvelope() {
|
||
862 | 2317 | nbrodin | Extent e1 = getDataStore().getExtent(); |
863 | Envelope rAux = null;
|
||
864 | try {
|
||
865 | rAux = geomManager.createEnvelope(e1.getMin().getX(), e1.getMin().getY(), e1.getMax().getX(), e1.getMax().getY(), SUBTYPES.GEOM2D); |
||
866 | } catch (CreateEnvelopeException exc) {
|
||
867 | logger.error("Error creating the envelope", exc);
|
||
868 | } |
||
869 | 1944 | nbrodin | |
870 | // Esto es para cuando se crea una capa nueva con el fullExtent de ancho
|
||
871 | // y alto 0.
|
||
872 | if (rAux == null || rAux.getMaximum(0) - rAux.getMinimum(0) == 0 |
||
873 | && rAux.getMaximum(1) - rAux.getMinimum(1) == 0) { |
||
874 | try {
|
||
875 | rAux = geomManager.createEnvelope(0, 0, 100, 100, SUBTYPES.GEOM2D); |
||
876 | } catch (CreateEnvelopeException e) {
|
||
877 | logger.error("Error creating the envelope", e);
|
||
878 | } |
||
879 | } |
||
880 | // Si existe reproyecci?n, reproyectar el extent
|
||
881 | ICoordTrans ct = getCoordTrans(); |
||
882 | if (ct != null) { |
||
883 | Point2D pt1 = new Point2D.Double(rAux.getMinimum(0), rAux |
||
884 | .getMinimum(1));
|
||
885 | Point2D pt2 = new Point2D.Double(rAux.getMaximum(0), rAux |
||
886 | .getMaximum(1));
|
||
887 | pt1 = ct.convert(pt1, null);
|
||
888 | pt2 = ct.convert(pt2, null);
|
||
889 | try {
|
||
890 | rAux = geomManager.createEnvelope(pt1.getX(), pt1.getY(), pt2 |
||
891 | .getX(), pt2.getY(), SUBTYPES.GEOM2D); |
||
892 | } catch (CreateEnvelopeException e) {
|
||
893 | logger.error("Error creating the envelope", e);
|
||
894 | }// new
|
||
895 | // Rectangle2D.Double();
|
||
896 | } |
||
897 | return rAux;
|
||
898 | |||
899 | } |
||
900 | |||
901 | public Extent getFullRasterExtent() {
|
||
902 | return getExtentFromEnvelope(getFullEnvelope());
|
||
903 | } |
||
904 | |||
905 | public DynObjectSet getInfo(org.gvsig.fmap.geom.primitive.Point p, double tolerance) throws LoadLayerException, DataException { |
||
906 | Point p1 = new Point((int)p.getX(), (int)p.getY()); |
||
907 | return getInfo(p1, tolerance, null, false); |
||
908 | } |
||
909 | |||
910 | @Override
|
||
911 | public DynObjectSet getInfo(Point p, double tolerance, Cancellable cancel, |
||
912 | boolean fast) throws LoadLayerException, DataException { |
||
913 | |||
914 | //try {
|
||
915 | ViewPort viewPort = getMapContext().getViewPort(); |
||
916 | |||
917 | getParameters().setExtent(this.getRectable2DFromEnvelope(viewPort.getAdjustedEnvelope()));
|
||
918 | if(getParameters().isSizeFixed()) {
|
||
919 | getParameters().setWidth((int)getParameters().getFixedSize().getWidth());
|
||
920 | getParameters().setHeight((int)getParameters().getFixedSize().getHeight());
|
||
921 | } else {
|
||
922 | getParameters().setWidth(viewPort.getImageWidth()); |
||
923 | getParameters().setHeight(viewPort.getImageHeight()); |
||
924 | } |
||
925 | |||
926 | CancelTaskImpl cancellable = new CancelTaskImpl(cancel);
|
||
927 | getParameters().setCancellable(cancellable); |
||
928 | |||
929 | String fInfo;
|
||
930 | try {
|
||
931 | //Point2D pt = new Point2D.Double();
|
||
932 | //try {
|
||
933 | //viewPort.getAffineTransform().transform(p, pt);
|
||
934 | /*} catch (NoninvertibleTransformException e) {
|
||
935 | return null;
|
||
936 | }*/
|
||
937 | |||
938 | Extent bbox = getExtentFromEnvelope(viewPort.getAdjustedEnvelope()); |
||
939 | fInfo = getDataStore().getInfoByPoint(p.getX(), |
||
940 | p.getY(), |
||
941 | bbox, |
||
942 | viewPort.getImageWidth(), |
||
943 | viewPort.getImageHeight(), |
||
944 | cancellable); |
||
945 | } catch (InfoByPointException e) {
|
||
946 | throw new LoadLayerException("Error in getInfoByPoint", e); |
||
947 | } |
||
948 | return new DynObjectSetWMSInfo(fInfo, getParameters().getInfoFormat()); |
||
949 | } |
||
950 | |||
951 | private Extent getExtentFromEnvelope(Envelope env) {
|
||
952 | double minx = env.getMinimum(0); |
||
953 | double miny = env.getMinimum(1); |
||
954 | double maxx = env.getMaximum(0); |
||
955 | double maxy = env.getMaximum(1); |
||
956 | Point2D ul = new Point2D.Double(minx, maxy); |
||
957 | Point2D ur = new Point2D.Double(maxx, maxy); |
||
958 | Point2D ll = new Point2D.Double(minx, miny); |
||
959 | Point2D lr = new Point2D.Double(maxx, miny); |
||
960 | return rManager.getDataStructFactory().createExtent(ul, lr, ur, ll);
|
||
961 | } |
||
962 | |||
963 | /**
|
||
964 | * Sets the data store parameters
|
||
965 | * @param params
|
||
966 | * @throws InitializeException
|
||
967 | */
|
||
968 | public void setParameters(DataStoreParameters params) throws InitializeException { |
||
969 | if(params instanceof TileDataParameters) { |
||
970 | ((TileDataParameters)params).deleteCache(deleteCache); |
||
971 | } |
||
972 | |||
973 | DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
||
974 | try {
|
||
975 | DataStore dStore = dataman.openStore(params.getDataStoreName(), params); |
||
976 | this.setDataStore(dStore);
|
||
977 | |||
978 | if(params instanceof WMSDataParameters) { |
||
979 | this.setName(((WMSDataParameters)params).getURI());
|
||
980 | } |
||
981 | |||
982 | if(params instanceof TileDataParameters) { |
||
983 | DataParameters p = ((TileDataParameters) params).getDataParameters(); |
||
984 | if(p instanceof WMSDataParameters) { |
||
985 | this.setName(((WMSDataParameters) p).getURI());
|
||
986 | } |
||
987 | } |
||
988 | } catch (ValidateDataParametersException e) {
|
||
989 | throw new InitializeException(e); |
||
990 | } catch (ProviderNotRegisteredException e) {
|
||
991 | throw new InitializeException(e); |
||
992 | } catch (LoadLayerException e) {
|
||
993 | throw new InitializeException(e); |
||
994 | } |
||
995 | } |
||
996 | |||
997 | public WMSDataParameters getParameters() {
|
||
998 | 2317 | nbrodin | return getWMSParameters(getDataStore().getParameters());
|
999 | 1944 | nbrodin | } |
1000 | |||
1001 | /**
|
||
1002 | * Gets <code>WMSDataParameters</code>
|
||
1003 | * @param parameters
|
||
1004 | * @return
|
||
1005 | */
|
||
1006 | private WMSDataParameters getWMSParameters(DataStoreParameters parameters) {
|
||
1007 | WMSDataParameters params = null;
|
||
1008 | if(parameters instanceof WMSDataParameters) { |
||
1009 | params = (WMSDataParameters) parameters; |
||
1010 | } |
||
1011 | |||
1012 | if(parameters instanceof TileDataParameters) { |
||
1013 | DataParameters p = ((TileDataParameters) parameters).getDataParameters(); |
||
1014 | if(p instanceof WMSDataParameters) { |
||
1015 | params = (WMSDataParameters) p; |
||
1016 | } |
||
1017 | } |
||
1018 | return params;
|
||
1019 | } |
||
1020 | |||
1021 | /**
|
||
1022 | * Assigns the flag to delete this layer from the cache
|
||
1023 | * @param selected
|
||
1024 | */
|
||
1025 | public void deleteCache(boolean deleteCache) { |
||
1026 | this.deleteCache = deleteCache;
|
||
1027 | } |
||
1028 | |||
1029 | /**
|
||
1030 | * Sets the explorer
|
||
1031 | * @param explorer
|
||
1032 | */
|
||
1033 | public void setExplorer(WMSServerExplorer explorer) { |
||
1034 | this.explorer = explorer;
|
||
1035 | } |
||
1036 | |||
1037 | /**
|
||
1038 | * Gets the explorer
|
||
1039 | * @return
|
||
1040 | */
|
||
1041 | public WMSServerExplorer getExplorer() {
|
||
1042 | return this.explorer; |
||
1043 | } |
||
1044 | |||
1045 | public FLayer cloneLayer() throws Exception { |
||
1046 | RasterDataStore ds = dataStore.cloneDataStore(); |
||
1047 | FLyrWMS newLayer = new FLyrWMS();
|
||
1048 | newLayer.setName(getName()); |
||
1049 | newLayer.setOpenRasterStore(ds); |
||
1050 | //newLayer.firstLoad = firstLoad;
|
||
1051 | newLayer.explorer = explorer; |
||
1052 | |||
1053 | List<RasterFilter> filters = getRender().getFilterList().getStatusCloned();
|
||
1054 | |||
1055 | //Hacemos una copia de las bandas a renderizar
|
||
1056 | 2312 | nbrodin | ColorInterpretation ci = getRender().getRenderColorInterpretation(); |
1057 | if(ci != null) { |
||
1058 | newLayer.getRender().setRenderColorInterpretation(ci.cloneColorInterpretation()); |
||
1059 | 1944 | nbrodin | } |
1060 | |||
1061 | //Asignamos el entorno
|
||
1062 | if(newLayer.getRender().getFilterList() == null) |
||
1063 | newLayer.getRender().setFilterList(RasterLocator.getManager().createEmptyFilterList(getRender().getFilterList().getInitDataType())); |
||
1064 | newLayer.getRender().getFilterList().setEnv(getRender().getFilterList().getEnv()); |
||
1065 | newLayer.getRender().getFilterList().setStatus(filters); |
||
1066 | |||
1067 | // Asignamos los valores noData del original
|
||
1068 | newLayer.setNoDataValue(getNoDataValue()); |
||
1069 | if(dataStore.getNoDataValue().isDefined())
|
||
1070 | newLayer.setNoDataTransparent(true);
|
||
1071 | newLayer.enableOpen(); |
||
1072 | |||
1073 | return newLayer;
|
||
1074 | } |
||
1075 | |||
1076 | |||
1077 | } |