comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/map/WMSLayerFacet.java @ 9619:63bbd5e45839

#21 WMS Legend
author dnt_bjoernsen <d.tironi@bjoernsen.de>
date Thu, 10 Oct 2019 16:08:47 +0200
parents e4606eae8ea5
children
comparison
equal deleted inserted replaced
9618:af671ee7835e 9619:63bbd5e45839
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.artifacts.model.map; 9 package org.dive4elements.river.artifacts.model.map;
10 10
11 import com.vividsolutions.jts.geom.Envelope; 11 import java.util.ArrayList;
12 import java.util.List;
12 13
14 import org.apache.log4j.Logger;
13 import org.dive4elements.artifactdatabase.state.DefaultFacet; 15 import org.dive4elements.artifactdatabase.state.DefaultFacet;
14 import org.dive4elements.artifactdatabase.state.Facet; 16 import org.dive4elements.artifactdatabase.state.Facet;
15 import org.dive4elements.artifacts.Artifact; 17 import org.dive4elements.artifacts.Artifact;
16 import org.dive4elements.artifacts.ArtifactNamespaceContext; 18 import org.dive4elements.artifacts.ArtifactNamespaceContext;
17 import org.dive4elements.artifacts.CallContext; 19 import org.dive4elements.artifacts.CallContext;
18 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; 20 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
19 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; 21 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
20 import org.dive4elements.river.utils.GeometryUtils; 22 import org.dive4elements.river.utils.GeometryUtils;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.log4j.Logger;
26 import org.w3c.dom.Document; 23 import org.w3c.dom.Document;
27 import org.w3c.dom.Element; 24 import org.w3c.dom.Element;
28 import org.w3c.dom.Node; 25 import org.w3c.dom.Node;
29 26
27 import com.vividsolutions.jts.geom.Envelope;
30 28
31 public class WMSLayerFacet 29 public class WMSLayerFacet extends DefaultFacet {
32 extends DefaultFacet 30 private static final long serialVersionUID = 1L;
33 { 31 protected ComputeType type;
34 protected ComputeType type;
35 protected List<String> layers; 32 protected List<String> layers;
36 protected String stateId; 33 protected String stateId;
37 protected String hash; 34 protected String hash;
38 protected String url; 35 protected String url;
39 protected Envelope extent; 36 protected Envelope extent;
40 protected Envelope originalExtent; 37 protected Envelope originalExtent;
41 protected String srid; 38 protected String srid;
42 39 private String legend;
40 private String imagepath;
43 41
44 private static final Logger log = Logger.getLogger(WMSLayerFacet.class); 42 private static final Logger log = Logger.getLogger(WMSLayerFacet.class);
45 43
46 public WMSLayerFacet() { 44 public WMSLayerFacet() {
47 } 45 }
48 46
49 47 public WMSLayerFacet(final int index, final String name, final String description) {
50 public WMSLayerFacet(int index, String name, String description) {
51 this(index, name, description, ComputeType.FEED, null, null); 48 this(index, name, description, ComputeType.FEED, null, null);
52 } 49 }
53 50
54 51 public WMSLayerFacet(final int index, final String name, final String description, final ComputeType type, final String stateId, final String hash
55 public WMSLayerFacet(
56 int index,
57 String name,
58 String description,
59 ComputeType type,
60 String stateId,
61 String hash
62 52
63 ) { 53 ) {
64 super(index, name, description); 54 super(index, name, description);
65 this.layers = new ArrayList<String>(); 55 this.layers = new ArrayList<>();
66 this.type = type; 56 this.type = type;
67 this.stateId = stateId; 57 this.stateId = stateId;
68 this.hash = hash; 58 this.hash = hash;
69 } 59 }
70 60
71 61 public WMSLayerFacet(final int index, final String name, final String description, final ComputeType type, final String stateId, final String hash,
72 public WMSLayerFacet( 62 final String url) {
73 int index,
74 String name,
75 String description,
76 ComputeType type,
77 String stateId,
78 String hash,
79 String url
80 ) {
81 this(index, name, description, type, stateId, hash); 63 this(index, name, description, type, stateId, hash);
82 this.url = url; 64 this.url = url;
83 } 65 }
84 66
85 67 public void addLayer(final String name) {
86 public void addLayer(String name) {
87 if (name != null && name.length() > 0) { 68 if (name != null && name.length() > 0) {
88 layers.add(name); 69 this.layers.add(name);
89 } 70 }
90 } 71 }
91 72
92
93 public List<String> getLayers() { 73 public List<String> getLayers() {
94 return layers; 74 return this.layers;
95 } 75 }
96 76
97 77 public void removeLayer(final String layer) {
98 public void removeLayer(String layer) { 78 if (this.layers != null) {
99 if (layers != null) { 79 this.layers.remove(layer);
100 layers.remove(layer);
101 } 80 }
102 } 81 }
103 82
104 83 public void setExtent(final Envelope extent) {
105 public void setExtent(Envelope extent) {
106 if (extent != null) { 84 if (extent != null) {
107 this.extent = extent; 85 this.extent = extent;
108 } 86 } else {
109 else {
110 log.debug("setExtent(): extent is null"); 87 log.debug("setExtent(): extent is null");
111 } 88 }
112 } 89 }
113 90
114
115 public Envelope getExtent() { 91 public Envelope getExtent() {
116 return extent; 92 return this.extent;
117 } 93 }
118 94
119 95 public void setOriginalExtent(final Envelope originalExtent) {
120 public void setOriginalExtent(Envelope originalExtent) {
121 this.originalExtent = originalExtent; 96 this.originalExtent = originalExtent;
122 } 97 }
123 98
124
125 public Envelope getOriginalExtent() { 99 public Envelope getOriginalExtent() {
126 return originalExtent; 100 return this.originalExtent;
127 } 101 }
128 102
129 103 public void setSrid(final String srid) {
130 public void setSrid(String srid) {
131 if (srid != null) { 104 if (srid != null) {
132 this.srid = srid; 105 this.srid = srid;
133 } 106 }
134 } 107 }
135 108
136
137 public String getSrid() { 109 public String getSrid() {
138 return srid; 110 return this.srid;
139 } 111 }
140 112
141
142 @Override 113 @Override
143 public Object getData(Artifact artifact, CallContext context) { 114 public Object getData(final Artifact artifact, final CallContext context) {
144 return null; 115 return null;
145 } 116 }
146 117
118 @Override
119 public Node toXML(final Document doc) {
120 final ElementCreator ec = new ElementCreator(doc, ArtifactNamespaceContext.NAMESPACE_URI, ArtifactNamespaceContext.NAMESPACE_PREFIX);
147 121
148 @Override 122 final Element facet = ec.create("facet");
149 public Node toXML(Document doc) { 123 ec.addAttr(facet, "description", this.description, true);
150 ElementCreator ec = new ElementCreator( 124 ec.addAttr(facet, "index", String.valueOf(this.index), true);
151 doc, 125 ec.addAttr(facet, "name", this.name, true);
152 ArtifactNamespaceContext.NAMESPACE_URI, 126 ec.addAttr(facet, "url", this.url, true);
153 ArtifactNamespaceContext.NAMESPACE_PREFIX); 127 ec.addAttr(facet, "layers", this.layers.get(0), true);
154 128 ec.addAttr(facet, "srid", this.srid != null ? this.srid : "", true);
155 Element facet = ec.create("facet"); 129 ec.addAttr(facet, "extent", this.originalExtent != null ? GeometryUtils.jtsBoundsToOLBounds(this.originalExtent) : "", true);
156 ec.addAttr(facet, "description", description, true);
157 ec.addAttr(facet, "index", String.valueOf(index), true);
158 ec.addAttr(facet, "name", name, true);
159 ec.addAttr(facet, "url", url, true);
160 ec.addAttr(facet, "layers", layers.get(0), true);
161 ec.addAttr(facet, "srid", srid != null ? srid : "", true);
162 ec.addAttr(facet, "extent", originalExtent != null
163 ? GeometryUtils.jtsBoundsToOLBounds(originalExtent)
164 : "", true);
165 ec.addAttr(facet, "queryable", String.valueOf(isQueryable()), true); 130 ec.addAttr(facet, "queryable", String.valueOf(isQueryable()), true);
131 ec.addAttr(facet, "imagepath", this.imagepath, true);
132 ec.addAttr(facet, "legend", this.legend, true);
166 133
167 return facet; 134 return facet;
168 } 135 }
169 136
137 public void setLegend(final String legend) {
138 this.legend = legend;
139 }
140
141 /* Code-Kongruenz */
142 public String getLegend() {
143 return this.legend;
144 }
170 145
171 public boolean isQueryable() { 146 public boolean isQueryable() {
172 return false; 147 return false;
173 } 148 }
174 149
150 /** Clone facet-bound data. */
151 protected void cloneData(final WMSLayerFacet copy) {
152 copy.type = this.type;
153 copy.stateId = this.stateId;
154 copy.hash = this.hash;
175 155
176 /** Clone facet-bound data. */ 156 if (this.layers != null) {
177 protected void cloneData(WMSLayerFacet copy) { 157 copy.layers = new ArrayList<>(this.layers);
178 copy.type = type; 158 } else {
179 copy.stateId = stateId; 159 copy.layers = new ArrayList<>();
180 copy.hash = hash;
181
182 if (layers != null) {
183 copy.layers = new ArrayList<String>(layers);
184 }
185 else {
186 copy.layers = new ArrayList<String>();
187 } 160 }
188 161
189 copy.originalExtent = originalExtent; 162 copy.originalExtent = this.originalExtent;
190 copy.url = url; 163 copy.url = this.url;
191 copy.extent = extent; 164 copy.extent = this.extent;
192 copy.srid = srid; 165 copy.srid = this.srid;
166
167 copy.imagepath = imagepath;
168 copy.legend = legend;
193 } 169 }
194 170
195 @Override 171 @Override
196 public Facet deepCopy() { 172 public Facet deepCopy() {
197 WMSLayerFacet copy = new WMSLayerFacet(); 173 final WMSLayerFacet copy = new WMSLayerFacet();
198 copy.set(this); 174 copy.set(this);
199 175
200 cloneData(copy); 176 cloneData(copy);
201 177
202 return copy; 178 return copy;

http://dive4elements.wald.intevation.org