svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wms / WMSLayer.java @ 40559
History | View | Annotate | Download (14.4 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.remoteclient.wms; |
25 |
|
26 |
import java.io.IOException; |
27 |
import java.util.ArrayList; |
28 |
import java.util.Hashtable; |
29 |
import java.util.TreeMap; |
30 |
import java.util.Vector; |
31 |
|
32 |
import org.kxml2.io.KXmlParser; |
33 |
import org.xmlpull.v1.XmlPullParserException; |
34 |
|
35 |
import org.gvsig.remoteclient.utils.BoundaryBox; |
36 |
import org.gvsig.remoteclient.utils.CapabilitiesTags; |
37 |
|
38 |
/**
|
39 |
* <p>Abstract class that defines an WMSLayer.</p>
|
40 |
*
|
41 |
*/
|
42 |
public abstract class WMSLayer implements org.gvsig.remoteclient.ILayer { |
43 |
|
44 |
protected ArrayList children; |
45 |
protected WMSLayer parent;
|
46 |
|
47 |
/**
|
48 |
* <p>Layer Abstract field in the capabilities document </p>
|
49 |
*/
|
50 |
private String layerAbstract; |
51 |
|
52 |
/**
|
53 |
* <p>Themes provided by the WMS for the layer</p>
|
54 |
*/
|
55 |
public ArrayList styles = new ArrayList(); |
56 |
|
57 |
/**
|
58 |
* <p>Layer name</p>
|
59 |
*/
|
60 |
private String name; |
61 |
|
62 |
/**
|
63 |
* <p>Layer title</p>
|
64 |
*/
|
65 |
private String title; |
66 |
|
67 |
private ArrayList keywordList = new ArrayList(); |
68 |
/**
|
69 |
* <p>Layer srs.</p>
|
70 |
*/
|
71 |
protected Vector srs = new Vector(); |
72 |
|
73 |
/**
|
74 |
* <p>extents for each srs the layer can be reproyected to</p>
|
75 |
*/
|
76 |
private Hashtable bBoxes = new Hashtable(); |
77 |
|
78 |
/**
|
79 |
* <p>extents that defines the bbox for the LatLon projection
|
80 |
* It can be included in the bBoxes vector as well, because it is the most used, we keep it separeted too, according
|
81 |
* with the OGC WMSCapabilities specifications...
|
82 |
*/
|
83 |
private org.gvsig.remoteclient.utils.BoundaryBox latLonBbox;
|
84 |
|
85 |
/**
|
86 |
* <p>min scale for the layer to be visible</p>
|
87 |
*/
|
88 |
private double scaleMin; |
89 |
|
90 |
/**
|
91 |
* <p>max scale for the layer to be visible</p>
|
92 |
*/
|
93 |
private double scaleMax; |
94 |
|
95 |
/**
|
96 |
* <p>Dimensions defined for the layer in the capabilities doc</p>
|
97 |
*/
|
98 |
protected java.util.ArrayList dimensions = new ArrayList(); |
99 |
|
100 |
/**
|
101 |
* Tells if this layer accepts getFeatureInfo requests.
|
102 |
*/
|
103 |
private boolean queryable = false; |
104 |
|
105 |
/**
|
106 |
* Tells if this layer is opaque.
|
107 |
*/
|
108 |
private boolean opaque = false; |
109 |
/**
|
110 |
* when set to true, noSubsets indicates that the server is not able to make a map
|
111 |
* of a geographic area other than the layer's bounding box.
|
112 |
*/
|
113 |
private boolean m_noSubSets = false; |
114 |
|
115 |
/**
|
116 |
* when present and non-zero fixedWidth and fixedHeight indicate that the server is not
|
117 |
* able to produce a map of the layer at a width and height different from the fixed sizes indicated.
|
118 |
*/
|
119 |
private int fixedWidth = 0; |
120 |
private int fixedHeight = 0; |
121 |
|
122 |
/**
|
123 |
* Tells if this layer can be served with transparency.
|
124 |
*/
|
125 |
private boolean transparency; |
126 |
|
127 |
/**
|
128 |
* <p>Parses the LAYER tag in the WMS capabilities, filling the WMSLayer object
|
129 |
* loading the data in memory to be easily accesed</p>
|
130 |
*
|
131 |
*/
|
132 |
public abstract void parse(KXmlParser parser, TreeMap layerTreeMap) |
133 |
throws IOException, XmlPullParserException; |
134 |
|
135 |
//public abstract ArrayList getAllDimensions();
|
136 |
|
137 |
/**
|
138 |
* add a new keyword to the keywordList.
|
139 |
* @param key
|
140 |
*/
|
141 |
protected void addkeyword(String key) |
142 |
{ |
143 |
keywordList.add(key); |
144 |
} |
145 |
public ArrayList getKeywords() |
146 |
{ |
147 |
return keywordList;
|
148 |
} |
149 |
/**
|
150 |
* <p>Adds a style to the styles vector</p>
|
151 |
* @param _style
|
152 |
*/
|
153 |
public void addStyle(org.gvsig.remoteclient.wms.WMSStyle _style) { |
154 |
styles.add( _style ); } |
155 |
|
156 |
/**
|
157 |
* <p>Gets the style vector</p>
|
158 |
* @return
|
159 |
*/
|
160 |
public ArrayList getStyles() { |
161 |
ArrayList list = new ArrayList(); |
162 |
if (styles != null) |
163 |
list.addAll(styles); |
164 |
if (this.getParent()!= null) |
165 |
{ |
166 |
//return getAllStyles(this);
|
167 |
if(this.getParent().getStyles() != null) |
168 |
list.addAll(this.getParent().getStyles());
|
169 |
} |
170 |
return list;
|
171 |
} |
172 |
|
173 |
public ArrayList getAllStyles(WMSLayer layer) |
174 |
{ |
175 |
if (layer.getParent()!= null) |
176 |
{ |
177 |
ArrayList list = getAllStyles(layer.getParent());
|
178 |
for(int i = 0; i < this.styles.size(); i++) |
179 |
{ |
180 |
list.add(styles.get(i)); |
181 |
} |
182 |
return list;
|
183 |
} |
184 |
else
|
185 |
{ |
186 |
return styles;
|
187 |
} |
188 |
} |
189 |
/**
|
190 |
* <p>Adds a bbox to the Bboxes vector</p>
|
191 |
* @param bbox
|
192 |
*/
|
193 |
public void addBBox(BoundaryBox bbox) { |
194 |
bBoxes.put(bbox.getSrs(), bbox); |
195 |
} |
196 |
|
197 |
/**
|
198 |
* <p>returns the bbox with that id in the Bboxes vector</p>
|
199 |
* @param id
|
200 |
*/
|
201 |
public BoundaryBox getBbox(String id) { |
202 |
if ((id.compareToIgnoreCase( CapabilitiesTags.EPSG_4326 )==0) |
203 |
||(id.compareToIgnoreCase( CapabilitiesTags.CRS_84)==0))
|
204 |
{ |
205 |
if (latLonBbox != null) |
206 |
return (BoundaryBox)latLonBbox;
|
207 |
} |
208 |
BoundaryBox b = (BoundaryBox) bBoxes.get(id); |
209 |
if (b == null && parent!=null) |
210 |
return parent.getBbox(id);
|
211 |
return (BoundaryBox)bBoxes.get(id);
|
212 |
} |
213 |
|
214 |
/**
|
215 |
* <p>Gets the bBoxes vector</p>
|
216 |
* @return
|
217 |
*/
|
218 |
public Hashtable getBboxes() { |
219 |
return bBoxes;
|
220 |
} |
221 |
|
222 |
|
223 |
//Methods to manipulate the box that defines the layer extent in LatLon SRS.
|
224 |
public BoundaryBox getLatLonBox()
|
225 |
{ |
226 |
return latLonBbox;
|
227 |
} |
228 |
public void setLatLonBox(BoundaryBox box) |
229 |
{ |
230 |
latLonBbox = box; |
231 |
} |
232 |
/**
|
233 |
* <p>adds a new srs to the srs vector</p>
|
234 |
*/
|
235 |
public void addSrs(String srs) |
236 |
{ |
237 |
if (!this.srs.contains(srs)) |
238 |
this.srs.add(srs);
|
239 |
} |
240 |
|
241 |
public Vector getAllSrs() |
242 |
{ |
243 |
Vector mySRSs = (Vector) this.srs.clone(); |
244 |
if (parent!=null) |
245 |
mySRSs.addAll(parent.getAllSrs()); |
246 |
return mySRSs;
|
247 |
|
248 |
// if (this.getParent()!= null)
|
249 |
// {
|
250 |
// Vector list = this.getParent().getAllSrs();
|
251 |
// for(int i = 0; i < this.srs.size(); i++)
|
252 |
// {
|
253 |
// list.add(srs.get(i));
|
254 |
// }
|
255 |
// return list;
|
256 |
// }
|
257 |
// else
|
258 |
// {
|
259 |
// return srs;
|
260 |
// }
|
261 |
|
262 |
} |
263 |
/**
|
264 |
* <p>gets the maximum scale for this layer</p>
|
265 |
* @return
|
266 |
*/
|
267 |
public double getScaleMax() { |
268 |
return scaleMax;
|
269 |
} |
270 |
|
271 |
/**
|
272 |
* <p>gets the minimum scale for this layer</p>
|
273 |
* @return
|
274 |
*/
|
275 |
public double getScaleMin() { |
276 |
return scaleMin;
|
277 |
} |
278 |
|
279 |
/**
|
280 |
* <p>sets the minimum scale for this layer to be visible.</p>
|
281 |
*
|
282 |
* @param scale
|
283 |
*/
|
284 |
public void setScaleMin(double scale) { |
285 |
scaleMin = scale; |
286 |
} |
287 |
|
288 |
/**
|
289 |
* <p>sets the maximum scale for this layer to be visible</p>
|
290 |
* @param scale
|
291 |
*/
|
292 |
public void setScaleMax(double scale) { |
293 |
scaleMax = scale; |
294 |
} |
295 |
|
296 |
/**
|
297 |
* <p> gets the dimension vector defined in this layer</p>
|
298 |
* @return
|
299 |
*/
|
300 |
public abstract ArrayList getDimensions(); |
301 |
// public ArrayList getDimensions() {
|
302 |
// return dimensions;
|
303 |
// }
|
304 |
|
305 |
public WMSDimension getDimension(String name) |
306 |
{ |
307 |
for(int i = 0; i < dimensions.size(); i++ ){ |
308 |
if(((WMSDimension)dimensions.get(i)).getName().compareTo(name)==0) |
309 |
{ |
310 |
return (WMSDimension)dimensions.get(i);
|
311 |
} |
312 |
} |
313 |
return null; |
314 |
} |
315 |
|
316 |
// /**
|
317 |
// * <p>Sets the dimension vector defined for this layer</p>
|
318 |
// * @param v
|
319 |
// */
|
320 |
// public void setDimensions(ArrayList v) {
|
321 |
// dimensions = (ArrayList)v.clone();
|
322 |
// }
|
323 |
|
324 |
/**
|
325 |
* <p>Adds a dimension to the dimension vector </p>
|
326 |
* @param dimension
|
327 |
*/
|
328 |
public void addDimension(org.gvsig.remoteclient.wms.WMSDimension dimension) { |
329 |
dimensions.add(dimension); |
330 |
} |
331 |
|
332 |
/**
|
333 |
* <p>Gets layer name</p>
|
334 |
* @return
|
335 |
*/
|
336 |
public String getName() { |
337 |
return this.name; |
338 |
} |
339 |
|
340 |
/**
|
341 |
* <p>Sets layer name</p>
|
342 |
* @param _name
|
343 |
*/
|
344 |
public void setName(String name) { |
345 |
this.name = name;
|
346 |
} |
347 |
|
348 |
/**
|
349 |
* <p>Gets layer title</p>
|
350 |
* @return
|
351 |
*/
|
352 |
public String getTitle() { |
353 |
return title;
|
354 |
} |
355 |
|
356 |
/**
|
357 |
* <p>Sets the layer title</p>
|
358 |
* @param _title
|
359 |
*/
|
360 |
public void setTitle(String title) { |
361 |
this.title = title;
|
362 |
} |
363 |
|
364 |
/**
|
365 |
* <p>Gets the layer abstract</p>
|
366 |
* @return
|
367 |
*/
|
368 |
public String getAbstract() { |
369 |
return layerAbstract;
|
370 |
} |
371 |
|
372 |
/**
|
373 |
* <p>Sets the layer abstract</p>
|
374 |
* @param m_abstract
|
375 |
*/
|
376 |
public void setAbstract(String _abstract) { |
377 |
layerAbstract = _abstract; |
378 |
} |
379 |
|
380 |
|
381 |
public ArrayList getChildren() { |
382 |
return children;
|
383 |
} |
384 |
|
385 |
|
386 |
public void setChildren(ArrayList children) { |
387 |
this.children = children;
|
388 |
} |
389 |
|
390 |
|
391 |
public WMSLayer getParent() {
|
392 |
return parent;
|
393 |
} |
394 |
|
395 |
|
396 |
public void setParent(WMSLayer parent) { |
397 |
this.parent = parent;
|
398 |
} |
399 |
|
400 |
public String toString(){ |
401 |
return this.getTitle(); |
402 |
} |
403 |
|
404 |
|
405 |
/**
|
406 |
* Tells if this layer accepts getFeatureInfo requests.
|
407 |
*/
|
408 |
public boolean isQueryable() { |
409 |
return queryable;
|
410 |
} |
411 |
|
412 |
|
413 |
/**
|
414 |
* @param queryable The queryable to set.
|
415 |
*/
|
416 |
public void setQueryable(boolean queryable) { |
417 |
this.queryable = queryable;
|
418 |
} |
419 |
|
420 |
/**
|
421 |
* Tells if this layer is opaque.
|
422 |
*/
|
423 |
public boolean isOpaque() { |
424 |
return opaque;
|
425 |
} |
426 |
/**
|
427 |
* @param opaque.
|
428 |
*/
|
429 |
public void setOpaque(boolean opaque) { |
430 |
this.opaque = opaque;
|
431 |
} |
432 |
|
433 |
/**
|
434 |
* Tells if this layer is subsettable
|
435 |
*/
|
436 |
public boolean noSubSets() { |
437 |
return this.m_noSubSets; |
438 |
} |
439 |
/**
|
440 |
* @param set layer nosubsets attribute.
|
441 |
*/
|
442 |
public void setNoSubSets(boolean _noSubSets) { |
443 |
m_noSubSets = _noSubSets; |
444 |
} |
445 |
|
446 |
public void setfixedWidth(int w) { |
447 |
fixedWidth = w; |
448 |
} |
449 |
|
450 |
public int getfixedWidth() { |
451 |
return fixedWidth;
|
452 |
} |
453 |
|
454 |
public void setfixedHeight(int h) { |
455 |
fixedHeight = h; |
456 |
} |
457 |
|
458 |
public int getfixedHeight() { |
459 |
return fixedHeight;
|
460 |
} |
461 |
|
462 |
/**
|
463 |
* @return <b>true</b> if this layer can be served with transparency, otherwise <b>false</b>
|
464 |
*/
|
465 |
public boolean hasTransparency() { |
466 |
return transparency;
|
467 |
} |
468 |
|
469 |
//Methods to parse tags that are common to several versions of WMS.
|
470 |
//In case there is a version which has different implemantation of one of this tags
|
471 |
// the subclass can overwrite this method
|
472 |
|
473 |
/**
|
474 |
* Parses the keywordlist from the capabilities and fills this list in the WMSLayer.
|
475 |
* @param parser
|
476 |
*/
|
477 |
protected void parseKeywordList(KXmlParser parser) throws IOException, XmlPullParserException |
478 |
{ |
479 |
int currentTag;
|
480 |
boolean end = false; |
481 |
String value;
|
482 |
|
483 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.KEYWORDLIST);
|
484 |
currentTag = parser.nextTag(); |
485 |
|
486 |
while (!end)
|
487 |
{ |
488 |
switch(currentTag)
|
489 |
{ |
490 |
case KXmlParser.START_TAG:
|
491 |
if (parser.getName().compareTo(CapabilitiesTags.KEYWORD)==0) |
492 |
{ |
493 |
value = parser.nextText(); |
494 |
if ((value != null) && (value.length() > 0 )) |
495 |
addkeyword(value); |
496 |
} |
497 |
break;
|
498 |
case KXmlParser.END_TAG:
|
499 |
if (parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST) == 0) |
500 |
end = true;
|
501 |
break;
|
502 |
case KXmlParser.TEXT:
|
503 |
break;
|
504 |
} |
505 |
if (!end)
|
506 |
{ |
507 |
currentTag = parser.next(); |
508 |
} |
509 |
} |
510 |
parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.KEYWORDLIST);
|
511 |
} |
512 |
|
513 |
/**
|
514 |
* Reads and parses the layer attributes
|
515 |
* Maybe this method should be moved to the WMSLayer. Until now the attributes are teh same for all versions.
|
516 |
* @param parser
|
517 |
*/
|
518 |
protected void readLayerAttributes(KXmlParser parser) |
519 |
{ |
520 |
String value = new String(); |
521 |
|
522 |
//First of all set whether the layer is Queryable reading the attribute.
|
523 |
value = parser.getAttributeValue("", CapabilitiesTags.QUERYABLE);
|
524 |
if (value != null) |
525 |
{ |
526 |
if (value.compareTo("0")==0) |
527 |
setQueryable(false);
|
528 |
else
|
529 |
setQueryable(true);
|
530 |
} |
531 |
value = parser.getAttributeValue("", CapabilitiesTags.OPAQUE);
|
532 |
if (value != null) |
533 |
{ |
534 |
if (value.compareTo("0")==0) |
535 |
setOpaque(false);
|
536 |
else
|
537 |
setOpaque(true);
|
538 |
} |
539 |
value = parser.getAttributeValue("", CapabilitiesTags.NOSUBSETS);
|
540 |
if (value != null) |
541 |
{ |
542 |
if (value.compareTo("0")==0) |
543 |
setNoSubSets(false);
|
544 |
else
|
545 |
setNoSubSets(true);
|
546 |
} |
547 |
value = parser.getAttributeValue("", CapabilitiesTags.FIXEDWIDTH);
|
548 |
if (value != null) |
549 |
{ |
550 |
setfixedWidth(Integer.parseInt(value));
|
551 |
} |
552 |
value = parser.getAttributeValue("", CapabilitiesTags.FIXEDHEIGHT);
|
553 |
if (value != null) |
554 |
{ |
555 |
setfixedHeight(Integer.parseInt(value));
|
556 |
} |
557 |
} |
558 |
|
559 |
|
560 |
/**
|
561 |
* <p>Inner class describing the MetadataURL tag in OGC specifications in WMS</p>
|
562 |
*
|
563 |
*/
|
564 |
protected class MetadataURL |
565 |
{ |
566 |
public MetadataURL()
|
567 |
{ |
568 |
type = new String(); |
569 |
format = new String(); |
570 |
onlineResource_xlink = new String(); |
571 |
onlineResource_type = new String(); |
572 |
onlineResource_href = new String(); |
573 |
} |
574 |
public String type; |
575 |
public String format; |
576 |
public String onlineResource_xlink; |
577 |
public String onlineResource_type; |
578 |
public String onlineResource_href; |
579 |
} |
580 |
|
581 |
/**
|
582 |
* <p>Inner class describing the DataURL tag in OGC specifications in WMS</p>
|
583 |
*
|
584 |
*/
|
585 |
protected class DataURL |
586 |
{ |
587 |
public DataURL()
|
588 |
{ |
589 |
type = new String(); |
590 |
format = new String(); |
591 |
onlineResource_xlink = new String(); |
592 |
onlineResource_type = new String(); |
593 |
onlineResource_href = new String(); |
594 |
} |
595 |
public String type; |
596 |
public String format; |
597 |
public String onlineResource_xlink; |
598 |
public String onlineResource_type; |
599 |
public String onlineResource_href; |
600 |
} |
601 |
} |