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