Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java @ 1774:092e1e5020bc
Added a new MapGenerator which only returns a map configuration document at the moment (work still in progress).
flys-artifacts/trunk@3095 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 28 Oct 2011 05:54:25 +0000 |
parents | |
children | 0156105222c9 |
comparison
equal
deleted
inserted
replaced
1773:9be01e2e6897 | 1774:092e1e5020bc |
---|---|
1 package de.intevation.flys.exports; | |
2 | |
3 import java.io.IOException; | |
4 import java.io.OutputStream; | |
5 import java.util.ArrayList; | |
6 import java.util.List; | |
7 | |
8 import org.w3c.dom.Document; | |
9 import org.w3c.dom.Element; | |
10 | |
11 import org.apache.log4j.Logger; | |
12 | |
13 import com.vividsolutions.jts.geom.Envelope; | |
14 | |
15 import de.intevation.artifacts.Artifact; | |
16 import de.intevation.artifacts.CallContext; | |
17 | |
18 import de.intevation.artifacts.common.ArtifactNamespaceContext; | |
19 import de.intevation.artifacts.common.utils.XMLUtils; | |
20 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | |
21 | |
22 import de.intevation.artifactdatabase.state.Facet; | |
23 | |
24 import de.intevation.flys.artifacts.FLYSArtifact; | |
25 import de.intevation.flys.artifacts.model.FacetTypes; | |
26 import de.intevation.flys.artifacts.model.WMSLayerFacet; | |
27 import de.intevation.flys.utils.GeometryUtils; | |
28 | |
29 | |
30 public class MapGenerator implements OutGenerator, FacetTypes { | |
31 | |
32 private static Logger logger = Logger.getLogger(MapGenerator.class); | |
33 | |
34 | |
35 protected Artifact master; | |
36 | |
37 protected Document request; | |
38 | |
39 protected OutputStream out; | |
40 | |
41 protected CallContext context; | |
42 | |
43 protected List<WMSLayerFacet> layers; | |
44 | |
45 protected Envelope maxExtent; | |
46 protected Envelope initialExtent; | |
47 | |
48 protected String srid; | |
49 | |
50 | |
51 | |
52 @Override | |
53 public void init(Document request, OutputStream out, CallContext context) { | |
54 logger.debug("MapGenerator.init"); | |
55 | |
56 this.request = request; | |
57 this.out = out; | |
58 this.context = context; | |
59 | |
60 this.layers = new ArrayList<WMSLayerFacet>(); | |
61 | |
62 this.maxExtent = null; | |
63 this.initialExtent = null; | |
64 } | |
65 | |
66 | |
67 @Override | |
68 public void setMasterArtifact(Artifact master) { | |
69 logger.debug("MapGenerator.setMasterArtifact"); | |
70 this.master = master; | |
71 } | |
72 | |
73 | |
74 @Override | |
75 public void doOut( | |
76 Artifact artifact, | |
77 Facet facet, | |
78 Document attr, | |
79 boolean visible) | |
80 { | |
81 String name = facet.getName(); | |
82 | |
83 logger.debug("MapGenerator.doOut: " +artifact.identifier()+" | "+name); | |
84 FLYSArtifact flys = (FLYSArtifact) artifact; | |
85 | |
86 Facet nativeFacet = flys.getNativeFacet(facet); | |
87 | |
88 if (nativeFacet instanceof WMSLayerFacet) { | |
89 WMSLayerFacet wms = (WMSLayerFacet) nativeFacet; | |
90 Envelope extent = wms.getExtent(); | |
91 | |
92 layers.add(wms); | |
93 | |
94 setMaxExtent(extent); | |
95 setSrid(wms.getSrid()); | |
96 | |
97 if (FLOODMAP_WSPLGEN.equals(name) && initialExtent == null) { | |
98 setInitialExtent(extent); | |
99 } | |
100 } | |
101 else { | |
102 logger.warn("Facet not supported: " + nativeFacet.getClass()); | |
103 } | |
104 | |
105 } | |
106 | |
107 | |
108 @Override | |
109 public void generate() | |
110 throws IOException | |
111 { | |
112 logger.debug("MapGenerator.generate"); | |
113 | |
114 Document response = XMLUtils.newDocument(); | |
115 ElementCreator c = new ElementCreator( | |
116 response, | |
117 ArtifactNamespaceContext.NAMESPACE_URI, | |
118 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
119 | |
120 Element root = c.create("floodmap"); | |
121 Element layers = c.create("layers"); | |
122 | |
123 response.appendChild(root); | |
124 root.appendChild(layers); | |
125 | |
126 appendLayers(layers); | |
127 appendMapInformation(root, c); | |
128 | |
129 XMLUtils.toStream(response, out); | |
130 } | |
131 | |
132 | |
133 protected void appendLayers(Element parent) { | |
134 for (WMSLayerFacet facet: layers) { | |
135 parent.appendChild(facet.toXML(parent.getOwnerDocument())); | |
136 } | |
137 } | |
138 | |
139 | |
140 protected void setMaxExtent(Envelope maxExtent) { | |
141 if (maxExtent == null) { | |
142 return; | |
143 } | |
144 | |
145 if (this.maxExtent == null) { | |
146 logger.debug("Set max extent to: " + maxExtent); | |
147 this.maxExtent = maxExtent; | |
148 return; | |
149 } | |
150 | |
151 logger.debug("Expand max extent by: " + maxExtent); | |
152 logger.debug("Max extent before expanding: " + this.maxExtent); | |
153 this.maxExtent.expandToInclude(maxExtent); | |
154 logger.debug("Max extent after expanding: " + this.maxExtent); | |
155 } | |
156 | |
157 | |
158 protected void setInitialExtent(Envelope initialExtent) { | |
159 if (initialExtent == null) { | |
160 return; | |
161 } | |
162 | |
163 if (this.initialExtent == null) { | |
164 logger.debug("Set initial extent to: " + initialExtent); | |
165 this.initialExtent = initialExtent; | |
166 return; | |
167 } | |
168 | |
169 logger.debug("Set initial extent to: " + initialExtent); | |
170 this.initialExtent = initialExtent; | |
171 } | |
172 | |
173 | |
174 protected void setSrid(String srid) { | |
175 if (srid == null || srid.length() == 0) { | |
176 return; | |
177 } | |
178 | |
179 this.srid = srid; | |
180 } | |
181 | |
182 | |
183 protected void appendMapInformation(Element parent, ElementCreator c) { | |
184 String mE = GeometryUtils.jtsBoundsToOLBounds(this.maxExtent); | |
185 logger.debug("BUILD MAX EXTENT OF:" + this.maxExtent); | |
186 logger.debug("BUILD MAX EXTENT:" + mE); | |
187 | |
188 Element maxExtent = c.create("maxExtent"); | |
189 maxExtent.setTextContent(mE); | |
190 | |
191 String iE = GeometryUtils.jtsBoundsToOLBounds(this.initialExtent); | |
192 logger.debug("BUILD INITIAL EXTENT OF: " + this.initialExtent); | |
193 logger.debug("BUILD INITIAL EXTENT: " + iE); | |
194 Element initExtent = c.create("initialExtent"); | |
195 initExtent.setTextContent(iE); | |
196 | |
197 Element srid = c.create("srid"); | |
198 srid.setTextContent(this.srid); | |
199 | |
200 // TODO zoom levels | |
201 // TODO resolutation | |
202 | |
203 parent.appendChild(maxExtent); | |
204 parent.appendChild(initExtent); | |
205 parent.appendChild(srid); | |
206 } | |
207 } | |
208 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |