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 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
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 |
* Av. Blasco Ib??ez, 50
|
24 |
* 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 |
import java.awt.Dimension; |
45 |
import java.awt.Graphics2D; |
46 |
import java.awt.Image; |
47 |
import java.awt.Point; |
48 |
import java.awt.Rectangle; |
49 |
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 |
import java.awt.image.DataBuffer; |
55 |
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 |
import java.util.Hashtable; |
64 |
import java.util.Iterator; |
65 |
import java.util.Map; |
66 |
import java.util.Vector; |
67 |
import java.util.prefs.Preferences; |
68 |
|
69 |
import javax.print.attribute.PrintRequestAttributeSet; |
70 |
import javax.swing.ImageIcon; |
71 |
import javax.swing.JOptionPane; |
72 |
|
73 |
import org.cresques.filter.RasterFilterStack; |
74 |
import org.cresques.filter.RasterFilterStackManager; |
75 |
import org.cresques.geo.ViewPortData; |
76 |
import org.cresques.io.GdalFile; |
77 |
import org.cresques.io.GeoRasterFile; |
78 |
import org.cresques.io.data.Grid; |
79 |
import org.cresques.io.exceptions.NotSupportedExtensionException; |
80 |
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 |
import org.gvsig.remoteClient.wms.ICancellable; |
85 |
import org.gvsig.remoteClient.wms.WMSStatus; |
86 |
|
87 |
import com.iver.andami.PluginServices; |
88 |
import com.iver.andami.messages.NotificationManager; |
89 |
import com.iver.cit.gvsig.fmap.ConnectionErrorExceptionType; |
90 |
import com.iver.cit.gvsig.fmap.DriverException; |
91 |
import com.iver.cit.gvsig.fmap.UnknownResponseFormatExceptionType; |
92 |
import com.iver.cit.gvsig.fmap.UnsuportedProtocolVersionExceptionType; |
93 |
import com.iver.cit.gvsig.fmap.ViewPort; |
94 |
import com.iver.cit.gvsig.fmap.WMSDriverExceptionType; |
95 |
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 |
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriverFactory; |
99 |
import com.iver.cit.gvsig.fmap.drivers.wms.WMSException; |
100 |
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode.FMapWMSStyle; |
101 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer; |
102 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.IHasImageLegend; |
103 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
104 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.StringXMLItem; |
105 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
106 |
import com.iver.cit.gvsig.fmap.rendering.XmlBuilder; |
107 |
import com.iver.cit.gvsig.wmc.WebMapContextTags; |
108 |
import com.iver.utiles.StringUtilities; |
109 |
import com.iver.utiles.XMLEntity; |
110 |
import com.iver.utiles.swing.threads.Cancellable; |
111 |
|
112 |
|
113 |
|
114 |
/**
|
115 |
* FMap's WMS Layer class.
|
116 |
*
|
117 |
* @author Jaume Dominguez Faus
|
118 |
* Nacho Brodin
|
119 |
*
|
120 |
*/
|
121 |
public class FLyrWMS extends FLyrDefault implements InfoByPoint, RasterOperations, IHasImageLegend { |
122 |
private boolean isPrinting = false; |
123 |
private boolean mustTileDraw = true; |
124 |
private boolean mustTilePrint = true; |
125 |
private final int maxTileDrawWidth = 1023; |
126 |
private final int maxTileDrawHeight = 1023; |
127 |
private final int maxTilePrintWidth = 1023; |
128 |
private final int maxTilePrintHeight = 1023; |
129 |
private final int minTilePrintWidth = 12; |
130 |
private final int minTilePrintHeight = 12; |
131 |
|
132 |
public URL host; |
133 |
public String m_Format; |
134 |
|
135 |
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 |
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 |
private boolean firstLoad = false; |
152 |
private int transparency = -1; |
153 |
private int rband = 0, gband = 1, bband = 2; |
154 |
private RasterFilterStackManager stackManager = null; |
155 |
private Hashtable onlineResources = new Hashtable(); |
156 |
private Dimension fixedSize; |
157 |
private boolean queryable = true; |
158 |
private VisualStatusWMS visualStatus = new VisualStatusWMS(); |
159 |
private Grid grid = null; |
160 |
|
161 |
|
162 |
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 |
if (original == null) return false; |
171 |
return original.isCanceled();
|
172 |
} |
173 |
|
174 |
} |
175 |
|
176 |
public FLyrWMS(){
|
177 |
super();
|
178 |
} |
179 |
|
180 |
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 |
|
189 |
try {
|
190 |
this.setHost(new URL(host)); |
191 |
} catch (MalformedURLException e) { |
192 |
//e.printStackTrace();
|
193 |
throw new DriverIOException("Malformed host URL, '" + host + "' (" + e.toString() + ")."); |
194 |
} |
195 |
try {
|
196 |
drv = this.getDriver();
|
197 |
} catch (Exception e) { |
198 |
// e.printStackTrace();
|
199 |
throw new DriverIOException("Can't get driver to host '" + host + "' (" + e.toString() + ")."); |
200 |
} |
201 |
if( sFormat == null || sSRS == null || fullExtent == null ) { |
202 |
if (!drv.connect(null)) |
203 |
throw new DriverIOException("Can't connect to host '" + host + "'."); |
204 |
|
205 |
WMSLayerNode wmsNode = drv.getLayer(sLayer); |
206 |
|
207 |
if (wmsNode == null){ |
208 |
throw new DriverIOException("The server '" + host + "' doesn't has the layer '" + sLayer + "'."); |
209 |
} |
210 |
if( sFormat == null ) { |
211 |
sFormat = this.getGreatFormat(drv.getFormats());
|
212 |
} |
213 |
|
214 |
//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 |
} |
222 |
} |
223 |
} |
224 |
|
225 |
if(!isSRSSupported) {
|
226 |
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 |
} |
230 |
} |
231 |
if (sSRS==null){ |
232 |
sSRS = (String)wmsNode.getAllSrs().get(0); |
233 |
} |
234 |
} |
235 |
if( fullExtent == null ) { |
236 |
fullExtent = drv.getLayersExtent(sLayers,sSRS); |
237 |
} |
238 |
} |
239 |
|
240 |
|
241 |
this.setFullExtent(fullExtent);
|
242 |
this.setFormat(sFormat);
|
243 |
this.setLayerQuery(sLayer);
|
244 |
this.setInfoLayerQuery(""); |
245 |
this.setSRS(sSRS);
|
246 |
this.setName(sLayer);
|
247 |
this.setOnlineResources(drv.getOnlineResources());
|
248 |
load(); |
249 |
} |
250 |
|
251 |
/**
|
252 |
* It choose the best format to load different maps if the server
|
253 |
* supports it. This format could be png, because it supports
|
254 |
* transparency.
|
255 |
* @param formats
|
256 |
* Arraywith all the formats supported by the server
|
257 |
* @return
|
258 |
*/
|
259 |
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 |
|
270 |
return (String)formats.get(0); |
271 |
} |
272 |
|
273 |
/**
|
274 |
* Clase que contiene los datos de visualizaci?n de WMS. Tiene datos que representan al
|
275 |
* raster en la vista. Este raster puede estar compuesto por tiles por lo que valores
|
276 |
* como el ancho total o el m?nimo o m?ximo deben ser calculados a partir de todos los
|
277 |
* tiles visualizados.
|
278 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
279 |
*/
|
280 |
private class VisualStatusWMS{ |
281 |
/**
|
282 |
* Ancho y alto de la imagen o del conjunto de tiles si los tiene. Coincide con
|
283 |
* 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 |
private int bandCount = 0; |
288 |
private int dataType = DataBuffer.TYPE_UNDEFINED; |
289 |
|
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 |
} |
301 |
|
302 |
|
303 |
/**
|
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 |
// Full extent
|
314 |
xml.putProperty("fullExtent", StringUtilities.rect2String(fullExtent));
|
315 |
|
316 |
// Host
|
317 |
xml.putProperty("host", host.toExternalForm());
|
318 |
|
319 |
// Part of the query that is not the host, or the
|
320 |
// layer names, or other not listed bellow
|
321 |
xml.putProperty("infoLayerQuery", infoLayerQuery);
|
322 |
|
323 |
// Part of the query containing the layer names
|
324 |
xml.putProperty("layerQuery", layerQuery);
|
325 |
|
326 |
// Format
|
327 |
xml.putProperty("format", m_Format);
|
328 |
|
329 |
// SRS
|
330 |
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 |
|
338 |
// Transparency
|
339 |
xml.putProperty("wms_transparency", wmsTransparency);
|
340 |
|
341 |
// Styles
|
342 |
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 |
if (stylePr.endsWith(",")) |
350 |
stylePr += " ";
|
351 |
xml.putProperty("styles", stylePr);
|
352 |
} |
353 |
|
354 |
// Dimensions
|
355 |
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 |
if (dim.endsWith(",")) |
363 |
dim += " ";
|
364 |
xml.putProperty("dimensions", dim);
|
365 |
} |
366 |
|
367 |
// 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 |
strOnlines += key+"~##SEP2##~"+value;
|
374 |
if (it.hasNext())
|
375 |
strOnlines += "~##SEP1##~";
|
376 |
} |
377 |
xml.putProperty("onlineResources", strOnlines);
|
378 |
|
379 |
// Queryable
|
380 |
xml.putProperty("queryable", queryable);
|
381 |
|
382 |
// fixedSize
|
383 |
if (isSizeFixed()) {
|
384 |
xml.putProperty("fixedSize", true); |
385 |
xml.putProperty("fixedWidth", fixedSize.width);
|
386 |
xml.putProperty("fixedHeight", fixedSize.height);
|
387 |
} |
388 |
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 |
|
433 |
// Host
|
434 |
try {
|
435 |
host = new URL(xml.getStringProperty("host")); |
436 |
} catch (MalformedURLException e) { |
437 |
throw new XMLException(e); |
438 |
} |
439 |
|
440 |
// Part of the query that is not the host, or the
|
441 |
// layer names, or other not listed bellow
|
442 |
infoLayerQuery = xml.getStringProperty("infoLayerQuery");
|
443 |
|
444 |
// Part of the query containing the layer names
|
445 |
layerQuery = xml.getStringProperty("layerQuery");
|
446 |
|
447 |
// Format
|
448 |
m_Format = xml.getStringProperty("format");
|
449 |
|
450 |
// SRS
|
451 |
m_SRS = xml.getStringProperty("srs");
|
452 |
|
453 |
String claseStr = StatusLayerRaster.defaultClass;
|
454 |
if (xml.contains("raster.class")) { |
455 |
claseStr = xml.getStringProperty("raster.class");
|
456 |
} |
457 |
|
458 |
// Transparency
|
459 |
if (xml.contains("wms_transparency")) |
460 |
wmsTransparency = xml.getBooleanProperty("wms_transparency");
|
461 |
|
462 |
// Styles
|
463 |
if (xml.contains("styles")){ |
464 |
styles = new Vector(); |
465 |
String[] stl = xml.getStringProperty("styles").split(","); |
466 |
|
467 |
for (int i = 0; i < stl.length; i++) { |
468 |
if (stl[i].equals(" ")) |
469 |
stl[i]="";
|
470 |
styles.add(stl[i]); |
471 |
} |
472 |
} |
473 |
|
474 |
// Dimensions
|
475 |
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 |
if (dims[i].equals(" ")) |
480 |
dims[i]="";
|
481 |
|
482 |
dimensions.add(dims[i]); |
483 |
} |
484 |
} |
485 |
|
486 |
// 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 |
|
496 |
// 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 |
|
501 |
// fixedSize
|
502 |
if (xml.contains("fixedSize")) { |
503 |
fixedSize = new Dimension(xml.getIntProperty("fixedWidth"), |
504 |
xml.getIntProperty("fixedHeight"));
|
505 |
} |
506 |
|
507 |
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 |
} |
528 |
} |
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 |
public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancellable) throws DriverException { |
537 |
XMLItem[] item = new XMLItem[1]; |
538 |
try {
|
539 |
if (queryable)
|
540 |
{ |
541 |
//TODO
|
542 |
// check if there are layers which are not queryable
|
543 |
ViewPort viewPort = getMapContext().getViewPort(); |
544 |
|
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 |
|
555 |
ViewPort vp = tiles.getTileViewPort(viewPort, tileIndex); |
556 |
wmsStatus.setExtent(vp.getAdjustedExtent()); |
557 |
wmsStatus.setHeight(vp.getImageHeight()); |
558 |
wmsStatus.setWidth(vp.getImageWidth()); |
559 |
wmsStatus.setOnlineResource((String) onlineResources.get("GetFeatureInfo")); |
560 |
|
561 |
//This is in the case we call layer.getInfo outside the info tool.
|
562 |
if (wmsStatus.getSrs() == null){ |
563 |
wmsStatus.setSrs(this.m_SRS);
|
564 |
} |
565 |
if(wmsStatus.getFormat() == null){ |
566 |
wmsStatus.setFormat(this.m_Format);
|
567 |
} |
568 |
if(wmsStatus.getLayerNames().isEmpty()){
|
569 |
wmsStatus.addLayerName(this.getLayerQuery());
|
570 |
} |
571 |
|
572 |
MyCancellable c = new MyCancellable(cancellable);
|
573 |
item[0] = new StringXMLItem(new String(getDriver() |
574 |
.getFeatureInfo(wmsStatus, (int) tiledPoint.getX(), (int) tiledPoint.getY(), Integer.MAX_VALUE, c)),this); |
575 |
return item;
|
576 |
} |
577 |
else
|
578 |
{ |
579 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),this.getName() + " " + |
580 |
PluginServices.getText(this,"layer_not_queryable")); |
581 |
item[0] = new StringXMLItem("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><info></info>",this); |
582 |
return item;
|
583 |
//return null;
|
584 |
} |
585 |
} catch (WMSException e) {
|
586 |
item[0] = new StringXMLItem("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><exception>" + |
587 |
e.getMessage() + "</exception>", this); |
588 |
return item;
|
589 |
} |
590 |
/*azabala
|
591 |
catch (ValidationException e) {
|
592 |
throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
|
593 |
} catch (UnsupportedVersionException e) {
|
594 |
throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
|
595 |
} catch (IOException e) {
|
596 |
throw new DriverException(PluginServices.getText(this, "connect_error"), e);
|
597 |
}
|
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 |
NotificationManager.addError("NotinvertibleTransform", e);
|
638 |
} |
639 |
return null; |
640 |
} |
641 |
|
642 |
/**
|
643 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
644 |
*/
|
645 |
public Rectangle2D getFullExtent() { |
646 |
return fullExtent;
|
647 |
} |
648 |
|
649 |
/**
|
650 |
*
|
651 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage,
|
652 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
|
653 |
* com.iver.cit.gvsig.fmap.operations.Cancellable)
|
654 |
*/
|
655 |
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 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
658 |
Cancellable cancel,double scale) throws DriverException { |
659 |
callCount = 0; // mess code |
660 |
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 |
|
671 |
|
672 |
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 |
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 |
} |
692 |
}else
|
693 |
drawTile(g, viewPort, cancel); |
694 |
} |
695 |
} |
696 |
} |
697 |
|
698 |
private void drawFixedSize(Graphics2D g, ViewPort vp, Cancellable cancel) throws DriverException { |
699 |
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 |
// This is the extent that will be requested
|
705 |
Rectangle2D bBox = getFullExtent();
|
706 |
MyCancellable c = new MyCancellable(cancel);
|
707 |
|
708 |
try {
|
709 |
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 |
File f = getDriver().getMap(wmsStatus, c);
|
720 |
if (f == null) |
721 |
return;
|
722 |
String nameWorldFile = f.getPath() + getExtensionWorldFile();
|
723 |
com.iver.andami.Utilities.createTemp(nameWorldFile, this.getDataWorldFile(bBox, fixedSize));
|
724 |
|
725 |
if(status!=null && firstLoad){ |
726 |
status.applyStatus(this);
|
727 |
firstLoad = false;
|
728 |
} |
729 |
|
730 |
// 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 |
|
735 |
ViewPortData vpData = new ViewPortData(
|
736 |
vp.getProjection(), new Extent(extent), fixedSize );
|
737 |
vpData.setMat(vp.getAffineTransform()); |
738 |
|
739 |
rasterProcess(g, vpData, f); |
740 |
|
741 |
} catch (ValidationException e) {
|
742 |
if (!c.isCanceled())
|
743 |
{ |
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 |
} catch (UnsupportedVersionException e) {
|
760 |
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 |
} catch (IOException e) { |
773 |
if (!c.isCanceled())
|
774 |
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 |
|
781 |
if (callCount == 1) { // mess code |
782 |
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 |
} // mess code
|
793 |
|
794 |
|
795 |
} catch (WMSException e) {
|
796 |
if (!c.isCanceled()) {
|
797 |
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 |
// 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 |
if (!isPrinting)
|
813 |
this.setVisible(false); |
814 |
throw new DriverException("Error WMS", e, type); |
815 |
|
816 |
|
817 |
} // mess code
|
818 |
} |
819 |
} |
820 |
callCount--; // mess code
|
821 |
} |
822 |
|
823 |
/**
|
824 |
* This is the method used to draw a tile in a WMS mosaic layer.
|
825 |
*/
|
826 |
private void drawTile(Graphics2D g, ViewPort vp, Cancellable cancel) throws DriverException { |
827 |
callCount++; |
828 |
// Compute the query geometry
|
829 |
// 1. Check if it is within borders
|
830 |
Rectangle2D extent = getFullExtent();
|
831 |
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 |
return;
|
836 |
} |
837 |
|
838 |
// 2. Compute extent to be requested.
|
839 |
Rectangle2D bBox = new Rectangle2D.Double(); |
840 |
Rectangle2D.intersect(vp.getAdjustedExtent(), extent, bBox);
|
841 |
|
842 |
// 3. Compute size in pixels
|
843 |
double scalex = vp.getAffineTransform().getScaleX();
|
844 |
double scaley = vp.getAffineTransform().getScaleY();
|
845 |
int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1); |
846 |
int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1); |
847 |
|
848 |
// 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 |
Dimension sz = new Dimension(wImg, hImg); |
870 |
|
871 |
if ((wImg <= 0) || (hImg <= 0)) { |
872 |
return;
|
873 |
} |
874 |
MyCancellable c = new MyCancellable(cancel);
|
875 |
|
876 |
try {
|
877 |
// wImg = vp.getImageWidth();
|
878 |
// hImg = vp.getImageHeight();
|
879 |
sz = new Dimension(wImg, hImg); |
880 |
Rectangle2D.intersect(vp.getAdjustedExtent(), extent, bBox);
|
881 |
|
882 |
|
883 |
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 |
|
894 |
// begin patch; Avoid to request too small tiles.
|
895 |
// This generally occurs when printing
|
896 |
|
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 |
File f = getDriver().getMap(wmsStatus, c);
|
921 |
if (f == null) |
922 |
return;
|
923 |
String nameWordFile = f.getPath() + getExtensionWorldFile();
|
924 |
com.iver.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz));
|
925 |
|
926 |
ViewPortData vpData = new ViewPortData(
|
927 |
vp.getProjection(), new Extent(bBox), sz );
|
928 |
vpData.setMat(vp.getAffineTransform()); |
929 |
|
930 |
rasterProcess(g, vpData, f); |
931 |
|
932 |
} catch (ValidationException e) {
|
933 |
//azabala
|
934 |
// if (!c.isCanceled())
|
935 |
// throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
|
936 |
|
937 |
if (!c.isCanceled())
|
938 |
{ |
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 |
} catch (UnsupportedVersionException e) {
|
954 |
|
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 |
} catch (IOException e) { |
971 |
/*azabala
|
972 |
if (!c.isCanceled())
|
973 |
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 |
drawTile(g, vp, cancel);
|
978 |
}
|
979 |
if (callCount == 1) {
|
980 |
throw new DriverException(PluginServices.getText(this, "connect_error"), e);
|
981 |
}
|
982 |
*/
|
983 |
if (!c.isCanceled()){
|
984 |
if (callCount<MAX_RETRY_TIMES) { // mess code |
985 |
NotificationManager.addWarning("\n[ FLyrWMS.drawTileSize() ] Failed in trying " + callCount + "/" + MAX_RETRY_TIMES + ")\n", null); // mess code |
986 |
// 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 |
drawTile(g, vp, cancel); // mess code
|
991 |
} // 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 |
} catch (WMSException e) {
|
1004 |
/*azabala
|
1005 |
if (!c.isCanceled()) {
|
1006 |
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 |
if (!isPrinting) {
|
1014 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
|
1015 |
this.setVisible(false);
|
1016 |
}
|
1017 |
}
|
1018 |
}
|
1019 |
*/
|
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 |
callCount--; |
1045 |
} |
1046 |
|
1047 |
/**
|
1048 |
* Obtiene la extensi?n del fichero de georreferenciaci?n
|
1049 |
* @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
|
1050 |
* del valor del formato obtenido del servidor. Por defecto asignaremos un .wld
|
1051 |
*/
|
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 |
|
1061 |
/**
|
1062 |
* 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 |
* @throws IOException
|
1067 |
*/
|
1068 |
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 |
data.append("-"+(bBox.getMaxY() - bBox.getMinY())/(sz.getHeight() - 1)+"\n"); |
1074 |
data.append(""+bBox.getMinX()+"\n"); |
1075 |
data.append(""+bBox.getMaxY()+"\n"); |
1076 |
return data.toString();
|
1077 |
} |
1078 |
|
1079 |
/**
|
1080 |
* 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 |
private void rasterProcess(Graphics2D g, ViewPortData vpData, File file) throws DriverException { |
1086 |
|
1087 |
//Creamos el PxRaster
|
1088 |
try {
|
1089 |
rasterFile = new GdalFile(vpData.getProjection(), file.getAbsolutePath());
|
1090 |
} catch (NotSupportedExtensionException e) {
|
1091 |
throw new DriverException("Open File Error"); |
1092 |
} |
1093 |
raster = new PxRaster(rasterFile, null, rasterFile.getExtent()); |
1094 |
grid = new Grid(rasterFile);
|
1095 |
grid.addRenderizer(raster); |
1096 |
|
1097 |
if(status != null && firstLoad){ |
1098 |
status.applyStatus(this);
|
1099 |
firstLoad = false;
|
1100 |
} |
1101 |
|
1102 |
//Recuperamos la pila de filtros si ya hubiese sido cargado antes
|
1103 |
if(this.filterStack!=null) |
1104 |
raster.filterStack = this.filterStack;
|
1105 |
|
1106 |
raster.setTransparency(false);
|
1107 |
|
1108 |
//Asignamos transparencia y orden de bandas
|
1109 |
if(this.transparency == -1 && !firstLoad); |
1110 |
else
|
1111 |
raster.setTransparency(this.transparency);
|
1112 |
|
1113 |
raster.setBand(GeoRasterFile.RED_BAND,rband); |
1114 |
raster.setBand(GeoRasterFile.GREEN_BAND, gband); |
1115 |
raster.setBand(GeoRasterFile.BLUE_BAND, bband); |
1116 |
|
1117 |
//Despues del primer pxRaster asignamos el stackManager guardado para los siguientes.
|
1118 |
//Con esto conseguimos asignar los cambios que se hayan producido desde el cuadro de
|
1119 |
//propiedades cuando creamos un nuevo pxRaster
|
1120 |
if(this.stackManager != null) |
1121 |
raster.setStackManager(this.stackManager);
|
1122 |
|
1123 |
if(visualStatus != null){ |
1124 |
visualStatus.bandCount = raster.getBandCount(); |
1125 |
visualStatus.dataType = raster.getDataType(); |
1126 |
} |
1127 |
|
1128 |
raster.draw(g, vpData); |
1129 |
|
1130 |
//En el primer pxRaster de una imagen obtenemos el Stack Manager para poder modificarlo
|
1131 |
//si queremos desde las propiedades
|
1132 |
|
1133 |
if(this.stackManager == null) |
1134 |
this.stackManager = raster.getStackManager();
|
1135 |
|
1136 |
if(this.filterStack == null) |
1137 |
this.filterStack = raster.filterStack;
|
1138 |
|
1139 |
//rasterFile.close();
|
1140 |
} |
1141 |
|
1142 |
/**
|
1143 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
1144 |
* com.iver.cit.gvsig.fmap.ViewPort,
|
1145 |
* com.iver.cit.gvsig.fmap.operations.Cancellable)
|
1146 |
*/
|
1147 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties) |
1148 |
throws DriverException {
|
1149 |
if (isVisible() && isWithinScale(scale)){
|
1150 |
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 |
// Llamamos a drawView con cuadraditos m?s peque?os
|
1157 |
// del BufferedImage ni caso, cuando se imprime viene con null
|
1158 |
|
1159 |
Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipBounds());
|
1160 |
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 |
drawTile(g, vp, cancel); |
1166 |
} catch (NoninvertibleTransformException e) { |
1167 |
e.printStackTrace(); |
1168 |
} |
1169 |
} |
1170 |
} |
1171 |
isPrinting = false;
|
1172 |
} |
1173 |
} |
1174 |
|
1175 |
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 |
throws IllegalStateException, ValidationException, |
1192 |
UnsupportedVersionException, IOException {
|
1193 |
return FMapWMSDriverFactory.getFMapDriverForURL(host);
|
1194 |
} |
1195 |
|
1196 |
/**
|
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 |
* Inserta la informaci?n de la consulta.
|
1239 |
*
|
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 |
* Inserta la extensi?n total de la capa.
|
1302 |
*
|
1303 |
* @param fullExtent Rect?ngulo.
|
1304 |
*/
|
1305 |
public void setFullExtent(Rectangle2D fullExtent) { |
1306 |
this.fullExtent = fullExtent;
|
1307 |
} |
1308 |
|
1309 |
public HashMap getProperties() { |
1310 |
HashMap info = new HashMap(); |
1311 |
String[] layerNames = getLayerQuery().split(","); |
1312 |
Vector layers = new Vector(layerNames.length); |
1313 |
try {
|
1314 |
if(getDriver().connect(null)){ |
1315 |
for (int i = 0; i < layerNames.length; i++) { |
1316 |
layers.add(i, getDriver().getLayer(layerNames[i])); |
1317 |
} |
1318 |
info.put("name", getName());
|
1319 |
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 |
info.put("fixedSize", fixedSize);
|
1327 |
return info;
|
1328 |
} |
1329 |
} catch (Exception e) { |
1330 |
e.printStackTrace(); |
1331 |
} |
1332 |
return null; |
1333 |
} |
1334 |
|
1335 |
/**
|
1336 |
* Asignar el estado del raster
|
1337 |
* @param status
|
1338 |
*/
|
1339 |
public void setStatus(StatusRasterInterface status){ |
1340 |
this.status = status;
|
1341 |
} |
1342 |
|
1343 |
/**
|
1344 |
* Obtiene el estado del raster
|
1345 |
* @return
|
1346 |
*/
|
1347 |
public StatusRasterInterface getStatus(){
|
1348 |
return this.status; |
1349 |
} |
1350 |
|
1351 |
/* (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 |
String dataType = "Byte"; |
1358 |
if (rasterFile.getDataType() == DataBuffer.TYPE_BYTE) dataType = "Byte"; |
1359 |
else if (visualStatus.dataType == DataBuffer.TYPE_SHORT) |
1360 |
dataType = "Short";
|
1361 |
else if (visualStatus.dataType == DataBuffer.TYPE_USHORT) |
1362 |
dataType = "Unsigned Short";
|
1363 |
else if (visualStatus.dataType == DataBuffer.TYPE_INT) |
1364 |
dataType = "Integer";
|
1365 |
else if (visualStatus.dataType == DataBuffer.TYPE_FLOAT) |
1366 |
dataType = "Float";
|
1367 |
else if (visualStatus.dataType == DataBuffer.TYPE_DOUBLE) |
1368 |
dataType = "Double";
|
1369 |
else
|
1370 |
dataType = "Unknown";
|
1371 |
|
1372 |
Object [][] a = { |
1373 |
{"Filename",rasterFile.getName().substring(rasterFile.getName().lastIndexOf("/")+1, rasterFile.getName().length())}, |
1374 |
{"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 |
}; |
1380 |
for (int i=0; i<a.length; i++) |
1381 |
attr.add(a[i]); |
1382 |
|
1383 |
return attr;
|
1384 |
} |
1385 |
return null; |
1386 |
} |
1387 |
|
1388 |
/* (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 |
return visualStatus.height;
|
1401 |
} |
1402 |
|
1403 |
/* (non-Javadoc)
|
1404 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxX()
|
1405 |
*/
|
1406 |
public double getMaxX() { |
1407 |
return visualStatus.maxX;
|
1408 |
} |
1409 |
|
1410 |
/* (non-Javadoc)
|
1411 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxY()
|
1412 |
*/
|
1413 |
public double getMaxY() { |
1414 |
return visualStatus.maxY;
|
1415 |
} |
1416 |
|
1417 |
/* (non-Javadoc)
|
1418 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinX()
|
1419 |
*/
|
1420 |
public double getMinX() { |
1421 |
return visualStatus.minX;
|
1422 |
} |
1423 |
|
1424 |
/* (non-Javadoc)
|
1425 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinY()
|
1426 |
*/
|
1427 |
public double getMinY() { |
1428 |
return visualStatus.minY;
|
1429 |
} |
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 |
return visualStatus.width;
|
1449 |
} |
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 |
|
1474 |
/* (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 |
|
1482 |
/* (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 |
|
1508 |
public void setTransparency(int trans) { |
1509 |
this.transparency = trans;
|
1510 |
} |
1511 |
|
1512 |
/**
|
1513 |
* Sets the R-band.
|
1514 |
*
|
1515 |
* Asigna la banda R.
|
1516 |
* @param r
|
1517 |
*/
|
1518 |
public void setBandR(int r){ |
1519 |
this.rband = r;
|
1520 |
} |
1521 |
|
1522 |
/**
|
1523 |
* Sets the G-band.
|
1524 |
*
|
1525 |
* Asigna la banda G
|
1526 |
* @param g
|
1527 |
*/
|
1528 |
public void setBandG(int g){ |
1529 |
this.gband = g;
|
1530 |
} |
1531 |
|
1532 |
/**
|
1533 |
* Sets the B-band.
|
1534 |
*
|
1535 |
* 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 |
public boolean isWmsTransparent() { |
1546 |
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 |
/**
|
1557 |
* @param styles
|
1558 |
*/
|
1559 |
public void setStyles(Vector styles) { |
1560 |
this.styles = styles;
|
1561 |
//laura:
|
1562 |
//layer query is built with the layer in reverse order
|
1563 |
// so here we build the styles upside-down.
|
1564 |
// 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 |
} |
1573 |
|
1574 |
/**
|
1575 |
* 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 |
* @param dimensions
|
1578 |
*/
|
1579 |
public void setDimensions(Vector dimensions) { |
1580 |
this.dimensions = dimensions;
|
1581 |
} |
1582 |
|
1583 |
/**
|
1584 |
* Sets the set of URLs that should be accessed for each operation performed
|
1585 |
* to the server.
|
1586 |
*
|
1587 |
* @param onlineResources
|
1588 |
*/
|
1589 |
public void setOnlineResources(Hashtable onlineResources) { |
1590 |
this.onlineResources = onlineResources;
|
1591 |
} |
1592 |
|
1593 |
/**
|
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 |
/**
|
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 |
|
1613 |
/**
|
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 |
|
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 |
* @throws UnsupportedVersionException
|
1637 |
*/
|
1638 |
public String toMapContext(String mapContextVersion) { |
1639 |
XmlBuilder xml = new XmlBuilder();
|
1640 |
FMapWMSDriver drv; |
1641 |
try {
|
1642 |
drv = getDriver(); |
1643 |
} catch (Exception e) { |
1644 |
return xml.toString();
|
1645 |
} |
1646 |
String[] layerNames = getLayerQuery().split(","); |
1647 |
String[] styleNames = (String[]) styles.toArray(new String[0]); |
1648 |
for (int i = 0; i < layerNames.length; i++) { |
1649 |
WMSLayerNode layer = drv.getLayer(layerNames[i]); |
1650 |
HashMap xmlAttrs = new HashMap(); |
1651 |
|
1652 |
// <Layer>
|
1653 |
xmlAttrs.put(WebMapContextTags.HIDDEN, !isVisible()+"");
|
1654 |
xmlAttrs.put(WebMapContextTags.QUERYABLE, queryable+"");
|
1655 |
xml.openTag(WebMapContextTags.LAYER, xmlAttrs); |
1656 |
xmlAttrs.clear(); |
1657 |
if (mapContextVersion.equals("1.1.0") || mapContextVersion.equals("1.0.0")) { |
1658 |
// <Server>
|
1659 |
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 |
xmlAttrs.clear(); |
1664 |
|
1665 |
// <OnlineResource>
|
1666 |
xmlAttrs.put(WebMapContextTags.XLINK_TYPE, "simple");
|
1667 |
xmlAttrs.put(WebMapContextTags.XLINK_HREF, getHost().toString()); |
1668 |
xml.writeTag(WebMapContextTags.ONLINE_RESOURCE, xmlAttrs); |
1669 |
xmlAttrs.clear(); |
1670 |
// </OnlineResource>
|
1671 |
|
1672 |
xml.closeTag(); |
1673 |
// </Server>
|
1674 |
|
1675 |
// <Name>
|
1676 |
xml.writeTag(WebMapContextTags.NAME, layer.getName().trim()); |
1677 |
// </Name>
|
1678 |
|
1679 |
// <Title>
|
1680 |
xml.writeTag(WebMapContextTags.TITLE, layer.getTitle().trim()); |
1681 |
//?xml.writeTag(WebMapContextTags.TITLE, getName().trim());
|
1682 |
// </Title>
|
1683 |
|
1684 |
// <Abstract>
|
1685 |
if (layer.getAbstract() != null) |
1686 |
xml.writeTag(WebMapContextTags.ABSTRACT, layer.getAbstract()); |
1687 |
// </Abstract>
|
1688 |
|
1689 |
// <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 |
xml.writeTag(WebMapContextTags.SRS, mySRS); |
1696 |
// </SRS>
|
1697 |
|
1698 |
// <FormatList>
|
1699 |
xml.openTag(WebMapContextTags.FORMAT_LIST); |
1700 |
strings = (String[]) drv.getFormats().toArray(new String[0]); |
1701 |
for (int j = 0; j < strings.length; j++) { |
1702 |
// <Format>
|
1703 |
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 |
// </Format>
|
1709 |
} |
1710 |
xml.closeTag(); |
1711 |
// </FormatList>
|
1712 |
|
1713 |
// <StyleList>
|
1714 |
xml.openTag(WebMapContextTags.STYLE_LIST); |
1715 |
|
1716 |
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 |
if (st.name.equals(styleNames[i]))
|
1721 |
xmlAttrs.put(WebMapContextTags.CURRENT, "1");
|
1722 |
xml.openTag(WebMapContextTags.STYLE, xmlAttrs); |
1723 |
xmlAttrs.clear(); |
1724 |
|
1725 |
// <Name>
|
1726 |
xml.writeTag(WebMapContextTags.NAME, st.name); |
1727 |
// </Name>
|
1728 |
|
1729 |
// <Title>
|
1730 |
xml.writeTag(WebMapContextTags.TITLE, st.title); |
1731 |
// </Title>
|
1732 |
|
1733 |
// <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 |
|
1740 |
} |
1741 |
|
1742 |
} else {
|
1743 |
// Create fake style (for compatibility issues)
|
1744 |
xmlAttrs.put(WebMapContextTags.CURRENT, "1");
|
1745 |
// <Style>
|
1746 |
xml.openTag(WebMapContextTags.STYLE, xmlAttrs); |
1747 |
xmlAttrs.clear(); |
1748 |
// <Name>
|
1749 |
xml.writeTag(WebMapContextTags.NAME, "default");
|
1750 |
// </Name>
|
1751 |
|
1752 |
// <Title>
|
1753 |
xml.writeTag(WebMapContextTags.TITLE, "default");
|
1754 |
// </Title>
|
1755 |
|
1756 |
// // <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 |
// </Style>
|
1770 |
xml.closeTag(); |
1771 |
} |
1772 |
// </StyleList>
|
1773 |
xml.closeTag(); |
1774 |
if (mapContextVersion.compareTo("1.0.0") > 0) { |
1775 |
// <DimensionList>
|
1776 |
xml.openTag(WebMapContextTags.DIMENSION_LIST); |
1777 |
// <Dimension>
|
1778 |
// </Dimension>
|
1779 |
xml.closeTag(); |
1780 |
// </DimensionList>
|
1781 |
} |
1782 |
} else {
|
1783 |
xml.writeTag("ERROR", PluginServices.getText(this, "unsupported_map_context_version")); |
1784 |
} |
1785 |
// </Layer>
|
1786 |
xml.closeTag(); |
1787 |
} |
1788 |
return xml.getXML();
|
1789 |
} |
1790 |
|
1791 |
public ImageIcon getTocImageIcon() { |
1792 |
return new ImageIcon(PluginServices.getPluginServices("com.iver.cit.gvsig.wms").getClassLoader().getResource("images/icoLayer.png")); |
1793 |
} |
1794 |
|
1795 |
/*
|
1796 |
* (non-Javadoc)
|
1797 |
* @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
|
1798 |
*/
|
1799 |
public int[] getTileSize() { |
1800 |
int[] size = {maxTileDrawWidth, maxTileDrawHeight}; |
1801 |
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 |
|
1811 |
public Image getImageLegend() { |
1812 |
try {
|
1813 |
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 |
Image img = null; |
1822 |
if ((path != null) && (path.length() > 0)) |
1823 |
img = new ImageIcon(path).getImage(); |
1824 |
return img;
|
1825 |
} |
1826 |
} 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 |
}catch(Exception e){ |
1836 |
//e.printStackTrace();
|
1837 |
return null; |
1838 |
} |
1839 |
} |
1840 |
|
1841 |
/**
|
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 |
|
1849 |
/**
|
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 |
public boolean isQueryable(){ |
1857 |
return queryable;
|
1858 |
} |
1859 |
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 |
} |