source: josm/trunk/src/org/openstreetmap/josm/data/imagery/LayerDetails.java

Last change on this file was 18208, checked in by Don-vip, 3 years ago

global use of Utils.isEmpty/isBlank

File size: 6.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.imagery;
3
4import java.util.ArrayList;
5import java.util.Collection;
6import java.util.List;
7import java.util.Map;
8import java.util.concurrent.ConcurrentHashMap;
9import java.util.stream.Stream;
10
11import org.openstreetmap.josm.data.Bounds;
12import org.openstreetmap.josm.tools.Utils;
13
14/**
15 * The details of a layer of this WMS server.
16 */
17public class LayerDetails {
18 private final Map<String, String> styles = new ConcurrentHashMap<>(); // name -> title
19 private final Collection<String> crs = new ArrayList<>();
20 /**
21 * The layer name (WMS {@code Title})
22 */
23 private String title;
24 /**
25 * The layer name (WMS {@code Name})
26 */
27 private String name;
28 /**
29 * The layer abstract (WMS {@code Abstract})
30 * @since 13199
31 */
32 private String abstr;
33 private final LayerDetails parentLayer;
34 private Bounds bounds;
35 private List<LayerDetails> children = new ArrayList<>();
36
37 /**
38 * Constructor pointing to parent layer. Set to null if this is topmost layer.
39 * This is needed to properly handle layer attributes inheritance.
40 *
41 * @param parentLayer parent layer
42 */
43 public LayerDetails(LayerDetails parentLayer) {
44 this.parentLayer = parentLayer;
45 }
46
47 /**
48 * Returns projections that are supported by this layer.
49 * @return projections that are supported by this layer
50 */
51 public Collection<String> getCrs() {
52 Collection<String> ret = new ArrayList<>();
53 if (parentLayer != null) {
54 ret.addAll(parentLayer.getCrs());
55 }
56 ret.addAll(crs);
57 return ret;
58 }
59
60 /**
61 * Returns styles defined for this layer.
62 * @return styles defined for this layer
63 */
64 public Map<String, String> getStyles() {
65 Map<String, String> ret = new ConcurrentHashMap<>();
66 if (parentLayer != null) {
67 ret.putAll(parentLayer.getStyles());
68 }
69 ret.putAll(styles);
70 return ret;
71 }
72
73 /**
74 * Returns "Human readable" title of this layer
75 * @return "Human readable" title of this layer
76 * @see LayerDetails#getName()
77 */
78 public String getTitle() {
79 return title;
80 }
81
82 /**
83 * Sets title of this layer
84 * @param title title of this layer
85 * @see LayerDetails#getName()
86 */
87 public void setTitle(String title) {
88 this.title = title;
89 }
90
91 /**
92 *
93 * Citation from OGC WMS specification (WMS 1.3.0):<p><i>
94 * A number of elements have both a {@literal <Name>} and a {@literal <Title>}. The Name is a text string used for machine-to-machine
95 * communication while the Title is for the benefit of humans. For example, a dataset might have the descriptive Title
96 * “Maximum Atmospheric Temperature” and be requested using the abbreviated Name “ATMAX”.</i></p>
97 *
98 * And second citation:<p><i>
99 * If, and only if, a layer has a {@literal <Name>}, then it is a map layer that can be requested by using that Name in the
100 * LAYERS parameter of a GetMap request. A Layer that contains a {@literal <Name>} element is referred to as a “named
101 * layer” in this International Standard. If the layer has a Title but no Name, then that layer is only a category title for
102 * all the layers nested within.</i></p>
103 * @return name of this layer
104 */
105 public String getName() {
106 return name;
107 }
108
109 /**
110 * Sets the name of this Layer.
111 * @param name the name of this Layer
112 * @see LayerDetails#getName()
113 */
114 public void setName(String name) {
115 this.name = name;
116 }
117
118 /**
119 * Add style to list of styles defined by this layer
120 * @param name machine-to-machine name of this style
121 * @param title human readable title of this style
122 */
123 public void addStyle(String name, String title) {
124 this.styles.put(name, title == null ? "" : title);
125 }
126
127 /**
128 * Add projection supported by this layer
129 * @param crs projection code
130 */
131 public void addCrs(String crs) {
132 this.crs.add(crs);
133 }
134
135 /**
136 * Returns bounds within layer might be queried.
137 * @return bounds within layer might be queried
138 */
139 public Bounds getBounds() {
140 return bounds;
141 }
142
143 /**
144 * Sets bounds of this layer
145 * @param bounds of this layer
146 */
147 public void setBounds(Bounds bounds) {
148 this.bounds = bounds;
149 }
150
151 @Override
152 public String toString() {
153 String baseName = Utils.isEmpty(title) ? name : title;
154 return abstr == null || abstr.equalsIgnoreCase(baseName) ? baseName : baseName + " (" + abstr + ')';
155 }
156
157 /**
158 * Returns parent layer for this layer.
159 * @return parent layer for this layer
160 */
161 public LayerDetails getParent() {
162 return parentLayer;
163 }
164
165 /**
166 * sets children layers for this layer
167 * @param children children of this layer
168 */
169 public void setChildren(List<LayerDetails> children) {
170 this.children = children;
171
172 }
173
174 /**
175 * Returns children layers of this layer.
176 * @return children layers of this layer
177 */
178 public List<LayerDetails> getChildren() {
179 return children;
180 }
181
182 /**
183 * if user may select this layer (is it possible to request it from server)
184 * @return true if user may select this layer, false if this layer is only grouping other layers
185 */
186 public boolean isSelectable() {
187 return !Utils.isEmpty(name);
188 }
189
190 /**
191 * Returns abstract of this layer.
192 * @return "Narrative description of the layer"
193 */
194 public String getAbstract() {
195 return abstr;
196 }
197
198 /**
199 * Sets abstract of this layer
200 * @param abstr abstract of this layer
201 */
202 public void setAbstract(String abstr) {
203 this.abstr = abstr;
204 }
205
206 /**
207 * Returns flattened stream of this layer and its children.
208 * @return flattened stream of this layer and its children (as well as recursively children of its children)
209 */
210 public Stream<LayerDetails> flattened() {
211 return Stream.concat(
212 Stream.of(this),
213 getChildren().stream().flatMap(LayerDetails::flattened)
214 );
215 }
216}
Note: See TracBrowser for help on using the repository browser.