001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: // Changed by Uwe Dalluege, uwe.dalluege@rzcn.haw-hamburg.de
034: // to differ between LatLonBoundingBox and BoundingBox
035: // 2005-07-29
036: package com.vividsolutions.wms;
037:
038: import java.util.*;
039:
040: import com.vividsolutions.jump.util.CollectionUtil;
041:
042: /**
043: * Represents a WMS Layer.
044: *
045: * @author Chris Hodgson chodgson@refractions.net
046: */
047: public class MapLayer {
048:
049: // immutable members
050: private MapLayer parent;
051: private String name;
052: private String title;
053: private ArrayList srsList;
054: private ArrayList subLayers;
055: private BoundingBox bbox;
056:
057: // I think, bbox contains the information about LatLonBoundingBox
058: // (see Parser.java)
059: // I need a new list for <BoundingBox> [uwe dalluege]
060: private ArrayList boundingBoxList;
061:
062: // user modifiable members
063: private boolean enabled = false;
064:
065: /**
066: * Creates a new instance of MapLayer
067: */
068: public MapLayer(String name, String title, Collection srsList,
069: Collection subLayers, BoundingBox bbox) {
070: this .parent = null;
071: this .name = name;
072: this .title = title;
073: this .srsList = new ArrayList(srsList);
074: this .subLayers = new ArrayList(subLayers);
075: Iterator it = subLayers.iterator();
076: while (it.hasNext()) {
077: ((MapLayer) it.next()).parent = this ;
078: }
079: this .bbox = bbox;
080: }
081:
082: // ----------------------------------------------------- MapLayer MapLayer ( )
083: /**
084: * Creates a new instance of MapLayer with boundingBoxList [uwe dalluege]
085: */
086: public MapLayer(String name, String title, Collection srsList,
087: Collection subLayers, BoundingBox bbox,
088: ArrayList boundingBoxList) {
089: this (name, title, srsList, subLayers, bbox);
090: this .boundingBoxList = boundingBoxList;
091: }
092:
093: // ----------------------------------------------------- MapLayer MapLayer ( )
094: // ---------------------------------------- MapLayer getAllBoundingBoxList ( )
095: /**
096: * @return All BoundingBoxes
097: * If there is no BoundingBox for this MapLayer the parent-BoundingBox
098: * will be taken.
099: * @author uwe dalluege
100: */
101: public ArrayList getAllBoundingBoxList() {
102: ArrayList allBoundingBoxList = new ArrayList();
103: MapLayer mapLayer = this ;
104: allBoundingBoxList = this .getBoundingBoxList();
105:
106: if (allBoundingBoxList.size() > 0)
107: return allBoundingBoxList;
108: // ---------------------------------------- MapLayer getAllBoundingBoxList ( )
109: while (mapLayer != null) {
110: mapLayer = mapLayer.getParent();
111: if (mapLayer == null)
112: return allBoundingBoxList;
113: allBoundingBoxList = mapLayer.getBoundingBoxList();
114: if (allBoundingBoxList.size() > 0)
115: return allBoundingBoxList;
116: }
117: // ---------------------------------------- MapLayer getAllBoundingBoxList ( )
118: return allBoundingBoxList;
119: }
120:
121: // ---------------------------------------- MapLayer getAllBoundingBoxList ( )
122:
123: /**
124: * Returns the number of sub-layers that this MapLayer has.
125: * @return the number of sub-layers that this MapLayer has
126: */
127: public int numSubLayers() {
128: return subLayers.size();
129: }
130:
131: /**
132: * Returns the sub-layer at the specified index.
133: * @param n the index of the sub-layer to return
134: * @return the MapLayer sub-layer at the specified index
135: */
136: public MapLayer getSubLayer(int n) {
137: return (MapLayer) subLayers.get(n);
138: }
139:
140: /**
141: * Gets a copy of the list of the sublayers of this layer.
142: * @return a copy of the Arraylist containing all the sub-layers of this layer
143: */
144: public ArrayList getSubLayerList() {
145: return (ArrayList) subLayers.clone();
146: }
147:
148: /**
149: * Returns a list of all the layers in order of a root-left-right traversal of
150: * the layer tree.
151: * @return a list of all the layers in order of a root-left-right traversal of
152: * the layer tree.
153: */
154: public ArrayList getLayerList() {
155: ArrayList list = new ArrayList();
156: list.add(this );
157: Iterator it = subLayers.iterator();
158: while (it.hasNext()) {
159: list.addAll(((MapLayer) it.next()).getLayerList());
160: }
161: return list;
162: }
163:
164: /**
165: * Gets the title of this MapLayer.
166: * The title of a layer should be used for display purposes.
167: * @return the title of this Layer
168: */
169: public String getTitle() {
170: return title;
171: }
172:
173: /**
174: * Gets the name of this Layer.
175: * The name of a layer is its 'back-end', ugly name, which generally
176: * shouldn't need to be used by others but is available anyway.
177: * Layers which do not have any data associated with them, such as container
178: * or grouping layers, might not have a name, in which case null will be
179: * returned.
180: * @return the name of the layer, or null if it doesn't have a name
181: */
182: public String getName() {
183: return name;
184: }
185:
186: /**
187: * Gets the parent MapLayer of this MapLayer.
188: * @return the parent layer of this MapLayer, or null if the layer has no parent.
189: */
190: public MapLayer getParent() {
191: return parent;
192: }
193:
194: /**
195: * Gets the LatLonBoundingBox for this layer.
196: * If this layer doesn't have a LatLonBoundingBox specified, we recursively
197: * ask the parent layer for its bounding box. The WMS spec says that each
198: * layer should either have its own LatLonBoundingBox, or inherit one from
199: * its parent, so this recursive call should be successful. If not, null is
200: * returned. However, if a bounding box is returned, it will have the
201: * SRS string "LatLon".
202: * Note that the BoundingBox is not necessarily "tight".
203: * @return the BoundingBox for this layer, or null if the BBox is unknown
204: */
205: public BoundingBox getBoundingBox() {
206:
207: if (bbox != null) {
208: return bbox;
209: }
210: if (parent != null) {
211: return parent.getBoundingBox();
212: }
213: return null;
214: }
215:
216: //----------------------------------------- MapLayer getLatLonBoundingBox ( )
217: /**
218: * I think this name is better [uwe dalluege]
219: * Gets the LatLonBoundingBox for this layer.
220: * If this layer doesn't have a LatLonBoundingBox specified, we recursively
221: * ask the parent layer for its bounding box. The WMS spec says that each
222: * layer should either have its own LatLonBoundingBox, or inherit one from
223: * its parent, so this recursive call should be successful. If not, null is
224: * returned. However, if a bounding box is returned, it will have the
225: * SRS string "LatLon".
226: * Note that the BoundingBox is not necessarily "tight".
227: * @return the BoundingBox for this layer, or null if the BBox is unknown
228: */
229: public BoundingBox getLatLonBoundingBox() {
230:
231: if (bbox != null) {
232: return bbox;
233: }
234: if (parent != null) {
235: return parent.getBoundingBox();
236: }
237: return null;
238: }
239:
240: // ----------------------------------------- MapLayer getLatLonBoundingBox ( )
241: //-------------------------------------------- MapLayer getBoundingBoxList ( )
242: /**
243: * Gets the BoundingBoxList for this Layer
244: * @return the BoundingBoxList containing the BoundingBoxes
245: */
246: // ------------------------------------------- MapLayer getBoundingBoxList ( )
247: public ArrayList getBoundingBoxList() {// [uwe dalluege]
248: return (ArrayList) boundingBoxList.clone();
249: }
250:
251: //--------------------------------------------- MapLayer getBoundingBoxList ( )
252:
253: /**
254: * Returns a copy of the list of supported SRS's. Each SRS is a string in the
255: * format described by the WMS specification, such as "EPSG:1234".
256: * @return a copy of the list of supported SRS's
257: */
258: public ArrayList getSRSList() {
259: return (ArrayList) srsList.clone();
260: }
261:
262: //<<TODO>>I'd like to return generic Lists, rather than concrete ArrayLists.
263: //Or even better, Collections, since order is not significant (I think) [Jon Aquino]
264: /**
265: * @return a list of the SRS list of this MapLayer and its ancestors
266: */
267: public Collection getFullSRSList() {
268: ArrayList fullSRSList = new ArrayList(getSRSList());
269: if (parent != null)
270: fullSRSList.addAll(parent.getFullSRSList());
271: return CollectionUtil.removeDuplicates(fullSRSList);
272: }
273:
274: /**
275: * Returns a somewhat nicely-formatted string representing all of the details of
276: * this layer and its sub-layers (recursively).
277: * @return a somewhat nicely-formatted string representing all of the details of
278: * this layer and its sub-layers (recursively).
279: */
280: public String toString() {
281: StringBuffer s = new StringBuffer("WMSLayer {\n" + " name: \""
282: + name + "\"\n" + " title: \"" + title + "\"\n"
283: + " srsList: " + srsList.toString() + "\n"
284: + " subLayers: [\n");
285: for (int i = 0; i < subLayers.size(); i++) {
286: s.append(subLayers.get(i).toString() + ", ");
287: }
288: s.append(" ]\n bbox: ");
289: if (bbox != null) {
290: s.append(bbox.toString());
291: } else {
292: s.append("null");
293: }
294: s.append("\n}\n");
295: return s.toString();
296: }
297: }
|