svn-gvsig-desktop / tags / v1_1_Build_1003 / extensions / extWMS / src / com / iver / cit / gvsig / fmap / layers / FLyrWMS.java @ 12271
History | View | Annotate | Download (58.8 KB)
1 | 4503 | jaume | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | 3746 | jaume | *
|
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | 4503 | jaume | * Av. Blasco Ib??ez, 50
|
24 | 3746 | jaume | * 46010 VALENCIA
|
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | package com.iver.cit.gvsig.fmap.layers; |
||
42 | |||
43 | import java.awt.Component; |
||
44 | 3841 | nacho | import java.awt.Dimension; |
45 | 3746 | jaume | import java.awt.Graphics2D; |
46 | 8765 | jjdelcerro | import java.awt.Image; |
47 | 3746 | jaume | import java.awt.Point; |
48 | 3840 | nacho | import java.awt.Rectangle; |
49 | 3746 | jaume | import java.awt.geom.AffineTransform; |
50 | import java.awt.geom.NoninvertibleTransformException; |
||
51 | import java.awt.geom.Point2D; |
||
52 | import java.awt.geom.Rectangle2D; |
||
53 | import java.awt.image.BufferedImage; |
||
54 | 4378 | nacho | import java.awt.image.DataBuffer; |
55 | 3746 | jaume | import java.io.File; |
56 | import java.io.IOException; |
||
57 | import java.lang.reflect.Constructor; |
||
58 | import java.lang.reflect.InvocationTargetException; |
||
59 | import java.net.MalformedURLException; |
||
60 | import java.net.URL; |
||
61 | import java.util.ArrayList; |
||
62 | import java.util.HashMap; |
||
63 | 3841 | nacho | import java.util.Hashtable; |
64 | 4222 | jaume | import java.util.Iterator; |
65 | 4677 | jorpiell | import java.util.Map; |
66 | 3746 | jaume | import java.util.Vector; |
67 | 11031 | jmvivo | import java.util.prefs.Preferences; |
68 | 3746 | jaume | |
69 | 9013 | caballero | import javax.print.attribute.PrintRequestAttributeSet; |
70 | 5763 | jmvivo | import javax.swing.ImageIcon; |
71 | 3746 | jaume | import javax.swing.JOptionPane; |
72 | |||
73 | 5981 | nacho | import org.cresques.filter.RasterFilterStack; |
74 | import org.cresques.filter.RasterFilterStackManager; |
||
75 | 3746 | jaume | import org.cresques.geo.ViewPortData; |
76 | 5991 | nacho | import org.cresques.io.GdalFile; |
77 | 3746 | jaume | import org.cresques.io.GeoRasterFile; |
78 | 9056 | nacho | import org.cresques.io.data.Grid; |
79 | import org.cresques.io.exceptions.NotSupportedExtensionException; |
||
80 | 3746 | jaume | import org.cresques.px.Extent; |
81 | import org.cresques.px.PxRaster; |
||
82 | import org.exolab.castor.xml.ValidationException; |
||
83 | import org.gvsig.remoteClient.utils.Utilities; |
||
84 | 5409 | jaume | import org.gvsig.remoteClient.wms.ICancellable; |
85 | 3746 | jaume | import org.gvsig.remoteClient.wms.WMSStatus; |
86 | |||
87 | import com.iver.andami.PluginServices; |
||
88 | 4222 | jaume | import com.iver.andami.messages.NotificationManager; |
89 | 8765 | jjdelcerro | import com.iver.cit.gvsig.fmap.ConnectionErrorExceptionType; |
90 | 3746 | jaume | import com.iver.cit.gvsig.fmap.DriverException; |
91 | 8765 | jjdelcerro | import com.iver.cit.gvsig.fmap.UnknownResponseFormatExceptionType; |
92 | import com.iver.cit.gvsig.fmap.UnsuportedProtocolVersionExceptionType; |
||
93 | 3746 | jaume | import com.iver.cit.gvsig.fmap.ViewPort; |
94 | 8765 | jjdelcerro | import com.iver.cit.gvsig.fmap.WMSDriverExceptionType; |
95 | 3746 | jaume | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
96 | import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException; |
||
97 | import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriver; |
||
98 | 5279 | jmvivo | import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriverFactory; |
99 | 5409 | jaume | import com.iver.cit.gvsig.fmap.drivers.wms.WMSException; |
100 | 4730 | jaume | import com.iver.cit.gvsig.fmap.layers.WMSLayerNode.FMapWMSStyle; |
101 | 11031 | jmvivo | import com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer; |
102 | 8765 | jjdelcerro | import com.iver.cit.gvsig.fmap.layers.layerOperations.IHasImageLegend; |
103 | 3746 | jaume | import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
104 | 5055 | ldiaz | import com.iver.cit.gvsig.fmap.layers.layerOperations.StringXMLItem; |
105 | 5203 | ldiaz | import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
106 | 4730 | jaume | import com.iver.cit.gvsig.fmap.rendering.XmlBuilder; |
107 | 5023 | jaume | import com.iver.cit.gvsig.wmc.WebMapContextTags; |
108 | 3746 | jaume | import com.iver.utiles.StringUtilities; |
109 | import com.iver.utiles.XMLEntity; |
||
110 | 5347 | jaume | import com.iver.utiles.swing.threads.Cancellable; |
111 | 3746 | jaume | |
112 | |||
113 | 5203 | ldiaz | |
114 | 3746 | jaume | /**
|
115 | 4222 | jaume | * FMap's WMS Layer class.
|
116 | 3746 | jaume | *
|
117 | 3749 | jaume | * @author Jaume Dominguez Faus
|
118 | 8765 | jjdelcerro | * Nacho Brodin
|
119 | 6050 | jaume | *
|
120 | 3746 | jaume | */
|
121 | 8765 | jjdelcerro | public class FLyrWMS extends FLyrDefault implements InfoByPoint, RasterOperations, IHasImageLegend { |
122 | 4222 | jaume | private boolean isPrinting = false; |
123 | 5534 | nacho | private boolean mustTileDraw = true; |
124 | 4222 | jaume | private boolean mustTilePrint = true; |
125 | 5534 | nacho | private final int maxTileDrawWidth = 1023; |
126 | private final int maxTileDrawHeight = 1023; |
||
127 | private final int maxTilePrintWidth = 1023; |
||
128 | private final int maxTilePrintHeight = 1023; |
||
129 | 6822 | jaume | private final int minTilePrintWidth = 12; |
130 | private final int minTilePrintHeight = 12; |
||
131 | 6050 | jaume | |
132 | 4222 | jaume | public URL host; |
133 | public String m_Format; |
||
134 | 6050 | jaume | |
135 | 4222 | jaume | private String m_SRS; |
136 | private String layerQuery; |
||
137 | private String infoLayerQuery; |
||
138 | private FMapWMSDriver wms;
|
||
139 | private WMSStatus wmsStatus = new WMSStatus(); |
||
140 | private Rectangle2D fullExtent; |
||
141 | private boolean wmsTransparency; |
||
142 | private Vector styles; |
||
143 | private Vector dimensions; |
||
144 | 3746 | jaume | private StatusRasterInterface status = null; |
145 | private int posX = 0, posY = 0; |
||
146 | private double posXWC = 0, posYWC = 0; |
||
147 | private int r = 0, g = 0, b = 0; |
||
148 | private GeoRasterFile rasterFile = null; |
||
149 | private PxRaster raster = null; |
||
150 | private RasterFilterStack filterStack = null; |
||
151 | 3756 | jaume | private boolean firstLoad = false; |
152 | 3746 | jaume | private int transparency = -1; |
153 | private int rband = 0, gband = 1, bband = 2; |
||
154 | private RasterFilterStackManager stackManager = null; |
||
155 | 4222 | jaume | private Hashtable onlineResources = new Hashtable(); |
156 | private Dimension fixedSize; |
||
157 | private boolean queryable = true; |
||
158 | private VisualStatusWMS visualStatus = new VisualStatusWMS(); |
||
159 | 9056 | nacho | private Grid grid = null; |
160 | 6050 | jaume | |
161 | |||
162 | 5409 | jaume | private class MyCancellable implements ICancellable |
163 | { |
||
164 | private Cancellable original;
|
||
165 | public MyCancellable(Cancellable cancelOriginal)
|
||
166 | { |
||
167 | this.original = cancelOriginal;
|
||
168 | } |
||
169 | public boolean isCanceled() { |
||
170 | 8765 | jjdelcerro | if (original == null) return false; |
171 | 5409 | jaume | return original.isCanceled();
|
172 | } |
||
173 | 6050 | jaume | |
174 | 5409 | jaume | } |
175 | 6050 | jaume | |
176 | 4677 | jorpiell | public FLyrWMS(){
|
177 | super();
|
||
178 | } |
||
179 | 6050 | jaume | |
180 | 4677 | jorpiell | public FLyrWMS(Map args) throws DriverIOException{ |
181 | FMapWMSDriver drv = null;
|
||
182 | String host = (String)args.get("host"); |
||
183 | String sLayer = (String)args.get("layer"); |
||
184 | Rectangle2D fullExtent = (Rectangle2D)args.get("FullExtent"); |
||
185 | String sSRS = (String)args.get("SRS"); |
||
186 | String sFormat = (String)args.get("Format"); |
||
187 | String[] sLayers = sLayer.split(","); |
||
188 | 6050 | jaume | |
189 | 4677 | jorpiell | try {
|
190 | this.setHost(new URL(host)); |
||
191 | } catch (MalformedURLException e) { |
||
192 | //e.printStackTrace();
|
||
193 | 6050 | jaume | throw new DriverIOException("Malformed host URL, '" + host + "' (" + e.toString() + ")."); |
194 | 4677 | jorpiell | } |
195 | try {
|
||
196 | 10705 | jaume | drv = this.getDriver();
|
197 | 4677 | jorpiell | } catch (Exception e) { |
198 | // e.printStackTrace();
|
||
199 | 6050 | jaume | throw new DriverIOException("Can't get driver to host '" + host + "' (" + e.toString() + ")."); |
200 | 4677 | jorpiell | } |
201 | if( sFormat == null || sSRS == null || fullExtent == null ) { |
||
202 | 5409 | jaume | if (!drv.connect(null)) |
203 | 6050 | jaume | throw new DriverIOException("Can't connect to host '" + host + "'."); |
204 | |||
205 | 4677 | jorpiell | WMSLayerNode wmsNode = drv.getLayer(sLayer); |
206 | 10705 | jaume | |
207 | 4677 | jorpiell | if (wmsNode == null){ |
208 | throw new DriverIOException("The server '" + host + "' doesn't has the layer '" + sLayer + "'."); |
||
209 | 6050 | jaume | } |
210 | 4677 | jorpiell | if( sFormat == null ) { |
211 | sFormat = this.getGreatFormat(drv.getFormats());
|
||
212 | } |
||
213 | 10705 | jaume | |
214 | 10208 | jorpiell | //SRS
|
215 | Vector allSrs = wmsNode.getAllSrs();
|
||
216 | boolean isSRSSupported = false; |
||
217 | if( sSRS != null ) { |
||
218 | for (int i=0; i<allSrs.size() ; i++){ |
||
219 | if (((String)allSrs.get(i)).compareTo(sSRS) == 0){ |
||
220 | isSRSSupported = true;
|
||
221 | 10705 | jaume | } |
222 | 10208 | jorpiell | } |
223 | } |
||
224 | 10705 | jaume | |
225 | 10208 | jorpiell | if(!isSRSSupported) {
|
226 | 9536 | jcampos | for (int i=0; i<allSrs.size() ; i++){ |
227 | if (((String)wmsNode.getAllSrs().get(i)).compareTo("EPSG:4326") == 0){ |
||
228 | sSRS = (String)wmsNode.getAllSrs().get(i);
|
||
229 | 10705 | jaume | } |
230 | 9536 | jcampos | } |
231 | if (sSRS==null){ |
||
232 | sSRS = (String)wmsNode.getAllSrs().get(0); |
||
233 | } |
||
234 | 4677 | jorpiell | } |
235 | if( fullExtent == null ) { |
||
236 | 10208 | jorpiell | fullExtent = drv.getLayersExtent(sLayers,sSRS); |
237 | 4677 | jorpiell | } |
238 | } |
||
239 | 6050 | jaume | |
240 | |||
241 | 4677 | jorpiell | this.setFullExtent(fullExtent);
|
242 | this.setFormat(sFormat);
|
||
243 | this.setLayerQuery(sLayer);
|
||
244 | this.setInfoLayerQuery(""); |
||
245 | this.setSRS(sSRS);
|
||
246 | this.setName(sLayer);
|
||
247 | 10208 | jorpiell | this.setOnlineResources(drv.getOnlineResources());
|
248 | load(); |
||
249 | 4677 | jorpiell | } |
250 | 6050 | jaume | |
251 | 4222 | jaume | /**
|
252 | 6050 | jaume | * It choose the best format to load different maps if the server
|
253 | * supports it. This format could be png, because it supports
|
||
254 | 4677 | jorpiell | * transparency.
|
255 | * @param formats
|
||
256 | * Arraywith all the formats supported by the server
|
||
257 | * @return
|
||
258 | 6050 | jaume | */
|
259 | 4677 | jorpiell | private String getGreatFormat(Vector formats){ |
260 | for (int i=0 ; i<formats.size() ; i++){ |
||
261 | String format = (String) formats.get(i); |
||
262 | if (format.equals("image/jpg")){ |
||
263 | return format;
|
||
264 | } |
||
265 | if (format.equals("image/jpeg")){ |
||
266 | return format;
|
||
267 | } |
||
268 | } |
||
269 | 6050 | jaume | |
270 | 4677 | jorpiell | return (String)formats.get(0); |
271 | } |
||
272 | 6050 | jaume | |
273 | 4677 | jorpiell | /**
|
274 | 9056 | nacho | * Clase que contiene los datos de visualizaci?n de WMS. Tiene datos que representan al
|
275 | 10705 | jaume | * raster en la vista. Este raster puede estar compuesto por tiles por lo que valores
|
276 | 9056 | nacho | * como el ancho total o el m?nimo o m?ximo deben ser calculados a partir de todos los
|
277 | * tiles visualizados.
|
||
278 | 4222 | jaume | * @author Nacho Brodin (brodin_ign@gva.es)
|
279 | */
|
||
280 | private class VisualStatusWMS{ |
||
281 | /**
|
||
282 | 6050 | jaume | * Ancho y alto de la imagen o del conjunto de tiles si los tiene. Coincide con
|
283 | 4222 | jaume | * el ancho y alto del viewPort
|
284 | */
|
||
285 | private int width = 0, height = 0; |
||
286 | private double minX = 0D, minY = 0D, maxX = 0D, maxY = 0D; |
||
287 | 4378 | nacho | private int bandCount = 0; |
288 | private int dataType = DataBuffer.TYPE_UNDEFINED; |
||
289 | 9056 | nacho | |
290 | /**
|
||
291 | * Ancho y alto total del raster que ser? la suma de todos los tiles.
|
||
292 | */
|
||
293 | private int rasterWidth = 0, rasterHeight = 0; |
||
294 | private double rasterMinX = Double.MAX_VALUE, rasterMinY = Double.MAX_VALUE; |
||
295 | private double rasterMaxX = 0, rasterMaxY = 0; |
||
296 | /**
|
||
297 | * Lista de nombre de fichero que componen toda la visualizaci?n.
|
||
298 | */
|
||
299 | private String[] fileNames = null; |
||
300 | 4222 | jaume | } |
301 | 3746 | jaume | |
302 | 6050 | jaume | |
303 | 3746 | jaume | /**
|
304 | * Devuelve el XMLEntity con la informaci?n necesaria para reproducir la
|
||
305 | * capa.
|
||
306 | *
|
||
307 | * @return XMLEntity.
|
||
308 | * @throws XMLException
|
||
309 | */
|
||
310 | public XMLEntity getXMLEntity() throws XMLException { |
||
311 | XMLEntity xml = super.getXMLEntity();
|
||
312 | |||
313 | 4222 | jaume | // Full extent
|
314 | 3746 | jaume | xml.putProperty("fullExtent", StringUtilities.rect2String(fullExtent));
|
315 | 6050 | jaume | |
316 | 4222 | jaume | // Host
|
317 | 3746 | jaume | xml.putProperty("host", host.toExternalForm());
|
318 | 6050 | jaume | |
319 | 4222 | jaume | // Part of the query that is not the host, or the
|
320 | // layer names, or other not listed bellow
|
||
321 | 3746 | jaume | xml.putProperty("infoLayerQuery", infoLayerQuery);
|
322 | 6050 | jaume | |
323 | 4222 | jaume | // Part of the query containing the layer names
|
324 | 3746 | jaume | xml.putProperty("layerQuery", layerQuery);
|
325 | 6050 | jaume | |
326 | 4222 | jaume | // Format
|
327 | 3746 | jaume | xml.putProperty("format", m_Format);
|
328 | 6050 | jaume | |
329 | 4222 | jaume | // SRS
|
330 | 3746 | jaume | xml.putProperty("srs", m_SRS);
|
331 | if (status!=null) |
||
332 | status.getXMLEntity(xml, true, this); |
||
333 | else{
|
||
334 | status = new StatusLayerRaster();
|
||
335 | status.getXMLEntity(xml, true, this); |
||
336 | } |
||
337 | 6050 | jaume | |
338 | 4222 | jaume | // Transparency
|
339 | 3746 | jaume | xml.putProperty("wms_transparency", wmsTransparency);
|
340 | 6050 | jaume | |
341 | 4222 | jaume | // Styles
|
342 | 3746 | jaume | if (styles!=null){ |
343 | String stylePr = ""; |
||
344 | for (int i = 0; i < styles.size(); i++) { |
||
345 | stylePr += (String) styles.get(i);
|
||
346 | if (i<styles.size()-1) |
||
347 | stylePr += ",";
|
||
348 | } |
||
349 | 4222 | jaume | if (stylePr.endsWith(",")) |
350 | stylePr += " ";
|
||
351 | 3746 | jaume | xml.putProperty("styles", stylePr);
|
352 | } |
||
353 | 6050 | jaume | |
354 | // Dimensions
|
||
355 | 3746 | jaume | if (dimensions!=null){ |
356 | String dim = ""; |
||
357 | for (int i = 0; i < dimensions.size(); i++) { |
||
358 | dim += (String) dimensions.get(i);
|
||
359 | if (i<dimensions.size()-1) |
||
360 | dim += ",";
|
||
361 | } |
||
362 | 4222 | jaume | if (dim.endsWith(",")) |
363 | dim += " ";
|
||
364 | 3746 | jaume | xml.putProperty("dimensions", dim);
|
365 | } |
||
366 | 6050 | jaume | |
367 | 4222 | jaume | // OnlineResources
|
368 | Iterator it = onlineResources.keySet().iterator();
|
||
369 | String strOnlines = ""; |
||
370 | while (it.hasNext()) {
|
||
371 | String key = (String) it.next(); |
||
372 | String value = (String) onlineResources.get(key); |
||
373 | 10705 | jaume | strOnlines += key+"~##SEP2##~"+value;
|
374 | 4222 | jaume | if (it.hasNext())
|
375 | strOnlines += "~##SEP1##~";
|
||
376 | } |
||
377 | xml.putProperty("onlineResources", strOnlines);
|
||
378 | 6050 | jaume | |
379 | 4222 | jaume | // Queryable
|
380 | xml.putProperty("queryable", queryable);
|
||
381 | 6050 | jaume | |
382 | 4222 | jaume | // fixedSize
|
383 | if (isSizeFixed()) {
|
||
384 | xml.putProperty("fixedSize", true); |
||
385 | xml.putProperty("fixedWidth", fixedSize.width);
|
||
386 | xml.putProperty("fixedHeight", fixedSize.height);
|
||
387 | } |
||
388 | 3746 | jaume | return xml;
|
389 | } |
||
390 | |||
391 | /**
|
||
392 | * A partir del XMLEntity reproduce la capa.
|
||
393 | *
|
||
394 | * @param xml XMLEntity
|
||
395 | *
|
||
396 | * @throws XMLException
|
||
397 | * @throws DriverException
|
||
398 | * @throws DriverIOException
|
||
399 | */
|
||
400 | public void setXMLEntity03(XMLEntity xml) |
||
401 | throws XMLException {
|
||
402 | super.setXMLEntity(xml);
|
||
403 | fullExtent = StringUtilities.string2Rect(xml.getStringProperty( |
||
404 | "fullExtent"));
|
||
405 | |||
406 | try {
|
||
407 | host = new URL(xml.getStringProperty("host")); |
||
408 | } catch (MalformedURLException e) { |
||
409 | throw new XMLException(e); |
||
410 | } |
||
411 | |||
412 | infoLayerQuery = xml.getStringProperty("infoLayerQuery");
|
||
413 | layerQuery = xml.getStringProperty("layerQuery");
|
||
414 | m_Format = xml.getStringProperty("format");
|
||
415 | m_SRS = xml.getStringProperty("srs");
|
||
416 | } |
||
417 | |||
418 | /**
|
||
419 | * A partir del XMLEntity reproduce la capa.
|
||
420 | *
|
||
421 | * @param xml XMLEntity
|
||
422 | *
|
||
423 | * @throws XMLException
|
||
424 | * @throws DriverException
|
||
425 | * @throws DriverIOException
|
||
426 | */
|
||
427 | public void setXMLEntity(XMLEntity xml) |
||
428 | throws XMLException {
|
||
429 | super.setXMLEntity(xml);
|
||
430 | fullExtent = StringUtilities.string2Rect(xml.getStringProperty( |
||
431 | "fullExtent"));
|
||
432 | 6050 | jaume | |
433 | 4222 | jaume | // Host
|
434 | 3746 | jaume | try {
|
435 | host = new URL(xml.getStringProperty("host")); |
||
436 | } catch (MalformedURLException e) { |
||
437 | throw new XMLException(e); |
||
438 | } |
||
439 | |||
440 | 4222 | jaume | // Part of the query that is not the host, or the
|
441 | // layer names, or other not listed bellow
|
||
442 | 3746 | jaume | infoLayerQuery = xml.getStringProperty("infoLayerQuery");
|
443 | 4222 | jaume | |
444 | // Part of the query containing the layer names
|
||
445 | 3746 | jaume | layerQuery = xml.getStringProperty("layerQuery");
|
446 | 6050 | jaume | |
447 | 4222 | jaume | // Format
|
448 | 3746 | jaume | m_Format = xml.getStringProperty("format");
|
449 | 6050 | jaume | |
450 | 4222 | jaume | // SRS
|
451 | 3746 | jaume | m_SRS = xml.getStringProperty("srs");
|
452 | 6050 | jaume | |
453 | 4222 | jaume | String claseStr = StatusLayerRaster.defaultClass;
|
454 | 3746 | jaume | if (xml.contains("raster.class")) { |
455 | claseStr = xml.getStringProperty("raster.class");
|
||
456 | } |
||
457 | 6050 | jaume | |
458 | 4222 | jaume | // Transparency
|
459 | 3746 | jaume | if (xml.contains("wms_transparency")) |
460 | wmsTransparency = xml.getBooleanProperty("wms_transparency");
|
||
461 | 6050 | jaume | |
462 | 4222 | jaume | // Styles
|
463 | 3746 | jaume | if (xml.contains("styles")){ |
464 | styles = new Vector(); |
||
465 | String[] stl = xml.getStringProperty("styles").split(","); |
||
466 | 6050 | jaume | |
467 | 3746 | jaume | for (int i = 0; i < stl.length; i++) { |
468 | 4222 | jaume | if (stl[i].equals(" ")) |
469 | stl[i]="";
|
||
470 | 3746 | jaume | styles.add(stl[i]); |
471 | } |
||
472 | } |
||
473 | 6050 | jaume | |
474 | 4222 | jaume | // Dimensions
|
475 | 3746 | jaume | if (xml.contains("dimensions")){ |
476 | dimensions = new Vector(); |
||
477 | String[] dims = xml.getStringProperty("dimensions").split(","); |
||
478 | for (int i = 0; i < dims.length; i++){ |
||
479 | 4222 | jaume | if (dims[i].equals(" ")) |
480 | dims[i]="";
|
||
481 | 6050 | jaume | |
482 | 3746 | jaume | dimensions.add(dims[i]); |
483 | } |
||
484 | } |
||
485 | 6050 | jaume | |
486 | 4222 | jaume | // OnlineResources
|
487 | if (xml.contains("onlineResources")) { |
||
488 | String[] operations = xml.getStringProperty("onlineResources").split("~##SEP1##~"); |
||
489 | for (int i = 0; i < operations.length; i++) { |
||
490 | String[] resources = operations[i].split("~##SEP2##~"); |
||
491 | if (resources.length==2 && resources[1]!="") |
||
492 | onlineResources.put(resources[0], resources[1]); |
||
493 | } |
||
494 | } |
||
495 | 6050 | jaume | |
496 | 4222 | jaume | // Queryable
|
497 | queryable = true; // let's assume that the layer is queryable by default |
||
498 | if (xml.contains("queryable")) |
||
499 | queryable = xml.getBooleanProperty("queryable");
|
||
500 | 6050 | jaume | |
501 | 4222 | jaume | // fixedSize
|
502 | if (xml.contains("fixedSize")) { |
||
503 | 6050 | jaume | fixedSize = new Dimension(xml.getIntProperty("fixedWidth"), |
504 | 4222 | jaume | xml.getIntProperty("fixedHeight"));
|
505 | } |
||
506 | 6050 | jaume | |
507 | 3746 | jaume | if(status!=null) |
508 | status.setXMLEntity(xml, this);
|
||
509 | else{
|
||
510 | if(claseStr!=null && !claseStr.equals("")){ |
||
511 | try{
|
||
512 | Class clase = Class.forName(claseStr); |
||
513 | Constructor constr = clase.getConstructor(null); |
||
514 | status = (StatusRasterInterface)constr.newInstance(null);
|
||
515 | if(status!=null) |
||
516 | status.setXMLEntity(xml, this);
|
||
517 | }catch(ClassNotFoundException exc){ |
||
518 | exc.printStackTrace(); |
||
519 | }catch(InstantiationException exc){ |
||
520 | exc.printStackTrace(); |
||
521 | }catch(IllegalAccessException exc){ |
||
522 | exc.printStackTrace(); |
||
523 | }catch(NoSuchMethodException exc){ |
||
524 | exc.printStackTrace(); |
||
525 | }catch(InvocationTargetException exc){ |
||
526 | exc.printStackTrace(); |
||
527 | 6050 | jaume | } |
528 | 3746 | jaume | } |
529 | } |
||
530 | firstLoad = true;
|
||
531 | } |
||
532 | |||
533 | /**
|
||
534 | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint)
|
||
535 | */
|
||
536 | 8765 | jjdelcerro | public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancellable) throws DriverException { |
537 | 5055 | ldiaz | XMLItem[] item = new XMLItem[1]; |
538 | 6050 | jaume | try {
|
539 | 4222 | jaume | if (queryable)
|
540 | { |
||
541 | //TODO
|
||
542 | // check if there are layers which are not queryable
|
||
543 | 6881 | cesar | ViewPort viewPort = getMapContext().getViewPort(); |
544 | 4222 | jaume | |
545 | Point tiledPoint = new Point((int) p.getX() % maxTilePrintWidth, (int) p.getY() % maxTilePrintHeight); |
||
546 | Rectangle rect = new Rectangle(0, 0, viewPort.getImageWidth() - 1, viewPort.getImageHeight() - 1); |
||
547 | Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, rect);
|
||
548 | tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
||
549 | int nCols = tiles.getNumCols();
|
||
550 | |||
551 | int col = (int) p.getX() / maxTilePrintWidth; |
||
552 | int row = (int) p.getY() / maxTilePrintHeight; |
||
553 | int tileIndex = (row*nCols) + col;
|
||
554 | 6050 | jaume | |
555 | 4222 | jaume | ViewPort vp = tiles.getTileViewPort(viewPort, tileIndex); |
556 | 8907 | jaume | wmsStatus.setExtent(vp.getAdjustedExtent()); |
557 | 4222 | jaume | wmsStatus.setHeight(vp.getImageHeight()); |
558 | wmsStatus.setWidth(vp.getImageWidth()); |
||
559 | wmsStatus.setOnlineResource((String) onlineResources.get("GetFeatureInfo")); |
||
560 | 10705 | jaume | |
561 | 10527 | ldiaz | //This is in the case we call layer.getInfo outside the info tool.
|
562 | 10522 | ldiaz | if (wmsStatus.getSrs() == null){ |
563 | wmsStatus.setSrs(this.m_SRS);
|
||
564 | } |
||
565 | 10527 | ldiaz | if(wmsStatus.getFormat() == null){ |
566 | wmsStatus.setFormat(this.m_Format);
|
||
567 | } |
||
568 | if(wmsStatus.getLayerNames().isEmpty()){
|
||
569 | wmsStatus.addLayerName(this.getLayerQuery());
|
||
570 | } |
||
571 | 10705 | jaume | |
572 | 8765 | jjdelcerro | MyCancellable c = new MyCancellable(cancellable);
|
573 | 5055 | ldiaz | item[0] = new StringXMLItem(new String(getDriver() |
574 | 8765 | jjdelcerro | .getFeatureInfo(wmsStatus, (int) tiledPoint.getX(), (int) tiledPoint.getY(), Integer.MAX_VALUE, c)),this); |
575 | 5055 | ldiaz | return item;
|
576 | 4222 | jaume | } |
577 | else
|
||
578 | { |
||
579 | 8765 | jjdelcerro | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),this.getName() + " " + |
580 | PluginServices.getText(this,"layer_not_queryable")); |
||
581 | 5203 | ldiaz | item[0] = new StringXMLItem("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><info></info>",this); |
582 | 5055 | ldiaz | return item;
|
583 | 8765 | jjdelcerro | //return null;
|
584 | 4222 | jaume | } |
585 | 3746 | jaume | } catch (WMSException e) {
|
586 | 5055 | ldiaz | item[0] = new StringXMLItem("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><exception>" + |
587 | 5203 | ldiaz | e.getMessage() + "</exception>", this); |
588 | 5055 | ldiaz | return item;
|
589 | 8765 | jjdelcerro | } |
590 | /*azabala
|
||
591 | catch (ValidationException e) {
|
||
592 | 4222 | jaume | throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
|
593 | 3746 | jaume | } catch (UnsupportedVersionException e) {
|
594 | 4222 | jaume | throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
|
595 | 3746 | jaume | } catch (IOException e) {
|
596 | 4222 | jaume | throw new DriverException(PluginServices.getText(this, "connect_error"), e);
|
597 | 8765 | jjdelcerro | }
|
598 | */
|
||
599 | catch (ValidationException e) {
|
||
600 | UnknownResponseFormatExceptionType type = |
||
601 | new UnknownResponseFormatExceptionType();
|
||
602 | type.setLayerName(getName()); |
||
603 | try {
|
||
604 | type.setDriverName("WMS Driver");
|
||
605 | } catch (Exception e1) { |
||
606 | e1.printStackTrace(); |
||
607 | } |
||
608 | type.setFormat(m_Format); |
||
609 | type.setHost(host); |
||
610 | type.setProtocol("WMS");
|
||
611 | DriverException exception = new DriverException("unknown_response_format", type); |
||
612 | throw exception;
|
||
613 | |||
614 | } catch (UnsupportedVersionException e) {
|
||
615 | UnsuportedProtocolVersionExceptionType type = |
||
616 | new UnsuportedProtocolVersionExceptionType();
|
||
617 | type.setLayerName(getName()); |
||
618 | try {
|
||
619 | type.setDriverName("WMS Driver");
|
||
620 | } catch (Exception ex){ |
||
621 | } |
||
622 | type.setUrl(host); |
||
623 | throw new DriverException(PluginServices.getText(this, "version_conflict"), e, type); |
||
624 | |||
625 | } catch (IOException e) { |
||
626 | ConnectionErrorExceptionType type = new ConnectionErrorExceptionType();
|
||
627 | type.setLayerName(getName()); |
||
628 | try {
|
||
629 | type.setDriverName("WMS Driver");
|
||
630 | } catch (Exception e1) { |
||
631 | } |
||
632 | type.setHost(host); |
||
633 | throw new DriverException(PluginServices. |
||
634 | getText(this, "connect_error"), e, type); |
||
635 | } |
||
636 | catch (NoninvertibleTransformException e) { |
||
637 | 4222 | jaume | NotificationManager.addError("NotinvertibleTransform", e);
|
638 | 3746 | jaume | } |
639 | 4222 | jaume | return null; |
640 | 3746 | jaume | } |
641 | |||
642 | /**
|
||
643 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
||
644 | */
|
||
645 | public Rectangle2D getFullExtent() { |
||
646 | return fullExtent;
|
||
647 | } |
||
648 | |||
649 | /**
|
||
650 | 6050 | jaume | *
|
651 | 3746 | jaume | * @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage,
|
652 | * java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
|
||
653 | 5334 | jaume | * com.iver.cit.gvsig.fmap.operations.Cancellable)
|
654 | 3746 | jaume | */
|
655 | 6805 | jaume | private int callCount; // mess code, represents the amount of times the methods drawFixedSize or drawTile where tried for an extent |
656 | private static final int MAX_RETRY_TIMES = 5; // mess code, represents the max amount of retries allowed. |
||
657 | 3746 | jaume | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
658 | Cancellable cancel,double scale) throws DriverException { |
||
659 | 6805 | jaume | callCount = 0; // mess code |
660 | 4222 | jaume | if (isWithinScale(scale)){
|
661 | Point2D p = viewPort.getOffset();
|
||
662 | // p will be (0, 0) when drawing a view or other when painting onto
|
||
663 | // the Layout.
|
||
664 | visualStatus.width = viewPort.getImageWidth(); |
||
665 | visualStatus.height = viewPort.getImageHeight(); |
||
666 | visualStatus.minX = viewPort.getAdjustedExtent().getMinX(); |
||
667 | visualStatus.minY = viewPort.getAdjustedExtent().getMinY(); |
||
668 | visualStatus.maxX = viewPort.getAdjustedExtent().getMaxX(); |
||
669 | visualStatus.maxY = viewPort.getAdjustedExtent().getMaxY(); |
||
670 | 6805 | jaume | |
671 | |||
672 | 4222 | jaume | if (isSizeFixed()) {
|
673 | // This condition handles those situations in which the server can
|
||
674 | // only give static extent and resolution maps despite we need
|
||
675 | // a specific BBOX and pixel WIDTH and HEIGHT
|
||
676 | drawFixedSize(g, viewPort, cancel); |
||
677 | |||
678 | } else {
|
||
679 | 5534 | nacho | if(mustTileDraw){
|
680 | Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), viewPort.getImageWidth(), viewPort.getImageHeight()); |
||
681 | Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
|
||
682 | tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
||
683 | for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
||
684 | // drawing part
|
||
685 | try {
|
||
686 | ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
||
687 | drawTile(g, vp, cancel); |
||
688 | } catch (NoninvertibleTransformException e) { |
||
689 | e.printStackTrace(); |
||
690 | } |
||
691 | 4222 | jaume | } |
692 | 5534 | nacho | }else
|
693 | drawTile(g, viewPort, cancel); |
||
694 | 4222 | jaume | } |
695 | 3841 | nacho | } |
696 | } |
||
697 | 6050 | jaume | |
698 | 4222 | jaume | private void drawFixedSize(Graphics2D g, ViewPort vp, Cancellable cancel) throws DriverException { |
699 | 6805 | jaume | callCount++; // mess code, it is not unusual a wms server to response an error which is completely
|
700 | // temporal and the response is available if we retry requesting.
|
||
701 | //
|
||
702 | |||
703 | |||
704 | 4222 | jaume | // This is the extent that will be requested
|
705 | Rectangle2D bBox = getFullExtent();
|
||
706 | 5409 | jaume | MyCancellable c = new MyCancellable(cancel);
|
707 | 6050 | jaume | |
708 | try {
|
||
709 | 4222 | jaume | wmsStatus.setExtent( bBox ); |
710 | wmsStatus.setFormat( m_Format ); |
||
711 | wmsStatus.setHeight( fixedSize.height ); |
||
712 | wmsStatus.setWidth( fixedSize.width ); |
||
713 | wmsStatus.setLayerNames(Utilities.createVector(layerQuery,",")); |
||
714 | wmsStatus.setSrs(m_SRS); |
||
715 | wmsStatus.setStyles(styles); |
||
716 | wmsStatus.setDimensions(dimensions); |
||
717 | wmsStatus.setTransparency(wmsTransparency); |
||
718 | wmsStatus.setOnlineResource((String) onlineResources.get("GetMap")); |
||
719 | 5409 | jaume | File f = getDriver().getMap(wmsStatus, c);
|
720 | if (f == null) |
||
721 | return;
|
||
722 | 4222 | jaume | String nameWorldFile = f.getPath() + getExtensionWorldFile();
|
723 | com.iver.andami.Utilities.createTemp(nameWorldFile, this.getDataWorldFile(bBox, fixedSize));
|
||
724 | 6050 | jaume | |
725 | 4222 | jaume | if(status!=null && firstLoad){ |
726 | status.applyStatus(this);
|
||
727 | firstLoad = false;
|
||
728 | } |
||
729 | 6050 | jaume | |
730 | 4222 | jaume | // And finally, obtain the extent intersecting the view and the BBox
|
731 | // to draw to.
|
||
732 | Rectangle2D extent = new Rectangle2D.Double(); |
||
733 | Rectangle2D.intersect(vp.getAdjustedExtent(), bBox, extent);
|
||
734 | 6050 | jaume | |
735 | 4222 | jaume | ViewPortData vpData = new ViewPortData(
|
736 | vp.getProjection(), new Extent(extent), fixedSize );
|
||
737 | vpData.setMat(vp.getAffineTransform()); |
||
738 | |||
739 | rasterProcess(g, vpData, f); |
||
740 | 6050 | jaume | |
741 | 4222 | jaume | } catch (ValidationException e) {
|
742 | 5409 | jaume | if (!c.isCanceled())
|
743 | 8765 | jjdelcerro | { |
744 | UnknownResponseFormatExceptionType type = |
||
745 | new UnknownResponseFormatExceptionType();
|
||
746 | type.setLayerName(getName()); |
||
747 | try {
|
||
748 | type.setDriverName("WMS Driver");
|
||
749 | } catch (Exception e1) { |
||
750 | e1.printStackTrace(); |
||
751 | } |
||
752 | type.setFormat(m_Format); |
||
753 | type.setHost(host); |
||
754 | type.setProtocol("WMS");
|
||
755 | DriverException exception = new DriverException("unknown_response_format", type); |
||
756 | throw exception;
|
||
757 | } |
||
758 | // azabala throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
|
||
759 | 4222 | jaume | } catch (UnsupportedVersionException e) {
|
760 | 8765 | jjdelcerro | if (!c.isCanceled()){
|
761 | UnsuportedProtocolVersionExceptionType type = |
||
762 | new UnsuportedProtocolVersionExceptionType();
|
||
763 | type.setLayerName(getName()); |
||
764 | try {
|
||
765 | type.setDriverName("WMS Driver");
|
||
766 | } catch (Exception ex){ |
||
767 | } |
||
768 | type.setUrl(host); |
||
769 | throw new DriverException(PluginServices.getText(this, "version_conflict"), e, type); |
||
770 | } |
||
771 | // azabala throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
|
||
772 | 4222 | jaume | } catch (IOException e) { |
773 | 5409 | jaume | if (!c.isCanceled())
|
774 | 6818 | jaume | if (callCount<MAX_RETRY_TIMES) { // mess code |
775 | NotificationManager.addWarning("\n[ FLyrWMS.drawFixedSize() ] Failed in trying " + callCount + "/" + MAX_RETRY_TIMES + ")\n", null); // mess code |
||
776 | // I'll try again requesting up to MAX_RETRY_TIMES times before throw an error // mess code
|
||
777 | // (this is mess code, should be replaced by a layer status handler which is scheduled for version > 1.0) // mess code
|
||
778 | drawFixedSize(g, vp, cancel); // mess code
|
||
779 | } // mess code
|
||
780 | 8765 | jjdelcerro | |
781 | 6818 | jaume | if (callCount == 1) { // mess code |
782 | 8765 | jjdelcerro | ConnectionErrorExceptionType type = new ConnectionErrorExceptionType();
|
783 | type.setLayerName(getName()); |
||
784 | try {
|
||
785 | type.setDriverName("WMS Driver");
|
||
786 | } catch (Exception e1) { |
||
787 | } |
||
788 | type.setHost(host); |
||
789 | throw new DriverException(PluginServices. |
||
790 | getText(this, "connect_error"), e, type); |
||
791 | // azabala throw new DriverException(PluginServices.getText(this, "connect_error"), e);
|
||
792 | 6818 | jaume | } // mess code
|
793 | 8765 | jjdelcerro | |
794 | |||
795 | 4222 | jaume | } catch (WMSException e) {
|
796 | 5409 | jaume | if (!c.isCanceled()) {
|
797 | 6818 | jaume | if (callCount<MAX_RETRY_TIMES) { // mess code |
798 | NotificationManager.addWarning("\n[ FLyrWMS.drawFixedSize() ] Failed in trying " + callCount + "/" + MAX_RETRY_TIMES + ")\n", null); // mess code |
||
799 | // I'll try again requesting up to MAX_RETRY_TIMES times before throw an error // mess code
|
||
800 | // (this is mess code, should be replaced by a layer status handler which is scheduled for version > 1.0) // mess code
|
||
801 | drawFixedSize(g, vp, cancel); // mess code
|
||
802 | } // mess code
|
||
803 | if (callCount == 1) { // mess code |
||
804 | 8765 | jjdelcerro | // azabala JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
|
805 | WMSDriverExceptionType type = new WMSDriverExceptionType();
|
||
806 | type.setLayerName(getName()); |
||
807 | try {
|
||
808 | type.setDriverName("WMS Driver");
|
||
809 | } catch (Exception e1) { |
||
810 | } |
||
811 | type.setWcsStatus(this.wmsStatus);
|
||
812 | 6805 | jaume | if (!isPrinting)
|
813 | this.setVisible(false); |
||
814 | 8765 | jjdelcerro | throw new DriverException("Error WMS", e, type); |
815 | 6805 | jaume | |
816 | 8765 | jjdelcerro | |
817 | 6818 | jaume | } // mess code
|
818 | 5409 | jaume | } |
819 | 3841 | nacho | } |
820 | 6818 | jaume | callCount--; // mess code
|
821 | 4222 | jaume | } |
822 | 6050 | jaume | |
823 | 3841 | nacho | /**
|
824 | 4222 | jaume | * This is the method used to draw a tile in a WMS mosaic layer.
|
825 | 3841 | nacho | */
|
826 | 4222 | jaume | private void drawTile(Graphics2D g, ViewPort vp, Cancellable cancel) throws DriverException { |
827 | 6805 | jaume | callCount++; |
828 | 6050 | jaume | // Compute the query geometry
|
829 | 4222 | jaume | // 1. Check if it is within borders
|
830 | Rectangle2D extent = getFullExtent();
|
||
831 | 6426 | jaume | if ((vp.getAdjustedExtent().getMinX() > extent.getMaxX()) ||
|
832 | (vp.getAdjustedExtent().getMinY() > extent.getMaxY()) || |
||
833 | (vp.getAdjustedExtent().getMaxX() < extent.getMinX()) || |
||
834 | (vp.getAdjustedExtent().getMaxY() < extent.getMinY())) { |
||
835 | 4222 | jaume | return;
|
836 | } |
||
837 | 6050 | jaume | |
838 | 4222 | jaume | // 2. Compute extent to be requested.
|
839 | Rectangle2D bBox = new Rectangle2D.Double(); |
||
840 | 8907 | jaume | Rectangle2D.intersect(vp.getAdjustedExtent(), extent, bBox);
|
841 | 6050 | jaume | |
842 | 4222 | jaume | // 3. Compute size in pixels
|
843 | 6050 | jaume | double scalex = vp.getAffineTransform().getScaleX();
|
844 | double scaley = vp.getAffineTransform().getScaleY();
|
||
845 | 4222 | jaume | int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1); |
846 | int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1); |
||
847 | 6050 | jaume | |
848 | 10856 | jaume | // begin patch; Avoid request too large (these cases should be product of a bug in
|
849 | // Tiling) when printing
|
||
850 | if (wImg > maxTilePrintWidth +5 || hImg > maxTileDrawHeight +5) { |
||
851 | // Copied and pasted from drawTile
|
||
852 | Point2D p = vp.getOffset();
|
||
853 | Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), vp.getImageWidth(), vp.getImageHeight()); |
||
854 | Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
|
||
855 | tiles.setAffineTransform((AffineTransform) vp.getAffineTransform().clone());
|
||
856 | for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
||
857 | // drawing part
|
||
858 | try {
|
||
859 | ViewPort myViewPort = tiles.getTileViewPort(vp, tileNr); |
||
860 | drawTile(g, myViewPort, cancel); |
||
861 | } catch (NoninvertibleTransformException e) { |
||
862 | e.printStackTrace(); |
||
863 | } |
||
864 | } |
||
865 | return;
|
||
866 | } |
||
867 | // end patch
|
||
868 | |||
869 | 4222 | jaume | Dimension sz = new Dimension(wImg, hImg); |
870 | |||
871 | if ((wImg <= 0) || (hImg <= 0)) { |
||
872 | return;
|
||
873 | } |
||
874 | 5409 | jaume | MyCancellable c = new MyCancellable(cancel);
|
875 | 6050 | jaume | |
876 | 5534 | nacho | try {
|
877 | 7642 | jaume | // wImg = vp.getImageWidth();
|
878 | // hImg = vp.getImageHeight();
|
||
879 | sz = new Dimension(wImg, hImg); |
||
880 | 6086 | jaume | Rectangle2D.intersect(vp.getAdjustedExtent(), extent, bBox);
|
881 | 6050 | jaume | |
882 | 6822 | jaume | |
883 | 4222 | jaume | wmsStatus.setExtent( bBox ); |
884 | wmsStatus.setFormat(m_Format); |
||
885 | wmsStatus.setHeight( hImg ); |
||
886 | wmsStatus.setWidth( wImg ); |
||
887 | wmsStatus.setLayerNames(Utilities.createVector(layerQuery,",")); |
||
888 | wmsStatus.setSrs(m_SRS); |
||
889 | wmsStatus.setStyles(styles); |
||
890 | wmsStatus.setDimensions(dimensions); |
||
891 | wmsStatus.setTransparency(wmsTransparency); |
||
892 | wmsStatus.setOnlineResource((String) onlineResources.get("GetMap")); |
||
893 | 6050 | jaume | |
894 | 8765 | jjdelcerro | // begin patch; Avoid to request too small tiles.
|
895 | // This generally occurs when printing
|
||
896 | 6822 | jaume | |
897 | if (wImg < minTilePrintWidth) {
|
||
898 | double wScale = (double) minTilePrintWidth / wImg; |
||
899 | wmsStatus.setWidth(minTilePrintWidth); |
||
900 | Rectangle2D sExtent = wmsStatus.getExtent();
|
||
901 | Point2D initialPoint = new Point2D.Double(sExtent.getX(), sExtent.getY()); |
||
902 | sExtent.setRect(sExtent.getX()*wScale, sExtent.getY(), sExtent.getWidth()*wScale, sExtent.getHeight()); |
||
903 | if (!bBox.contains(initialPoint)) {
|
||
904 | sExtent.setRect(sExtent.getX() - initialPoint.getX(), sExtent.getY(), sExtent.getWidth(), sExtent.getHeight()); |
||
905 | } |
||
906 | } |
||
907 | |||
908 | if (hImg < minTilePrintHeight) {
|
||
909 | double hScale = (double) minTilePrintHeight / hImg; |
||
910 | wmsStatus.setHeight(minTilePrintHeight); |
||
911 | Rectangle2D sExtent = wmsStatus.getExtent();
|
||
912 | Point2D initialPoint = new Point2D.Double(sExtent.getX(), sExtent.getY()); |
||
913 | sExtent.setRect(sExtent.getX(), sExtent.getY()*hScale, sExtent.getWidth(), sExtent.getHeight()*hScale); |
||
914 | if (!bBox.contains(initialPoint)) {
|
||
915 | sExtent.setRect(sExtent.getX(), sExtent.getY() - initialPoint.getY(), sExtent.getWidth(), sExtent.getHeight()); |
||
916 | } |
||
917 | } |
||
918 | |||
919 | // end patch
|
||
920 | 5409 | jaume | File f = getDriver().getMap(wmsStatus, c);
|
921 | if (f == null) |
||
922 | return;
|
||
923 | 4222 | jaume | String nameWordFile = f.getPath() + getExtensionWorldFile();
|
924 | com.iver.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz));
|
||
925 | 7642 | jaume | |
926 | 4222 | jaume | ViewPortData vpData = new ViewPortData(
|
927 | vp.getProjection(), new Extent(bBox), sz );
|
||
928 | vpData.setMat(vp.getAffineTransform()); |
||
929 | |||
930 | rasterProcess(g, vpData, f); |
||
931 | 7642 | jaume | |
932 | 3840 | nacho | } catch (ValidationException e) {
|
933 | 8765 | jjdelcerro | //azabala
|
934 | // if (!c.isCanceled())
|
||
935 | // throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
|
||
936 | |||
937 | 5409 | jaume | if (!c.isCanceled())
|
938 | 8765 | jjdelcerro | { |
939 | UnknownResponseFormatExceptionType type = |
||
940 | new UnknownResponseFormatExceptionType();
|
||
941 | type.setLayerName(getName()); |
||
942 | try {
|
||
943 | type.setDriverName("WMS Driver");
|
||
944 | } catch (Exception e1) { |
||
945 | e1.printStackTrace(); |
||
946 | } |
||
947 | type.setFormat(m_Format); |
||
948 | type.setHost(host); |
||
949 | type.setProtocol("WMS");
|
||
950 | DriverException exception = new DriverException("unknown_response_format", type); |
||
951 | throw exception;
|
||
952 | } |
||
953 | 3840 | nacho | } catch (UnsupportedVersionException e) {
|
954 | 8765 | jjdelcerro | |
955 | // if (!c.isCanceled())
|
||
956 | // throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
|
||
957 | |||
958 | if (!c.isCanceled()){
|
||
959 | UnsuportedProtocolVersionExceptionType type = |
||
960 | new UnsuportedProtocolVersionExceptionType();
|
||
961 | type.setLayerName(getName()); |
||
962 | try {
|
||
963 | type.setDriverName("WMS Driver");
|
||
964 | } catch (Exception ex){ |
||
965 | } |
||
966 | type.setUrl(host); |
||
967 | throw new DriverException(PluginServices.getText(this, "version_conflict"), e, type); |
||
968 | } |
||
969 | |||
970 | 3840 | nacho | } catch (IOException e) { |
971 | 8765 | jjdelcerro | /*azabala
|
972 | 5409 | jaume | if (!c.isCanceled())
|
973 | 6805 | jaume | if (callCount<MAX_RETRY_TIMES) {
|
974 | NotificationManager.addWarning("\n[ FLyrWMS.drawFixedSize() ] Failed in trying " + callCount + "/" + MAX_RETRY_TIMES + ")\n", null);
|
||
975 | // I'll try again requesting up to MAX_RETRY_TIMES times before throw an error
|
||
976 | // (this is mess code, should be replaced by a layer status handler which is scheduled for version > 1.0)
|
||
977 | 7075 | jaume | drawTile(g, vp, cancel);
|
978 | 6805 | jaume | }
|
979 | if (callCount == 1) {
|
||
980 | throw new DriverException(PluginServices.getText(this, "connect_error"), e);
|
||
981 | }
|
||
982 | 8765 | jjdelcerro | */
|
983 | if (!c.isCanceled()){
|
||
984 | if (callCount<MAX_RETRY_TIMES) { // mess code |
||
985 | 10856 | jaume | NotificationManager.addWarning("\n[ FLyrWMS.drawTileSize() ] Failed in trying " + callCount + "/" + MAX_RETRY_TIMES + ")\n", null); // mess code |
986 | 8765 | jjdelcerro | // I'll try again requesting up to MAX_RETRY_TIMES times before throw an error // mess code
|
987 | // (this is mess code, should be replaced by a layer status handler which is scheduled for version > 1.0) // mess code
|
||
988 | |||
989 | //FIXME Aqu? deberiamos llamar a drawTile o a drawFixedSize????
|
||
990 | 10856 | jaume | drawTile(g, vp, cancel); // mess code
|
991 | 8765 | jjdelcerro | } // mess code
|
992 | } |
||
993 | if (callCount == 1) { // mess code |
||
994 | ConnectionErrorExceptionType type = new ConnectionErrorExceptionType();
|
||
995 | type.setLayerName(getName()); |
||
996 | try {
|
||
997 | type.setDriverName("WMS Driver");
|
||
998 | } catch (Exception e1) {} |
||
999 | type.setHost(host); |
||
1000 | throw new DriverException(PluginServices. |
||
1001 | getText(this, "connect_error"), e, type); |
||
1002 | }//if
|
||
1003 | 3840 | nacho | } catch (WMSException e) {
|
1004 | 8765 | jjdelcerro | /*azabala
|
1005 | 5409 | jaume | if (!c.isCanceled()) {
|
1006 | 6805 | jaume | if (callCount<MAX_RETRY_TIMES) {
|
1007 | NotificationManager.addWarning("\n[ FLyrWMS.drawTile() ] Failed in trying " + callCount + "/" + MAX_RETRY_TIMES +" \n", null);
|
||
1008 | // I'll try again requesting up to MAX_RETRY_TIMES times before throw an error
|
||
1009 | // (this is mess code, should be replaced by a layer status handler which is scheduled for version > 1.0)
|
||
1010 | drawTile(g, vp, cancel);
|
||
1011 | }
|
||
1012 | if (callCount == 1) {
|
||
1013 | 6939 | jaume | if (!isPrinting) {
|
1014 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
|
||
1015 | 6805 | jaume | this.setVisible(false);
|
1016 | 6939 | jaume | }
|
1017 | 6805 | jaume | }
|
1018 | 5409 | jaume | }
|
1019 | 8765 | jjdelcerro | */
|
1020 | if (!c.isCanceled()) {
|
||
1021 | if (callCount<MAX_RETRY_TIMES) { // mess code |
||
1022 | NotificationManager.addWarning("\n[ FLyrWMS.drawFixedSize() ] Failed in trying " + callCount + "/" + MAX_RETRY_TIMES + ")\n", null); // mess code |
||
1023 | // I'll try again requesting up to MAX_RETRY_TIMES times before throw an error // mess code
|
||
1024 | // (this is mess code, should be replaced by a layer status handler which is scheduled for version > 1.0) // mess code
|
||
1025 | drawTile(g, vp, cancel); |
||
1026 | } // mess code
|
||
1027 | if (callCount == 1) { // mess code |
||
1028 | // azabala JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
|
||
1029 | WMSDriverExceptionType type = new WMSDriverExceptionType();
|
||
1030 | type.setLayerName(getName()); |
||
1031 | try {
|
||
1032 | type.setDriverName("WMS Driver");
|
||
1033 | } catch (Exception e1) { |
||
1034 | } |
||
1035 | type.setWcsStatus(this.wmsStatus);
|
||
1036 | if (!isPrinting)
|
||
1037 | this.setVisible(false); |
||
1038 | throw new DriverException("Error WMS", e, type); |
||
1039 | |||
1040 | |||
1041 | } //if
|
||
1042 | }//if
|
||
1043 | }//catch
|
||
1044 | 6805 | jaume | callCount--; |
1045 | 3746 | jaume | } |
1046 | 4222 | jaume | |
1047 | /**
|
||
1048 | * Obtiene la extensi?n del fichero de georreferenciaci?n
|
||
1049 | 6986 | cesar | * @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
|
1050 | 6050 | jaume | * del valor del formato obtenido del servidor. Por defecto asignaremos un .wld
|
1051 | 4222 | jaume | */
|
1052 | private String getExtensionWorldFile(){ |
||
1053 | String extWorldFile = ".wld"; |
||
1054 | if(m_Format.equals("image/tif") || m_Format.equals("image/tiff")) |
||
1055 | extWorldFile = ".tfw";
|
||
1056 | if(m_Format.equals("image/jpeg")) |
||
1057 | extWorldFile = ".jpgw";
|
||
1058 | return extWorldFile;
|
||
1059 | } |
||
1060 | 6050 | jaume | |
1061 | 3746 | jaume | /**
|
1062 | 4222 | jaume | * Calcula el contenido del fichero de georreferenciaci?n de una imagen.
|
1063 | * @param bBox Tama?o y posici?n de la imagen (en coordenadas de usuario)
|
||
1064 | * @param sz Tama?o de la imagen en pixeles.
|
||
1065 | * @return el 'WorldFile', como String.
|
||
1066 | 3746 | jaume | * @throws IOException
|
1067 | */
|
||
1068 | 4222 | jaume | public String getDataWorldFile(Rectangle2D bBox, Dimension sz) throws IOException { |
1069 | StringBuffer data = new StringBuffer(); |
||
1070 | data.append((bBox.getMaxX() - bBox.getMinX())/(sz.getWidth() - 1)+"\n"); |
||
1071 | data.append("0.0\n");
|
||
1072 | data.append("0.0\n");
|
||
1073 | 8765 | jjdelcerro | data.append("-"+(bBox.getMaxY() - bBox.getMinY())/(sz.getHeight() - 1)+"\n"); |
1074 | 4222 | jaume | data.append(""+bBox.getMinX()+"\n"); |
1075 | 8765 | jjdelcerro | data.append(""+bBox.getMaxY()+"\n"); |
1076 | 4222 | jaume | return data.toString();
|
1077 | 3746 | jaume | } |
1078 | 6050 | jaume | |
1079 | 3746 | jaume | /**
|
1080 | 4222 | jaume | * Dibuja una imagen usando PxRaster
|
1081 | * @param g Graphics2D en el que hay que dibujar.
|
||
1082 | * @param vpData Par?metros de visualizaci?n
|
||
1083 | * @param file La imagen en cuesti?n.
|
||
1084 | */
|
||
1085 | 9056 | nacho | private void rasterProcess(Graphics2D g, ViewPortData vpData, File file) throws DriverException { |
1086 | 6050 | jaume | |
1087 | //Creamos el PxRaster
|
||
1088 | 9056 | nacho | try {
|
1089 | rasterFile = new GdalFile(vpData.getProjection(), file.getAbsolutePath());
|
||
1090 | } catch (NotSupportedExtensionException e) {
|
||
1091 | throw new DriverException("Open File Error"); |
||
1092 | } |
||
1093 | 3746 | jaume | raster = new PxRaster(rasterFile, null, rasterFile.getExtent()); |
1094 | 9056 | nacho | grid = new Grid(rasterFile);
|
1095 | grid.addRenderizer(raster); |
||
1096 | 10705 | jaume | |
1097 | 9056 | nacho | if(status != null && firstLoad){ |
1098 | 7106 | nacho | status.applyStatus(this);
|
1099 | firstLoad = false;
|
||
1100 | } |
||
1101 | 7642 | jaume | |
1102 | 3746 | jaume | //Recuperamos la pila de filtros si ya hubiese sido cargado antes
|
1103 | if(this.filterStack!=null) |
||
1104 | raster.filterStack = this.filterStack;
|
||
1105 | 6050 | jaume | |
1106 | 3746 | jaume | raster.setTransparency(false);
|
1107 | 6050 | jaume | |
1108 | 3746 | jaume | //Asignamos transparencia y orden de bandas
|
1109 | 9056 | nacho | if(this.transparency == -1 && !firstLoad); |
1110 | 3746 | jaume | else
|
1111 | raster.setTransparency(this.transparency);
|
||
1112 | 6050 | jaume | |
1113 | 3746 | jaume | raster.setBand(GeoRasterFile.RED_BAND,rband); |
1114 | raster.setBand(GeoRasterFile.GREEN_BAND, gband); |
||
1115 | raster.setBand(GeoRasterFile.BLUE_BAND, bband); |
||
1116 | 6050 | jaume | |
1117 | 3746 | jaume | //Despues del primer pxRaster asignamos el stackManager guardado para los siguientes.
|
1118 | 6050 | jaume | //Con esto conseguimos asignar los cambios que se hayan producido desde el cuadro de
|
1119 | 3746 | jaume | //propiedades cuando creamos un nuevo pxRaster
|
1120 | if(this.stackManager != null) |
||
1121 | 6050 | jaume | raster.setStackManager(this.stackManager);
|
1122 | |||
1123 | 4378 | nacho | if(visualStatus != null){ |
1124 | visualStatus.bandCount = raster.getBandCount(); |
||
1125 | visualStatus.dataType = raster.getDataType(); |
||
1126 | } |
||
1127 | 3841 | nacho | |
1128 | 3746 | jaume | raster.draw(g, vpData); |
1129 | 6050 | jaume | |
1130 | 3746 | jaume | //En el primer pxRaster de una imagen obtenemos el Stack Manager para poder modificarlo
|
1131 | //si queremos desde las propiedades
|
||
1132 | 6050 | jaume | |
1133 | 3746 | jaume | if(this.stackManager == null) |
1134 | 6050 | jaume | this.stackManager = raster.getStackManager();
|
1135 | |||
1136 | 3746 | jaume | if(this.filterStack == null) |
1137 | this.filterStack = raster.filterStack;
|
||
1138 | 6050 | jaume | |
1139 | 4329 | ldiaz | //rasterFile.close();
|
1140 | 3746 | jaume | } |
1141 | 6050 | jaume | |
1142 | 3746 | jaume | /**
|
1143 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
||
1144 | * com.iver.cit.gvsig.fmap.ViewPort,
|
||
1145 | 5334 | jaume | * com.iver.cit.gvsig.fmap.operations.Cancellable)
|
1146 | 3746 | jaume | */
|
1147 | 9013 | caballero | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties) |
1148 | 3746 | jaume | throws DriverException {
|
1149 | 6050 | jaume | if (isVisible() && isWithinScale(scale)){
|
1150 | 3746 | jaume | isPrinting = true;
|
1151 | if (!mustTilePrint) {
|
||
1152 | draw(null, g, viewPort, cancel,scale);
|
||
1153 | } else {
|
||
1154 | // Para no pedir imagenes demasiado grandes, vamos
|
||
1155 | // a hacer lo mismo que hace EcwFile: chunkear.
|
||
1156 | 4222 | jaume | // Llamamos a drawView con cuadraditos m?s peque?os
|
1157 | 3746 | jaume | // del BufferedImage ni caso, cuando se imprime viene con null
|
1158 | 6050 | jaume | |
1159 | 6986 | cesar | Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipBounds());
|
1160 | 3746 | jaume | tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
|
1161 | for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) { |
||
1162 | // Parte que dibuja
|
||
1163 | try {
|
||
1164 | ViewPort vp = tiles.getTileViewPort(viewPort, tileNr); |
||
1165 | 4222 | jaume | drawTile(g, vp, cancel); |
1166 | 3746 | jaume | } catch (NoninvertibleTransformException e) { |
1167 | e.printStackTrace(); |
||
1168 | } |
||
1169 | } |
||
1170 | } |
||
1171 | isPrinting = false;
|
||
1172 | } |
||
1173 | } |
||
1174 | 6050 | jaume | |
1175 | 3746 | jaume | public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale) |
1176 | throws DriverException {
|
||
1177 | draw(null, g, viewPort, cancel,scale);
|
||
1178 | } |
||
1179 | |||
1180 | /**
|
||
1181 | * Devuelve el FMapWMSDriver.
|
||
1182 | *
|
||
1183 | * @return FMapWMSDriver
|
||
1184 | *
|
||
1185 | * @throws IllegalStateException
|
||
1186 | * @throws ValidationException
|
||
1187 | * @throws UnsupportedVersionException
|
||
1188 | * @throws IOException
|
||
1189 | */
|
||
1190 | private FMapWMSDriver getDriver()
|
||
1191 | 6050 | jaume | throws IllegalStateException, ValidationException, |
1192 | 3746 | jaume | UnsupportedVersionException, IOException {
|
1193 | 5334 | jaume | return FMapWMSDriverFactory.getFMapDriverForURL(host);
|
1194 | 3746 | jaume | } |
1195 | 6050 | jaume | |
1196 | 3746 | jaume | /**
|
1197 | * Devuelve el FMapWMSDriver.
|
||
1198 | *
|
||
1199 | * @return FMapWMSDriver
|
||
1200 | *
|
||
1201 | * @throws IllegalStateException
|
||
1202 | * @throws ValidationException
|
||
1203 | * @throws UnsupportedVersionException
|
||
1204 | * @throws IOException
|
||
1205 | */
|
||
1206 | public void setDriver(FMapWMSDriver drv) { |
||
1207 | wms = drv; |
||
1208 | } |
||
1209 | |||
1210 | /**
|
||
1211 | * Devuelve el URL.
|
||
1212 | *
|
||
1213 | * @return URL.
|
||
1214 | */
|
||
1215 | public URL getHost() { |
||
1216 | return host;
|
||
1217 | } |
||
1218 | |||
1219 | /**
|
||
1220 | * Inserta el URL.
|
||
1221 | *
|
||
1222 | * @param host URL.
|
||
1223 | */
|
||
1224 | public void setHost(URL host) { |
||
1225 | this.host = host;
|
||
1226 | } |
||
1227 | |||
1228 | /**
|
||
1229 | * Devuelve la informaci?n de la consulta.
|
||
1230 | *
|
||
1231 | * @return String.
|
||
1232 | */
|
||
1233 | public String getInfoLayerQuery() { |
||
1234 | return infoLayerQuery;
|
||
1235 | } |
||
1236 | |||
1237 | /**
|
||
1238 | 4222 | jaume | * Inserta la informaci?n de la consulta.
|
1239 | 3746 | jaume | *
|
1240 | * @param infoLayerQuery String.
|
||
1241 | */
|
||
1242 | public void setInfoLayerQuery(String infoLayerQuery) { |
||
1243 | this.infoLayerQuery = infoLayerQuery;
|
||
1244 | } |
||
1245 | |||
1246 | /**
|
||
1247 | * Devuelve la consulta.
|
||
1248 | *
|
||
1249 | * @return String.
|
||
1250 | */
|
||
1251 | public String getLayerQuery() { |
||
1252 | return layerQuery;
|
||
1253 | } |
||
1254 | |||
1255 | /**
|
||
1256 | * Inserta la consulta.
|
||
1257 | *
|
||
1258 | * @param layerQuery consulta.
|
||
1259 | */
|
||
1260 | public void setLayerQuery(String layerQuery) { |
||
1261 | this.layerQuery = layerQuery;
|
||
1262 | } |
||
1263 | |||
1264 | /**
|
||
1265 | * Devuelve el formato.
|
||
1266 | *
|
||
1267 | * @return Formato.
|
||
1268 | */
|
||
1269 | public String getFormat() { |
||
1270 | return m_Format;
|
||
1271 | } |
||
1272 | |||
1273 | /**
|
||
1274 | * Inserta el formato.
|
||
1275 | *
|
||
1276 | * @param format Formato.
|
||
1277 | */
|
||
1278 | public void setFormat(String format) { |
||
1279 | m_Format = format; |
||
1280 | } |
||
1281 | |||
1282 | /**
|
||
1283 | * Devuelve el SRS.
|
||
1284 | *
|
||
1285 | * @return SRS.
|
||
1286 | */
|
||
1287 | public String getSRS() { |
||
1288 | return m_SRS;
|
||
1289 | } |
||
1290 | |||
1291 | /**
|
||
1292 | * Inserta el SRS.
|
||
1293 | *
|
||
1294 | * @param m_srs SRS.
|
||
1295 | */
|
||
1296 | public void setSRS(String m_srs) { |
||
1297 | m_SRS = m_srs; |
||
1298 | } |
||
1299 | |||
1300 | /**
|
||
1301 | 4222 | jaume | * Inserta la extensi?n total de la capa.
|
1302 | 3746 | jaume | *
|
1303 | 4222 | jaume | * @param fullExtent Rect?ngulo.
|
1304 | 3746 | jaume | */
|
1305 | public void setFullExtent(Rectangle2D fullExtent) { |
||
1306 | this.fullExtent = fullExtent;
|
||
1307 | } |
||
1308 | 6050 | jaume | |
1309 | 3746 | jaume | public HashMap getProperties() { |
1310 | HashMap info = new HashMap(); |
||
1311 | String[] layerNames = getLayerQuery().split(","); |
||
1312 | Vector layers = new Vector(layerNames.length); |
||
1313 | try {
|
||
1314 | 5409 | jaume | if(getDriver().connect(null)){ |
1315 | 3746 | jaume | for (int i = 0; i < layerNames.length; i++) { |
1316 | 5410 | jaume | layers.add(i, getDriver().getLayer(layerNames[i])); |
1317 | 3746 | jaume | } |
1318 | 4222 | jaume | info.put("name", getName());
|
1319 | 3746 | jaume | info.put("selectedLayers", layers);
|
1320 | info.put("host", getHost());
|
||
1321 | info.put("srs", getSRS());
|
||
1322 | info.put("format", getFormat());
|
||
1323 | info.put("wmsTransparency", new Boolean(wmsTransparency)); |
||
1324 | info.put("styles", styles);
|
||
1325 | info.put("dimensions", dimensions);
|
||
1326 | 4222 | jaume | info.put("fixedSize", fixedSize);
|
1327 | 3746 | jaume | return info;
|
1328 | } |
||
1329 | } catch (Exception e) { |
||
1330 | e.printStackTrace(); |
||
1331 | } |
||
1332 | return null; |
||
1333 | } |
||
1334 | 6050 | jaume | |
1335 | 3746 | jaume | /**
|
1336 | * Asignar el estado del raster
|
||
1337 | * @param status
|
||
1338 | */
|
||
1339 | public void setStatus(StatusRasterInterface status){ |
||
1340 | this.status = status;
|
||
1341 | } |
||
1342 | 6050 | jaume | |
1343 | 3746 | jaume | /**
|
1344 | * Obtiene el estado del raster
|
||
1345 | * @return
|
||
1346 | */
|
||
1347 | public StatusRasterInterface getStatus(){
|
||
1348 | return this.status; |
||
1349 | } |
||
1350 | 6050 | jaume | |
1351 | 3746 | jaume | /* (non-Javadoc)
|
1352 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getAttributes()
|
||
1353 | */
|
||
1354 | public ArrayList getAttributes() { |
||
1355 | if(rasterFile != null){ |
||
1356 | ArrayList attr = new ArrayList(); |
||
1357 | 4378 | nacho | String dataType = "Byte"; |
1358 | 3746 | jaume | if (rasterFile.getDataType() == DataBuffer.TYPE_BYTE) dataType = "Byte"; |
1359 | 4378 | nacho | else if (visualStatus.dataType == DataBuffer.TYPE_SHORT) |
1360 | 3746 | jaume | dataType = "Short";
|
1361 | 4378 | nacho | else if (visualStatus.dataType == DataBuffer.TYPE_USHORT) |
1362 | 3746 | jaume | dataType = "Unsigned Short";
|
1363 | 4378 | nacho | else if (visualStatus.dataType == DataBuffer.TYPE_INT) |
1364 | 3746 | jaume | dataType = "Integer";
|
1365 | 4378 | nacho | else if (visualStatus.dataType == DataBuffer.TYPE_FLOAT) |
1366 | 3746 | jaume | dataType = "Float";
|
1367 | 4378 | nacho | else if (visualStatus.dataType == DataBuffer.TYPE_DOUBLE) |
1368 | 3746 | jaume | dataType = "Double";
|
1369 | else
|
||
1370 | dataType = "Unknown";
|
||
1371 | 4378 | nacho | |
1372 | 3746 | jaume | Object [][] a = { |
1373 | {"Filename",rasterFile.getName().substring(rasterFile.getName().lastIndexOf("/")+1, rasterFile.getName().length())}, |
||
1374 | 4378 | nacho | {"Filesize",new Long(0)}, |
1375 | {"Width",new Integer((int)this.getWidth())}, |
||
1376 | {"Height", new Integer((int)this.getHeight())}, |
||
1377 | {"Bands", new Integer(visualStatus.bandCount)}, |
||
1378 | {"BandDataType", dataType}
|
||
1379 | 3746 | jaume | }; |
1380 | 4378 | nacho | for (int i=0; i<a.length; i++) |
1381 | 3746 | jaume | attr.add(a[i]); |
1382 | 4378 | nacho | |
1383 | 3746 | jaume | return attr;
|
1384 | } |
||
1385 | return null; |
||
1386 | } |
||
1387 | 6050 | jaume | |
1388 | 3746 | jaume | /* (non-Javadoc)
|
1389 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getFilterStack()
|
||
1390 | */
|
||
1391 | public RasterFilterStack getFilterStack() {
|
||
1392 | if(raster!=null) |
||
1393 | return raster.filterStack;
|
||
1394 | return null; |
||
1395 | } |
||
1396 | /* (non-Javadoc)
|
||
1397 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getHeight()
|
||
1398 | */
|
||
1399 | public double getHeight() { |
||
1400 | 4222 | jaume | return visualStatus.height;
|
1401 | 3746 | jaume | } |
1402 | 6050 | jaume | |
1403 | 3746 | jaume | /* (non-Javadoc)
|
1404 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxX()
|
||
1405 | */
|
||
1406 | public double getMaxX() { |
||
1407 | 4222 | jaume | return visualStatus.maxX;
|
1408 | 3746 | jaume | } |
1409 | 6050 | jaume | |
1410 | 3746 | jaume | /* (non-Javadoc)
|
1411 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxY()
|
||
1412 | */
|
||
1413 | public double getMaxY() { |
||
1414 | 4222 | jaume | return visualStatus.maxY;
|
1415 | 3746 | jaume | } |
1416 | 6050 | jaume | |
1417 | 3746 | jaume | /* (non-Javadoc)
|
1418 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinX()
|
||
1419 | */
|
||
1420 | public double getMinX() { |
||
1421 | 4222 | jaume | return visualStatus.minX;
|
1422 | 3746 | jaume | } |
1423 | 6050 | jaume | |
1424 | 3746 | jaume | /* (non-Javadoc)
|
1425 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinY()
|
||
1426 | */
|
||
1427 | public double getMinY() { |
||
1428 | 4222 | jaume | return visualStatus.minY;
|
1429 | 3746 | jaume | } |
1430 | /* (non-Javadoc)
|
||
1431 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getPixel(double, double)
|
||
1432 | */
|
||
1433 | public int[] getPixel(double wcx, double wcy) { |
||
1434 | if(getPxRaster() != null) |
||
1435 | return getPxRaster().getPixel(wcx, wcy);
|
||
1436 | return null; |
||
1437 | } |
||
1438 | /* (non-Javadoc)
|
||
1439 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getSource()
|
||
1440 | */
|
||
1441 | public RasterAdapter getSource() {
|
||
1442 | return null; |
||
1443 | } |
||
1444 | /* (non-Javadoc)
|
||
1445 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getWidth()
|
||
1446 | */
|
||
1447 | public double getWidth() { |
||
1448 | 4222 | jaume | return visualStatus.width;
|
1449 | 3746 | jaume | } |
1450 | /* (non-Javadoc)
|
||
1451 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int)
|
||
1452 | */
|
||
1453 | public void setBand(int flag, int nBand) { |
||
1454 | switch(flag){
|
||
1455 | case GeoRasterFile.RED_BAND:setBandR(nBand);break; |
||
1456 | case GeoRasterFile.GREEN_BAND:setBandG(nBand);break; |
||
1457 | case GeoRasterFile.BLUE_BAND:setBandB(nBand);break; |
||
1458 | } |
||
1459 | } |
||
1460 | /* (non-Javadoc)
|
||
1461 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setFilterStack(org.cresques.io.raster.RasterFilterStack)
|
||
1462 | */
|
||
1463 | public void setFilterStack(RasterFilterStack stack) { |
||
1464 | this.filterStack = stack;
|
||
1465 | } |
||
1466 | /* (non-Javadoc)
|
||
1467 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPos(int, int)
|
||
1468 | */
|
||
1469 | public void setPos(int x, int y) { |
||
1470 | this.posX = x;
|
||
1471 | this.posY = y;
|
||
1472 | } |
||
1473 | 6050 | jaume | |
1474 | 3746 | jaume | /* (non-Javadoc)
|
1475 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPosWC(double, double)
|
||
1476 | */
|
||
1477 | public void setPosWC(double x, double y) { |
||
1478 | this.posXWC = x;
|
||
1479 | this.posYWC = y;
|
||
1480 | } |
||
1481 | 6050 | jaume | |
1482 | 3746 | jaume | /* (non-Javadoc)
|
1483 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setRGB(int, int, int)
|
||
1484 | */
|
||
1485 | public void setRGB(int r, int g, int b) { |
||
1486 | this.r = r;
|
||
1487 | this.g = g;
|
||
1488 | this.b = b;
|
||
1489 | } |
||
1490 | /* (non-Javadoc)
|
||
1491 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setSource(com.iver.cit.gvsig.fmap.layers.RasterAdapter)
|
||
1492 | */
|
||
1493 | public void setSource(RasterAdapter ra) { |
||
1494 | } |
||
1495 | /**
|
||
1496 | * @return Returns the raster.
|
||
1497 | */
|
||
1498 | public PxRaster getPxRaster() {
|
||
1499 | return raster;
|
||
1500 | } |
||
1501 | /**
|
||
1502 | * @return Returns the rasterFile.
|
||
1503 | */
|
||
1504 | public GeoRasterFile getGeoRasterFile() {
|
||
1505 | return rasterFile;
|
||
1506 | } |
||
1507 | 6050 | jaume | |
1508 | 3746 | jaume | public void setTransparency(int trans) { |
1509 | this.transparency = trans;
|
||
1510 | } |
||
1511 | 6050 | jaume | |
1512 | 3746 | jaume | /**
|
1513 | * Sets the R-band.
|
||
1514 | 6050 | jaume | *
|
1515 | 3746 | jaume | * Asigna la banda R.
|
1516 | * @param r
|
||
1517 | */
|
||
1518 | public void setBandR(int r){ |
||
1519 | this.rband = r;
|
||
1520 | } |
||
1521 | 6050 | jaume | |
1522 | 3746 | jaume | /**
|
1523 | * Sets the G-band.
|
||
1524 | 6050 | jaume | *
|
1525 | 3746 | jaume | * Asigna la banda G
|
1526 | * @param g
|
||
1527 | */
|
||
1528 | public void setBandG(int g){ |
||
1529 | this.gband = g;
|
||
1530 | } |
||
1531 | 6050 | jaume | |
1532 | 3746 | jaume | /**
|
1533 | * Sets the B-band.
|
||
1534 | 6050 | jaume | *
|
1535 | 3746 | jaume | * Asigna la banda B
|
1536 | * @param b
|
||
1537 | */
|
||
1538 | public void setBandB(int b){ |
||
1539 | this.bband = b;
|
||
1540 | } |
||
1541 | |||
1542 | /**
|
||
1543 | * @return Returns the wmsTransparency.
|
||
1544 | */
|
||
1545 | 4222 | jaume | public boolean isWmsTransparent() { |
1546 | 3746 | jaume | return wmsTransparency;
|
1547 | } |
||
1548 | |||
1549 | /**
|
||
1550 | * @param wmsTransparency The wmsTransparency to set.
|
||
1551 | */
|
||
1552 | public void setWmsTransparency(boolean wmsTransparency) { |
||
1553 | this.wmsTransparency = wmsTransparency;
|
||
1554 | } |
||
1555 | |||
1556 | 3842 | nacho | /**
|
1557 | 3746 | jaume | * @param styles
|
1558 | */
|
||
1559 | public void setStyles(Vector styles) { |
||
1560 | 11031 | jmvivo | this.styles = styles;
|
1561 | 3842 | nacho | //laura:
|
1562 | //layer query is built with the layer in reverse order
|
||
1563 | // so here we build the styles upside-down.
|
||
1564 | 11031 | jmvivo | // if (styles != null)
|
1565 | // {
|
||
1566 | // this.styles = new Vector();
|
||
1567 | // for(int i = styles.size()-1; i>=0; i--)
|
||
1568 | // {
|
||
1569 | // this.styles.add(styles.elementAt(i));
|
||
1570 | // }
|
||
1571 | // }
|
||
1572 | 3746 | jaume | } |
1573 | 6050 | jaume | |
1574 | 3746 | jaume | /**
|
1575 | 4222 | jaume | * Sets the dimension vector that is a list of key-value pairs containing
|
1576 | * the name of the dimension and the value for it
|
||
1577 | 3746 | jaume | * @param dimensions
|
1578 | */
|
||
1579 | public void setDimensions(Vector dimensions) { |
||
1580 | this.dimensions = dimensions;
|
||
1581 | } |
||
1582 | 4222 | jaume | |
1583 | /**
|
||
1584 | * Sets the set of URLs that should be accessed for each operation performed
|
||
1585 | * to the server.
|
||
1586 | 6050 | jaume | *
|
1587 | 4222 | jaume | * @param onlineResources
|
1588 | */
|
||
1589 | public void setOnlineResources(Hashtable onlineResources) { |
||
1590 | this.onlineResources = onlineResources;
|
||
1591 | } |
||
1592 | 6050 | jaume | |
1593 | 8765 | jjdelcerro | /**
|
1594 | * Gets the URL that should be accessed for an operation performed
|
||
1595 | * to the server.
|
||
1596 | *
|
||
1597 | * @param onlineResources
|
||
1598 | */
|
||
1599 | public String getOnlineResource(String operation) { |
||
1600 | return ((String) onlineResources.get(operation)); |
||
1601 | } |
||
1602 | |||
1603 | 4222 | jaume | /**
|
1604 | * When a server is not fully featured and it only can serve constant map
|
||
1605 | * sizes this value must be set. It expresses the size in pixels (width, height)
|
||
1606 | * that the map will be requested.
|
||
1607 | * @param Dimension sz
|
||
1608 | */
|
||
1609 | public void setFixedSize(Dimension sz) { |
||
1610 | fixedSize = sz; |
||
1611 | } |
||
1612 | 6050 | jaume | |
1613 | 4222 | jaume | /**
|
1614 | * Tells whether if this layer must deal with the server with the constant-size
|
||
1615 | * limitations or not.
|
||
1616 | * @return boolean.
|
||
1617 | */
|
||
1618 | private boolean isSizeFixed() { |
||
1619 | return fixedSize != null && fixedSize.getWidth() > 0 && fixedSize.getHeight() > 0; |
||
1620 | } |
||
1621 | |||
1622 | /**
|
||
1623 | * If it is true, this layer accepts GetFeatureInfo operations. This WMS operations
|
||
1624 | * maps to FMap's infoByPoint(p) operation.
|
||
1625 | * @param b
|
||
1626 | */
|
||
1627 | public void setQueryable(boolean b) { |
||
1628 | queryable = b; |
||
1629 | } |
||
1630 | 4730 | jaume | |
1631 | /**
|
||
1632 | * Creates the part of a OGC's MapContext document that would describe this
|
||
1633 | * layer(s).
|
||
1634 | * @param version, The desired version of the resulting document. (1.1.0)
|
||
1635 | * @return String containing the xml.
|
||
1636 | 6050 | jaume | * @throws UnsupportedVersionException
|
1637 | 4730 | jaume | */
|
1638 | 4917 | jaume | public String toMapContext(String mapContextVersion) { |
1639 | 4730 | jaume | XmlBuilder xml = new XmlBuilder();
|
1640 | FMapWMSDriver drv; |
||
1641 | try {
|
||
1642 | drv = getDriver(); |
||
1643 | } catch (Exception e) { |
||
1644 | return xml.toString();
|
||
1645 | 6050 | jaume | } |
1646 | 4730 | jaume | String[] layerNames = getLayerQuery().split(","); |
1647 | 6050 | jaume | String[] styleNames = (String[]) styles.toArray(new String[0]); |
1648 | 4730 | jaume | for (int i = 0; i < layerNames.length; i++) { |
1649 | WMSLayerNode layer = drv.getLayer(layerNames[i]); |
||
1650 | 4917 | jaume | HashMap xmlAttrs = new HashMap(); |
1651 | 6050 | jaume | |
1652 | 4833 | jaume | // <Layer>
|
1653 | 4917 | jaume | xmlAttrs.put(WebMapContextTags.HIDDEN, !isVisible()+"");
|
1654 | xmlAttrs.put(WebMapContextTags.QUERYABLE, queryable+"");
|
||
1655 | 5409 | jaume | xml.openTag(WebMapContextTags.LAYER, xmlAttrs); |
1656 | xmlAttrs.clear(); |
||
1657 | 4917 | jaume | if (mapContextVersion.equals("1.1.0") || mapContextVersion.equals("1.0.0")) { |
1658 | 4730 | jaume | // <Server>
|
1659 | 4876 | jaume | xmlAttrs.put(WebMapContextTags.SERVICE, WebMapContextTags.WMS); |
1660 | xmlAttrs.put(WebMapContextTags.VERSION, drv.getVersion()); |
||
1661 | xmlAttrs.put(WebMapContextTags.SERVER_TITLE, drv.getServiceTitle()); |
||
1662 | xml.openTag(WebMapContextTags.SERVER, xmlAttrs); |
||
1663 | 4730 | jaume | xmlAttrs.clear(); |
1664 | 6050 | jaume | |
1665 | 4730 | jaume | // <OnlineResource>
|
1666 | 4876 | jaume | xmlAttrs.put(WebMapContextTags.XLINK_TYPE, "simple");
|
1667 | xmlAttrs.put(WebMapContextTags.XLINK_HREF, getHost().toString()); |
||
1668 | xml.writeTag(WebMapContextTags.ONLINE_RESOURCE, xmlAttrs); |
||
1669 | 4730 | jaume | xmlAttrs.clear(); |
1670 | // </OnlineResource>
|
||
1671 | 6050 | jaume | |
1672 | 4730 | jaume | xml.closeTag(); |
1673 | // </Server>
|
||
1674 | 6050 | jaume | |
1675 | 4730 | jaume | // <Name>
|
1676 | 4915 | jaume | xml.writeTag(WebMapContextTags.NAME, layer.getName().trim()); |
1677 | 4730 | jaume | // </Name>
|
1678 | 6050 | jaume | |
1679 | 4730 | jaume | // <Title>
|
1680 | 8765 | jjdelcerro | xml.writeTag(WebMapContextTags.TITLE, layer.getTitle().trim()); |
1681 | //?xml.writeTag(WebMapContextTags.TITLE, getName().trim());
|
||
1682 | 4730 | jaume | // </Title>
|
1683 | 6050 | jaume | |
1684 | 4730 | jaume | // <Abstract>
|
1685 | 4915 | jaume | if (layer.getAbstract() != null) |
1686 | xml.writeTag(WebMapContextTags.ABSTRACT, layer.getAbstract()); |
||
1687 | 4730 | jaume | // </Abstract>
|
1688 | 6050 | jaume | |
1689 | 4730 | jaume | // <SRS> (a list of available SRS for the enclosing layer)
|
1690 | String[] strings = (String[]) layer.getAllSrs().toArray(new String[0]); |
||
1691 | String mySRS = strings[0]; |
||
1692 | for (int j = 1; j < strings.length; j++) { |
||
1693 | mySRS += ","+strings[j];
|
||
1694 | } |
||
1695 | 4915 | jaume | xml.writeTag(WebMapContextTags.SRS, mySRS); |
1696 | 4730 | jaume | // </SRS>
|
1697 | 6050 | jaume | |
1698 | 4730 | jaume | // <FormatList>
|
1699 | 4876 | jaume | xml.openTag(WebMapContextTags.FORMAT_LIST); |
1700 | 4730 | jaume | strings = (String[]) drv.getFormats().toArray(new String[0]); |
1701 | for (int j = 0; j < strings.length; j++) { |
||
1702 | // <Format>
|
||
1703 | 4915 | jaume | String str = strings[j].trim();
|
1704 | if (str.equals(getFormat()))
|
||
1705 | xml.writeTag(WebMapContextTags.FORMAT, str, WebMapContextTags.CURRENT, "1");
|
||
1706 | else
|
||
1707 | xml.writeTag(WebMapContextTags.FORMAT, str); |
||
1708 | 6050 | jaume | // </Format>
|
1709 | 4730 | jaume | } |
1710 | xml.closeTag(); |
||
1711 | // </FormatList>
|
||
1712 | 6050 | jaume | |
1713 | 4730 | jaume | // <StyleList>
|
1714 | 5409 | jaume | xml.openTag(WebMapContextTags.STYLE_LIST); |
1715 | 6050 | jaume | |
1716 | 5409 | jaume | if (layer.getStyles().size()>0) { |
1717 | for (int j = 0; j < layer.getStyles().size(); j++) { |
||
1718 | // <Style>
|
||
1719 | FMapWMSStyle st = (FMapWMSStyle) layer.getStyles().get(j); |
||
1720 | 5410 | jaume | if (st.name.equals(styleNames[i]))
|
1721 | 5409 | jaume | xmlAttrs.put(WebMapContextTags.CURRENT, "1");
|
1722 | xml.openTag(WebMapContextTags.STYLE, xmlAttrs); |
||
1723 | xmlAttrs.clear(); |
||
1724 | 6050 | jaume | |
1725 | 5409 | jaume | // <Name>
|
1726 | xml.writeTag(WebMapContextTags.NAME, st.name); |
||
1727 | // </Name>
|
||
1728 | 6050 | jaume | |
1729 | 5409 | jaume | // <Title>
|
1730 | xml.writeTag(WebMapContextTags.TITLE, st.title); |
||
1731 | // </Title>
|
||
1732 | 6050 | jaume | |
1733 | 5409 | jaume | // <LegendURL width="180" format="image/gif" height="50">
|
1734 | // <OnlineResource xlink:type="simple" xlink:href="http://globe.digitalearth.gov/globe/en/icons/colorbars/NATIONAL.gif"/>
|
||
1735 | // </OnlineResource>
|
||
1736 | // </LegendURL>
|
||
1737 | xml.closeTag(); |
||
1738 | // </Style>
|
||
1739 | 6050 | jaume | |
1740 | 5409 | jaume | } |
1741 | 6050 | jaume | |
1742 | 5409 | jaume | } else {
|
1743 | // Create fake style (for compatibility issues)
|
||
1744 | xmlAttrs.put(WebMapContextTags.CURRENT, "1");
|
||
1745 | 4730 | jaume | // <Style>
|
1746 | 4876 | jaume | xml.openTag(WebMapContextTags.STYLE, xmlAttrs); |
1747 | 5409 | jaume | xmlAttrs.clear(); |
1748 | 4730 | jaume | // <Name>
|
1749 | 5409 | jaume | xml.writeTag(WebMapContextTags.NAME, "default");
|
1750 | 4730 | jaume | // </Name>
|
1751 | 6050 | jaume | |
1752 | 4730 | jaume | // <Title>
|
1753 | 5409 | jaume | xml.writeTag(WebMapContextTags.TITLE, "default");
|
1754 | 4730 | jaume | // </Title>
|
1755 | 6050 | jaume | |
1756 | 5411 | jaume | // // <LegendURL width="180" format="image/gif" height="50">
|
1757 | // xmlAttrs.put(WebMapContextTags.WIDTH, "0");
|
||
1758 | // xmlAttrs.put(WebMapContextTags.HEIGHT, "0");
|
||
1759 | // xmlAttrs.put(WebMapContextTags.FORMAT.toLowerCase(), "image/gif");
|
||
1760 | // xml.openTag(WebMapContextTags.LEGEND_URL, xmlAttrs);
|
||
1761 | // xmlAttrs.clear();
|
||
1762 | // // <OnlineResource xlink:type="simple" xlink:href="http://globe.digitalearth.gov/globe/en/icons/colorbars/NATIONAL.gif"/>
|
||
1763 | // xmlAttrs.put(WebMapContextTags.XLINK_TYPE, "simple");
|
||
1764 | // xmlAttrs.put(WebMapContextTags.XLINK_HREF, "http://globe.digitalearth.gov/globe/en/icons/colorbars/NATIONAL.gif");
|
||
1765 | // xml.writeTag(WebMapContextTags.ONLINE_RESOURCE, xmlAttrs);
|
||
1766 | // // </OnlineResource>
|
||
1767 | // // </LegendURL>
|
||
1768 | // xml.closeTag();
|
||
1769 | 5409 | jaume | // </Style>
|
1770 | 4940 | jaume | xml.closeTag(); |
1771 | 4730 | jaume | } |
1772 | // </StyleList>
|
||
1773 | 5409 | jaume | xml.closeTag(); |
1774 | 4940 | jaume | if (mapContextVersion.compareTo("1.0.0") > 0) { |
1775 | 4730 | jaume | // <DimensionList>
|
1776 | 4940 | jaume | xml.openTag(WebMapContextTags.DIMENSION_LIST); |
1777 | 4730 | jaume | // <Dimension>
|
1778 | // </Dimension>
|
||
1779 | 4940 | jaume | xml.closeTag(); |
1780 | 4730 | jaume | // </DimensionList>
|
1781 | 4917 | jaume | } |
1782 | 4730 | jaume | } else {
|
1783 | xml.writeTag("ERROR", PluginServices.getText(this, "unsupported_map_context_version")); |
||
1784 | } |
||
1785 | 4833 | jaume | // </Layer>
|
1786 | xml.closeTag(); |
||
1787 | 4730 | jaume | } |
1788 | 4915 | jaume | return xml.getXML();
|
1789 | 4730 | jaume | } |
1790 | 6050 | jaume | |
1791 | public ImageIcon getTocImageIcon() { |
||
1792 | 5763 | jmvivo | return new ImageIcon(PluginServices.getPluginServices("com.iver.cit.gvsig.wms").getClassLoader().getResource("images/icoLayer.png")); |
1793 | } |
||
1794 | 6005 | nacho | |
1795 | /*
|
||
1796 | * (non-Javadoc)
|
||
1797 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
|
||
1798 | */
|
||
1799 | public int[] getTileSize() { |
||
1800 | 6050 | jaume | int[] size = {maxTileDrawWidth, maxTileDrawHeight}; |
1801 | 6005 | nacho | return size;
|
1802 | } |
||
1803 | /*
|
||
1804 | * (non-Javadoc)
|
||
1805 | * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled()
|
||
1806 | */
|
||
1807 | public boolean isTiled() { |
||
1808 | return mustTileDraw;
|
||
1809 | } |
||
1810 | 6050 | jaume | |
1811 | 8765 | jjdelcerro | public Image getImageLegend() { |
1812 | try {
|
||
1813 | 10672 | caballero | if (wms == null) |
1814 | wms = getDriver(); |
||
1815 | if (wms.hasLegendGraphic()) {
|
||
1816 | wmsStatus.setOnlineResource((String) onlineResources
|
||
1817 | .get("GetLegendGraphic"));
|
||
1818 | String path = getPathImage();// File legend = |
||
1819 | // getDriver().getLegendGraphic(wmsStatus,
|
||
1820 | // layerQuery, null);
|
||
1821 | 8765 | jjdelcerro | Image img = null; |
1822 | 10672 | caballero | if ((path != null) && (path.length() > 0)) |
1823 | img = new ImageIcon(path).getImage(); |
||
1824 | 8765 | jjdelcerro | return img;
|
1825 | } |
||
1826 | 10672 | caballero | } catch (Exception e) { |
1827 | } |
||
1828 | return null; |
||
1829 | } |
||
1830 | |||
1831 | public String getPathImage() { |
||
1832 | try {
|
||
1833 | File legend = getDriver().getLegendGraphic(wmsStatus, layerQuery, null); |
||
1834 | return legend.getAbsolutePath();
|
||
1835 | 8765 | jjdelcerro | }catch(Exception e){ |
1836 | 9056 | nacho | //e.printStackTrace();
|
1837 | 8765 | jjdelcerro | return null; |
1838 | } |
||
1839 | } |
||
1840 | 6050 | jaume | |
1841 | 9056 | nacho | /**
|
1842 | * Obtiene el grid asociado al raster que hay cargado en ese momento
|
||
1843 | * @return grid
|
||
1844 | */
|
||
1845 | public Grid getGrid(){
|
||
1846 | return grid;
|
||
1847 | } |
||
1848 | 10705 | jaume | |
1849 | 9056 | nacho | /**
|
1850 | * Obtiene el tipo de dato de la capa raster
|
||
1851 | * @return Entero que representa el tipo de dato de la capa raster.
|
||
1852 | */
|
||
1853 | public int getDataType() { |
||
1854 | return rasterFile.getDataType();
|
||
1855 | } |
||
1856 | 10362 | ldiaz | public boolean isQueryable(){ |
1857 | return queryable;
|
||
1858 | } |
||
1859 | 11031 | jmvivo | public ComposedLayer newComposedLayer() {
|
1860 | Preferences prefs = Preferences.userRoot().node("gvsig.wms"); |
||
1861 | |||
1862 | String str = prefs.get("useComposedLayer","false"); |
||
1863 | Boolean useComposedLayer = Boolean.FALSE; |
||
1864 | try {
|
||
1865 | useComposedLayer = Boolean.valueOf(str);
|
||
1866 | } catch (Exception e) { |
||
1867 | |||
1868 | } |
||
1869 | if (useComposedLayer.booleanValue()) {
|
||
1870 | return new ComposedLayerWMS(); |
||
1871 | } else {
|
||
1872 | return null; |
||
1873 | } |
||
1874 | } |
||
1875 | |||
1876 | /**
|
||
1877 | * @param styles
|
||
1878 | */
|
||
1879 | public Vector getStyles() { |
||
1880 | return this.styles; |
||
1881 | } |
||
1882 | |||
1883 | |||
1884 | /* Checks if can make a single petition for
|
||
1885 | * the two layers to the server
|
||
1886 | *
|
||
1887 | * @see com.iver.cit.gvsig.fmap.layers.ComposedLayerWMS#canAdd(com.iver.cit.gvsig.fmap.layers.FLayer)
|
||
1888 | */
|
||
1889 | boolean isComposedLayerCompatible(FLayer layer) {
|
||
1890 | FLyrWMS aLayer; |
||
1891 | |||
1892 | if (!(layer instanceof FLyrWMS)) { |
||
1893 | return false; |
||
1894 | } |
||
1895 | aLayer = (FLyrWMS)layer; |
||
1896 | if (!this.getHost().equals(aLayer.getHost())) { |
||
1897 | return false; |
||
1898 | } |
||
1899 | if (!this.getFormat().equals(aLayer.getFormat())) { |
||
1900 | return false; |
||
1901 | } |
||
1902 | if (!this.getSRS().equals(aLayer.getSRS())) { |
||
1903 | return false; |
||
1904 | } |
||
1905 | if (this.getInfoLayerQuery() != null) { |
||
1906 | if (!this.getInfoLayerQuery().equals(aLayer.getInfoLayerQuery())) { |
||
1907 | return false; |
||
1908 | } |
||
1909 | }else if (aLayer.getInfoLayerQuery() != null) { |
||
1910 | return false; |
||
1911 | } |
||
1912 | |||
1913 | |||
1914 | // isFixedSize es privado
|
||
1915 | if ((this.fixedSize != null) && |
||
1916 | (aLayer.fixedSize!= null)) {
|
||
1917 | if (this.fixedSize.equals(aLayer.fixedSize)) { |
||
1918 | return false; |
||
1919 | } |
||
1920 | } else if ((this.fixedSize != null) != (aLayer.fixedSize != null)) { |
||
1921 | return false; |
||
1922 | } |
||
1923 | |||
1924 | // time elevation (dimensions)
|
||
1925 | if ((this.dimensions != null) && |
||
1926 | (aLayer.dimensions != null)) {
|
||
1927 | if (this.dimensions.size() != aLayer.dimensions.size()) { |
||
1928 | return false; |
||
1929 | } else {
|
||
1930 | Iterator iter = this.dimensions.iterator(); |
||
1931 | while (iter.hasNext()) {
|
||
1932 | if (!aLayer.dimensions.contains(iter.next())) {
|
||
1933 | return false; |
||
1934 | } |
||
1935 | } |
||
1936 | } |
||
1937 | |||
1938 | } else if ((this.dimensions != null) != (aLayer.dimensions != null)) { |
||
1939 | return false; |
||
1940 | } |
||
1941 | |||
1942 | |||
1943 | return true; |
||
1944 | |||
1945 | } |
||
1946 | |||
1947 | 3746 | jaume | } |