Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapOutputTab.java @ 9483:992c188b7330
wms uinfo.inundation
author | gernotbelger |
---|---|
date | Thu, 13 Sep 2018 18:22:05 +0200 |
parents | 5e38e2924c07 |
children | 5397555d74c9 |
comparison
equal
deleted
inserted
replaced
9482:e5cb5efbc43e | 9483:992c188b7330 |
---|---|
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.client.client.ui.map; | 9 package org.dive4elements.river.client.client.ui.map; |
10 | 10 |
11 import com.google.gwt.core.client.GWT; | 11 import java.util.HashMap; |
12 import com.google.gwt.user.client.rpc.AsyncCallback; | 12 import java.util.List; |
13 import com.google.gwt.user.client.ui.AbsolutePanel; | |
14 import com.smartgwt.client.util.SC; | |
15 import com.smartgwt.client.widgets.Canvas; | |
16 import com.smartgwt.client.widgets.events.ParentMovedEvent; | |
17 import com.smartgwt.client.widgets.events.ParentMovedHandler; | |
18 import com.smartgwt.client.widgets.events.ResizedEvent; | |
19 import com.smartgwt.client.widgets.events.ResizedHandler; | |
20 import com.smartgwt.client.widgets.layout.HLayout; | |
21 import com.smartgwt.client.widgets.layout.VLayout; | |
22 import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; | |
23 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; | |
24 | 13 |
25 import org.dive4elements.river.client.client.Config; | 14 import org.dive4elements.river.client.client.Config; |
26 import org.dive4elements.river.client.client.FLYSConstants; | 15 import org.dive4elements.river.client.client.FLYSConstants; |
27 import org.dive4elements.river.client.client.event.OutputParameterChangeEvent; | 16 import org.dive4elements.river.client.client.event.OutputParameterChangeEvent; |
28 import org.dive4elements.river.client.client.event.OutputParameterChangeHandler; | 17 import org.dive4elements.river.client.client.event.OutputParameterChangeHandler; |
50 import org.dive4elements.river.client.shared.model.OutputMode; | 39 import org.dive4elements.river.client.shared.model.OutputMode; |
51 import org.dive4elements.river.client.shared.model.Recommendation; | 40 import org.dive4elements.river.client.shared.model.Recommendation; |
52 import org.dive4elements.river.client.shared.model.Theme; | 41 import org.dive4elements.river.client.shared.model.Theme; |
53 import org.dive4elements.river.client.shared.model.ThemeList; | 42 import org.dive4elements.river.client.shared.model.ThemeList; |
54 import org.dive4elements.river.client.shared.model.WMSLayer; | 43 import org.dive4elements.river.client.shared.model.WMSLayer; |
55 | |
56 import java.util.HashMap; | |
57 import java.util.List; | |
58 | |
59 import org.gwtopenmaps.openlayers.client.Bounds; | 44 import org.gwtopenmaps.openlayers.client.Bounds; |
60 import org.gwtopenmaps.openlayers.client.Map; | 45 import org.gwtopenmaps.openlayers.client.Map; |
61 import org.gwtopenmaps.openlayers.client.MapWidget; | 46 import org.gwtopenmaps.openlayers.client.MapWidget; |
62 import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener; | 47 import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener; |
63 import org.gwtopenmaps.openlayers.client.event.VectorFeatureRemovedListener; | 48 import org.gwtopenmaps.openlayers.client.event.VectorFeatureRemovedListener; |
68 import org.gwtopenmaps.openlayers.client.layer.Vector; | 53 import org.gwtopenmaps.openlayers.client.layer.Vector; |
69 import org.gwtopenmaps.openlayers.client.layer.WMS; | 54 import org.gwtopenmaps.openlayers.client.layer.WMS; |
70 import org.gwtopenmaps.openlayers.client.layer.WMSOptions; | 55 import org.gwtopenmaps.openlayers.client.layer.WMSOptions; |
71 import org.gwtopenmaps.openlayers.client.layer.WMSParams; | 56 import org.gwtopenmaps.openlayers.client.layer.WMSParams; |
72 | 57 |
73 | 58 import com.google.gwt.core.client.GWT; |
74 public class MapOutputTab | 59 import com.google.gwt.user.client.rpc.AsyncCallback; |
75 extends OutputTab | 60 import com.google.gwt.user.client.ui.AbsolutePanel; |
76 implements RedrawRequestHandler, ExternalWMSWindow.LayerLoader, | 61 import com.smartgwt.client.util.SC; |
77 TabSelectedHandler, OutputParameterChangeHandler { | 62 import com.smartgwt.client.widgets.Canvas; |
63 import com.smartgwt.client.widgets.events.ParentMovedEvent; | |
64 import com.smartgwt.client.widgets.events.ParentMovedHandler; | |
65 import com.smartgwt.client.widgets.events.ResizedEvent; | |
66 import com.smartgwt.client.widgets.events.ResizedHandler; | |
67 import com.smartgwt.client.widgets.layout.HLayout; | |
68 import com.smartgwt.client.widgets.layout.VLayout; | |
69 import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; | |
70 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; | |
71 | |
72 public class MapOutputTab extends OutputTab implements RedrawRequestHandler, ExternalWMSWindow.LayerLoader, TabSelectedHandler, OutputParameterChangeHandler { | |
78 | 73 |
79 public static final String DEFAULT_SRID = "4326"; | 74 public static final String DEFAULT_SRID = "4326"; |
80 | 75 |
81 public static final String BARRIERS_PARAMETER_KEY = "uesk.barriers"; | 76 public static final String BARRIERS_PARAMETER_KEY = "uesk.barriers"; |
82 | 77 |
83 public static final String WSPLGEN_FACET = "floodmap.wsplgen"; | 78 public static final String WSPLGEN_FACET = "floodmap.wsplgen"; |
84 | 79 |
85 public static final String EXTERNAL_WMS_FACTORY = "externalwmsfactory"; | 80 public static final String EXTERNAL_WMS_FACTORY = "externalwmsfactory"; |
86 | 81 |
87 | 82 protected StepForwardServiceAsync feedService = GWT.create(StepForwardService.class); |
88 protected StepForwardServiceAsync feedService = | 83 |
89 GWT.create(StepForwardService.class); | 84 protected MapOutputServiceAsync mapService = GWT.create(MapOutputService.class); |
90 | |
91 protected MapOutputServiceAsync mapService = | |
92 GWT.create(MapOutputService.class); | |
93 | 85 |
94 /** Service handle to clone and add artifacts to collection. */ | 86 /** Service handle to clone and add artifacts to collection. */ |
95 protected LoadArtifactServiceAsync loadArtifactService = | 87 protected LoadArtifactServiceAsync loadArtifactService = GWT.create(LoadArtifactService.class); |
96 GWT.create(LoadArtifactService.class); | |
97 | 88 |
98 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | 89 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); |
99 | 90 |
100 protected MapToolbar controlPanel; | 91 protected MapToolbar controlPanel; |
101 protected ThemePanel themePanel; | 92 protected ThemePanel themePanel; |
102 protected Canvas themePanelCanvas; | 93 protected Canvas themePanelCanvas; |
103 protected MapWidget mapPanel; | 94 protected MapWidget mapPanel; |
104 protected Canvas mapPanelCanvas; | 95 protected Canvas mapPanelCanvas; |
105 protected VLayout rootLayout = new VLayout(); | 96 protected VLayout rootLayout = new VLayout(); |
106 protected AbsolutePanel absPan = new AbsolutePanel(); | 97 protected AbsolutePanel absPan = new AbsolutePanel(); |
107 protected FloodMap floodMap; | 98 protected FloodMap floodMap; |
108 protected java.util.Map<String, String> wmsUrls = | 99 |
109 new HashMap<String, String>(); | 100 private final java.util.Map<String, String> wmsUrls = new HashMap<String, String>(); |
110 | 101 |
111 | 102 public MapOutputTab(final String title, final Collection collection, final OutputMode mode, final CollectionView collectionView) { |
112 public MapOutputTab( | |
113 String title, | |
114 Collection collection, | |
115 OutputMode mode, | |
116 CollectionView collectionView | |
117 ){ | |
118 super(title, collection, collectionView, mode); | 103 super(title, collection, collectionView, mode); |
119 | 104 |
120 collectionView.registerTabHandler(this); | 105 collectionView.registerTabHandler(this); |
121 | 106 |
122 mapService.doOut(collection, new AsyncCallback<MapConfig>() { | 107 this.mapService.doOut(collection, new AsyncCallback<MapConfig>() { |
123 @Override | 108 @Override |
124 public void onFailure(Throwable caught) { | 109 public void onFailure(final Throwable caught) { |
125 GWT.log("MAP ERROR: " + caught.getMessage()); | 110 GWT.log("MAP ERROR: " + caught.getMessage()); |
111 } | |
112 | |
113 @Override | |
114 public void onSuccess(final MapConfig c) { | |
115 GWT.log("MAP SUCCESS!"); | |
116 | |
117 final Bounds max = boundsFromString(c.getMaxExtent()); | |
118 Bounds initial = boundsFromString(c.getInitialExtent()); | |
119 | |
120 if (initial == null) { | |
121 GWT.log("Warning: No initial extent set."); | |
122 initial = max; | |
126 } | 123 } |
127 | 124 |
128 @Override | 125 setFloodmap(new FloodMap(c.getSrid(), max, 640, 480)); |
129 public void onSuccess(MapConfig c) { | 126 |
130 GWT.log("MAP SUCCESS!"); | 127 initLayout(); |
131 | 128 initBarriers(); |
132 Bounds max = boundsFromString(c.getMaxExtent()); | 129 |
133 Bounds initial = boundsFromString(c.getInitialExtent()); | 130 GWT.log("MAX EXTENT: " + max); |
134 | 131 GWT.log("ZOOM TO: " + initial); |
135 if (initial == null) { | 132 getMap().zoomToExtent(initial); |
136 GWT.log("Warning: No initial extent set."); | 133 } |
137 initial = max; | 134 }); |
138 } | 135 } |
139 | |
140 setFloodmap(new FloodMap(c.getSrid(), max, 640, 480)); | |
141 | |
142 initLayout(); | |
143 initBarriers(); | |
144 | |
145 GWT.log("MAX EXTENT: " + max); | |
146 GWT.log("ZOOM TO: " + initial); | |
147 getMap().zoomToExtent(initial); | |
148 } | |
149 } | |
150 ); | |
151 } | |
152 | |
153 | 136 |
154 protected void initLayout() { | 137 protected void initLayout() { |
155 rootLayout.setHeight100(); | 138 this.rootLayout.setHeight100(); |
156 rootLayout.setWidth100(); | 139 this.rootLayout.setWidth100(); |
157 rootLayout.setMembersMargin(2); | 140 this.rootLayout.setMembersMargin(2); |
158 | 141 |
159 HLayout hlayout = new HLayout(); | 142 final HLayout hlayout = new HLayout(); |
160 hlayout.setMembersMargin(0); | 143 hlayout.setMembersMargin(0); |
161 | 144 |
162 this.themePanelCanvas = createThemePanel(); | 145 this.themePanelCanvas = createThemePanel(); |
163 | 146 |
164 controlPanel = createControlPanel(); | 147 this.controlPanel = createControlPanel(); |
165 mapPanel = floodMap.getMapWidget(); | 148 this.mapPanel = this.floodMap.getMapWidget(); |
166 | 149 |
167 rootLayout.addMember(controlPanel); | 150 this.rootLayout.addMember(this.controlPanel); |
168 rootLayout.addMember(absPan); | 151 this.rootLayout.addMember(this.absPan); |
169 absPan.setWidth("100%"); | 152 this.absPan.setWidth("100%"); |
170 absPan.setHeight("100%"); | 153 this.absPan.setHeight("100%"); |
171 absPan.add(themePanelCanvas); | 154 this.absPan.add(this.themePanelCanvas); |
172 absPan.add(mapPanel); | 155 this.absPan.add(this.mapPanel); |
173 | 156 |
174 rootLayout.addResizedHandler(new ResizedHandler() { | 157 this.rootLayout.addResizedHandler(new ResizedHandler() { |
175 @Override | 158 @Override |
176 public void onResized(ResizedEvent e) { | 159 public void onResized(final ResizedEvent e) { |
177 doLayout(); | 160 doLayout(); |
178 } | 161 } |
179 }); | 162 }); |
180 | 163 |
181 rootLayout.addParentMovedHandler(new ParentMovedHandler() { | 164 this.rootLayout.addParentMovedHandler(new ParentMovedHandler() { |
182 @Override | 165 @Override |
183 public void onParentMoved(ParentMovedEvent event) { | 166 public void onParentMoved(final ParentMovedEvent event) { |
184 mapPanel.getMap().updateSize(); | 167 MapOutputTab.this.mapPanel.getMap().updateSize(); |
185 } | 168 } |
186 }); | 169 }); |
187 | 170 |
188 setPane(rootLayout); | 171 setPane(this.rootLayout); |
189 } | 172 } |
190 | |
191 | 173 |
192 protected void doLayout() { | 174 protected void doLayout() { |
193 if(!rootLayout.isVisible()) { | 175 if (!this.rootLayout.isVisible()) { |
194 return; | 176 return; |
195 } | 177 } |
196 | 178 |
197 // Manually set the height of the AbsolutePanel, | 179 // Manually set the height of the AbsolutePanel, |
198 // somehow this is necessary | 180 // somehow this is necessary |
199 absPan.setHeight(String.valueOf( | 181 this.absPan.setHeight(String.valueOf(this.rootLayout.getHeight() - this.controlPanel.getHeight() - 2) + "px"); |
200 rootLayout.getHeight() - controlPanel.getHeight() - 2) + "px"); | |
201 | 182 |
202 // Calculate bounds of Map | 183 // Calculate bounds of Map |
203 int height = rootLayout.getHeight() - | 184 final int height = this.rootLayout.getHeight() - this.controlPanel.getHeight() - 6; |
204 controlPanel.getHeight() - 6; | 185 final int width = this.controlPanel.getWidth() - (this.themePanelCanvas.isVisible() ? this.themePanelCanvas.getWidth() + 4 : 2); |
205 int width = controlPanel.getWidth() - | |
206 (themePanelCanvas.isVisible() | |
207 ? themePanelCanvas.getWidth() + 4 | |
208 : 2); | |
209 | 186 |
210 // Set size and position of Map | 187 // Set size and position of Map |
211 String w = String.valueOf(width) + "px"; | 188 final String w = String.valueOf(width) + "px"; |
212 String h = String.valueOf(height) + "px"; | 189 final String h = String.valueOf(height) + "px"; |
213 GWT.log("width=" + w); | 190 GWT.log("width=" + w); |
214 | 191 |
215 mapPanel.setSize(w, h); | 192 this.mapPanel.setSize(w, h); |
216 mapPanel.getMap().updateSize(); | 193 this.mapPanel.getMap().updateSize(); |
217 if(themePanelCanvas.isVisible()) { | 194 if (this.themePanelCanvas.isVisible()) { |
218 absPan.setWidgetPosition( | 195 this.absPan.setWidgetPosition(this.mapPanel, this.themePanelCanvas.getWidth() + 2, 0); |
219 mapPanel, themePanelCanvas.getWidth() + 2, 0); | 196 } else { |
220 } | 197 this.absPan.setWidgetPosition(this.mapPanel, 0, 0); |
221 else { | |
222 absPan.setWidgetPosition(mapPanel, 0, 0); | |
223 } | 198 } |
224 | 199 |
225 // Set bounds of ThemePanelCanvas | 200 // Set bounds of ThemePanelCanvas |
226 themePanelCanvas.setSize( | 201 this.themePanelCanvas.setSize(this.themePanelCanvas.getWidthAsString(), String.valueOf(height + 2) + "px"); |
227 themePanelCanvas.getWidthAsString(), | 202 } |
228 String.valueOf(height + 2) + "px"); | |
229 } | |
230 | |
231 | 203 |
232 protected void initBarriers() { | 204 protected void initBarriers() { |
233 Vector vector = floodMap.getBarrierLayer(); | 205 final Vector vector = this.floodMap.getBarrierLayer(); |
234 vector.addVectorFeatureAddedListener( | 206 vector.addVectorFeatureAddedListener(new VectorFeatureAddedListener() { |
235 new VectorFeatureAddedListener() { | 207 @Override |
236 @Override | 208 public void onFeatureAdded(final FeatureAddedEvent e) { |
237 public void onFeatureAdded(FeatureAddedEvent e) { | 209 saveBarriers(); |
238 saveBarriers(); | 210 } |
239 } | 211 }); |
240 } | 212 |
241 ); | 213 vector.addVectorFeatureRemovedListener(new VectorFeatureRemovedListener() { |
242 | 214 @Override |
243 vector.addVectorFeatureRemovedListener( | 215 public void onFeatureRemoved(final FeatureRemovedEvent e) { |
244 new VectorFeatureRemovedListener() { | 216 saveBarriers(); |
245 @Override | 217 } |
246 public void onFeatureRemoved(FeatureRemovedEvent e) { | 218 }); |
247 saveBarriers(); | 219 |
248 } | 220 final Artifact artifact = getArtifact(); |
249 } | |
250 ); | |
251 | |
252 | |
253 Artifact artifact = getArtifact(); | |
254 | 221 |
255 if (artifact == null) { | 222 if (artifact == null) { |
256 return; | 223 return; |
257 } | 224 } |
258 | 225 |
259 ArtifactDescription desc = artifact.getArtifactDescription(); | 226 final ArtifactDescription desc = artifact.getArtifactDescription(); |
260 | 227 |
261 String geojson = getGeoJSONFromStatic(desc); | 228 String geojson = getGeoJSONFromStatic(desc); |
262 geojson = geojson != null ? geojson : getGeoJSONFromDynamic(desc); | 229 geojson = geojson != null ? geojson : getGeoJSONFromDynamic(desc); |
263 | 230 |
264 if (geojson == null || geojson.length() == 0) { | 231 if (geojson == null || geojson.length() == 0) { |
265 GWT.log("No geojson string found -> no barriers existing."); | 232 GWT.log("No geojson string found -> no barriers existing."); |
266 return; | 233 return; |
267 } | 234 } |
268 | 235 |
269 GeoJSON reader = new GeoJSON(); | 236 final GeoJSON reader = new GeoJSON(); |
270 VectorFeature[] features = reader.read(geojson); | 237 final VectorFeature[] features = reader.read(geojson); |
271 | 238 |
272 vector.addFeatures(features); | 239 vector.addFeatures(features); |
273 } | 240 } |
274 | 241 |
275 | 242 public void addLayer(final Theme newTheme) { |
276 public void addLayer(Layer layer) { | 243 |
277 FloodMap map = getFloodmap(); | 244 final Layer layer = createWMSLayer(newTheme); |
245 | |
246 final FloodMap map = getFloodmap(); | |
278 | 247 |
279 if (map != null) { | 248 if (map != null) { |
280 GWT.log("Add new layer '" + layer.getName() + "' to map."); | 249 GWT.log("Add new layer '" + layer.getName() + "' to map."); |
281 map.addLayer(layer); | 250 map.addLayer(layer); |
282 if (layer instanceof WMS) { | 251 if (layer instanceof WMS) { |
283 wmsUrls.put(layer.getName(), | 252 this.wmsUrls.put(layer.getName(), ((WMS) layer).getFullRequestString(new WMSParams(), null)); |
284 ((WMS)layer).getFullRequestString(new WMSParams(), null)); | 253 } |
285 } | 254 } |
286 } | 255 } |
287 } | 256 |
288 | 257 public void removeLayer(final Theme theme) { |
289 | 258 |
290 public void removeLayer(String name) { | 259 final String layerId = getLayerId(theme); |
291 Map map = getMap(); | 260 |
292 | 261 final Map map = getMap(); |
293 Layer[] layers = map.getLayers(); | 262 |
294 | 263 final Layer[] layers = map.getLayers(); |
295 for (Layer layer: layers) { | 264 |
296 if (name.equals(layer.getName())) { | 265 for (final Layer layer : layers) { |
266 if (layerId.equals(layer.getName())) { | |
297 map.removeLayer(layer); | 267 map.removeLayer(layer); |
298 } | 268 } |
299 } | 269 } |
300 } | 270 } |
301 | 271 |
302 | |
303 @Override | 272 @Override |
304 public void onRedrawRequest(RedrawRequestEvent event) { | 273 public void onRedrawRequest(final RedrawRequestEvent event) { |
305 mapService.doOut(collection, new AsyncCallback<MapConfig>() { | 274 this.mapService.doOut(this.collection, new AsyncCallback<MapConfig>() { |
306 @Override | 275 @Override |
307 public void onFailure(Throwable caught) { | 276 public void onFailure(final Throwable caught) { |
308 GWT.log("MAP ERROR: " + caught.getMessage()); | 277 GWT.log("MAP ERROR: " + caught.getMessage()); |
309 } | 278 } |
310 | 279 |
311 @Override | 280 @Override |
312 public void onSuccess(MapConfig c) { | 281 public void onSuccess(final MapConfig c) { |
313 GWT.log("We want to refresh the map now!"); | 282 GWT.log("We want to refresh the map now!"); |
314 themePanel.updateCollection(); | 283 MapOutputTab.this.themePanel.updateCollection(); |
315 getFloodmap().update(); | 284 getFloodmap().update(); |
316 } | 285 } |
317 }); | 286 }); |
318 } | 287 } |
319 | 288 |
320 | |
321 @Override | 289 @Override |
322 public void load(List<WMSLayer> toLoad) { | 290 public void load(final List<WMSLayer> toLoad) { |
323 GWT.log("The user wants to add " + toLoad.size() + " new WMS layers."); | 291 GWT.log("The user wants to add " + toLoad.size() + " new WMS layers."); |
324 | 292 |
325 int len = toLoad.size(); | 293 final int len = toLoad.size(); |
326 | 294 |
327 Recommendation[] recom = new Recommendation[len]; | 295 final Recommendation[] recom = new Recommendation[len]; |
328 | 296 |
329 for (int i = 0; i < len; i++) { | 297 for (int i = 0; i < len; i++) { |
330 WMSLayer w = toLoad.get(i); | 298 final WMSLayer w = toLoad.get(i); |
331 | 299 |
332 String ids = w.getServer() + ";" + w.getName() + ";" + w.getTitle(); | 300 final String ids = w.getServer() + ";" + w.getName() + ";" + w.getTitle(); |
333 recom[i] = new Recommendation(EXTERNAL_WMS_FACTORY, ids); | 301 recom[i] = new Recommendation(EXTERNAL_WMS_FACTORY, ids); |
334 } | 302 } |
335 | 303 |
336 Collection c = getCollection(); | 304 final Collection c = getCollection(); |
337 | 305 |
338 Config config = Config.getInstance(); | 306 final Config config = Config.getInstance(); |
339 String locale = config.getLocale(); | 307 final String locale = config.getLocale(); |
340 | 308 |
341 loadArtifactService.loadMany(c, recom, EXTERNAL_WMS_FACTORY, locale, | 309 this.loadArtifactService.loadMany(c, recom, EXTERNAL_WMS_FACTORY, locale, new AsyncCallback<Artifact[]>() { |
342 new AsyncCallback<Artifact[]>() { | 310 |
343 | 311 @Override |
344 @Override | 312 public void onFailure(final Throwable throwable) { |
345 public void onFailure(Throwable throwable) { | 313 SC.warn(MapOutputTab.this.MSG.getString(throwable.getMessage())); |
346 SC.warn(MSG.getString(throwable.getMessage())); | 314 } |
347 } | 315 |
348 | 316 @Override |
349 @Override | 317 public void onSuccess(final Artifact[] newArtifacts) { |
350 public void onSuccess(Artifact[] newArtifacts) { | 318 getThemePanel().updateCollection(); |
351 getThemePanel().updateCollection(); | 319 } |
352 } | 320 }); |
353 } | 321 } |
354 ); | 322 |
355 } | 323 protected void setFloodmap(final FloodMap floodMap) { |
356 | |
357 | |
358 protected void setFloodmap(FloodMap floodMap) { | |
359 this.floodMap = floodMap; | 324 this.floodMap = floodMap; |
360 } | 325 } |
361 | 326 |
362 | |
363 protected FloodMap getFloodmap() { | 327 protected FloodMap getFloodmap() { |
364 return floodMap; | 328 return this.floodMap; |
365 } | 329 } |
366 | |
367 | 330 |
368 protected Map getMap() { | 331 protected Map getMap() { |
369 return floodMap.getMap(); | 332 return this.floodMap.getMap(); |
370 } | 333 } |
371 | |
372 | 334 |
373 protected ThemePanel getThemePanel() { | 335 protected ThemePanel getThemePanel() { |
374 return themePanel; | 336 return this.themePanel; |
375 } | 337 } |
376 | 338 |
377 | 339 protected String getGeoJSONFromDynamic(final ArtifactDescription desc) { |
378 protected String getGeoJSONFromDynamic(ArtifactDescription desc) { | 340 final DataList list = desc.getCurrentData(); |
379 DataList list = desc.getCurrentData(); | |
380 | 341 |
381 if (list == null) { | 342 if (list == null) { |
382 return null; | 343 return null; |
383 } | 344 } |
384 | 345 |
385 List<Data> datas = list.getAll(); | 346 final List<Data> datas = list.getAll(); |
386 for (Data data: datas) { | 347 for (final Data data : datas) { |
387 String key = data.getLabel(); | 348 final String key = data.getLabel(); |
388 | 349 |
389 if (key != null && key.equals(BARRIERS_PARAMETER_KEY)) { | 350 if (key != null && key.equals(BARRIERS_PARAMETER_KEY)) { |
390 DataItem def = data.getDefault(); | 351 final DataItem def = data.getDefault(); |
391 | 352 |
392 if (def != null) { | 353 if (def != null) { |
393 return def.getStringValue(); | 354 return def.getStringValue(); |
394 } | 355 } |
395 } | 356 } |
396 } | 357 } |
397 | 358 |
398 return null; | 359 return null; |
399 } | 360 } |
400 | 361 |
401 | 362 protected String getGeoJSONFromStatic(final ArtifactDescription desc) { |
402 protected String getGeoJSONFromStatic(ArtifactDescription desc) { | |
403 // TODO Implement this method, if there are reachable states right after | 363 // TODO Implement this method, if there are reachable states right after |
404 // the floodmap state - which is currently not the case. | 364 // the floodmap state - which is currently not the case. |
405 return null; | 365 return null; |
406 } | 366 } |
407 | 367 |
408 | |
409 public ThemeList getThemeList() { | 368 public ThemeList getThemeList() { |
410 return collection.getThemeList(mode.getName()); | 369 return this.collection.getThemeList(this.mode.getName()); |
411 } | 370 } |
412 | |
413 | 371 |
414 public String getSrid() { | 372 public String getSrid() { |
415 ThemeList themeList = getThemeList(); | 373 final ThemeList themeList = getThemeList(); |
416 | 374 |
417 int num = themeList.getThemeCount(); | 375 final int num = themeList.getThemeCount(); |
418 | 376 |
419 for (int i = 1; i <= num; i++) { | 377 for (int i = 1; i <= num; i++) { |
420 AttributedTheme theme = (AttributedTheme) themeList.getThemeAt(i); | 378 final AttributedTheme theme = (AttributedTheme) themeList.getThemeAt(i); |
421 | 379 |
422 if (theme == null) { | 380 if (theme == null) { |
423 continue; | 381 continue; |
424 } | 382 } |
425 | 383 |
426 String srid = theme.getAttr("srid"); | 384 final String srid = theme.getAttr("srid"); |
427 | 385 |
428 if (srid != null && srid.length() > 0) { | 386 if (srid != null && srid.length() > 0) { |
429 return srid; | 387 return srid; |
430 } | 388 } |
431 } | 389 } |
432 | 390 |
433 return DEFAULT_SRID; | 391 return DEFAULT_SRID; |
434 } | 392 } |
435 | 393 |
436 | 394 protected Bounds boundsFromString(final String bounds) { |
437 protected Bounds boundsFromString(String bounds) { | |
438 GWT.log("Create Bounds from String: '" + bounds + "'"); | 395 GWT.log("Create Bounds from String: '" + bounds + "'"); |
439 if (bounds == null || bounds.length() == 0) { | 396 if (bounds == null || bounds.length() == 0) { |
440 return null; | 397 return null; |
441 } | 398 } |
442 | 399 |
443 String[] values = bounds.split(" "); | 400 final String[] values = bounds.split(" "); |
444 | 401 |
445 if (values == null || values.length < 4) { | 402 if (values == null || values.length < 4) { |
446 return null; | 403 return null; |
447 } | 404 } |
448 | 405 |
449 try { | 406 try { |
450 return new Bounds( | 407 return new Bounds(Double.valueOf(values[0]), Double.valueOf(values[1]), Double.valueOf(values[2]), Double.valueOf(values[3])); |
451 Double.valueOf(values[0]), | 408 } |
452 Double.valueOf(values[1]), | 409 catch (final NumberFormatException nfe) { |
453 Double.valueOf(values[2]), | 410 } |
454 Double.valueOf(values[3])); | |
455 } | |
456 catch (NumberFormatException nfe) {} | |
457 | 411 |
458 return null; | 412 return null; |
459 } | 413 } |
460 | 414 |
461 | 415 private Layer createWMSLayer(final Theme theme) { |
462 public Layer createWMSLayer(Theme theme) { | |
463 if (!(theme instanceof AttributedTheme)) { | 416 if (!(theme instanceof AttributedTheme)) { |
464 return null; | 417 return null; |
465 } | 418 } |
466 | 419 |
467 AttributedTheme at = (AttributedTheme) theme; | 420 final AttributedTheme at = (AttributedTheme) theme; |
468 | 421 |
469 String name = at.getAttr("name"); | 422 // final String desc = at.getAttr("description"); |
470 String desc = at.getAttr("description"); | 423 final String url = at.getAttr("url"); |
471 String url = at.getAttr("url"); | 424 final String layers = at.getAttr("layers"); |
472 String layers = at.getAttr("layers"); | 425 |
426 final String layerId = getLayerId(theme); | |
473 | 427 |
474 if (url == null || layers == null) { | 428 if (url == null || layers == null) { |
475 return null; | 429 return null; |
476 } | 430 } |
477 | 431 |
478 WMSParams params = new WMSParams(); | 432 final WMSParams params = new WMSParams(); |
479 params.setLayers(layers); | 433 params.setLayers(layers); |
480 params.setFormat("image/png"); | 434 params.setFormat("image/png"); |
481 params.setIsTransparent(true); | 435 params.setIsTransparent(true); |
482 | 436 |
483 WMSOptions opts = new WMSOptions(); | 437 final WMSOptions opts = new WMSOptions(); |
438 | |
484 opts.setProjection("EPSG:" + getSrid()); | 439 opts.setProjection("EPSG:" + getSrid()); |
485 opts.setSingleTile(true); | 440 opts.setSingleTile(true); |
486 opts.setRatio(1); | 441 opts.setRatio(1); |
487 if (layers.equals("OSM-WMS-Dienst")) { | 442 if (layers.equals("OSM-WMS-Dienst")) { |
488 opts.setAttribution(MSG.attribution()); | 443 opts.setAttribution(this.MSG.attribution()); |
489 opts.setSingleTile(true); | 444 opts.setSingleTile(true); |
490 opts.setTransitionEffect(TransitionEffect.RESIZE); | 445 opts.setTransitionEffect(TransitionEffect.RESIZE); |
491 } | 446 } |
492 WMS wms = new WMS(layers, url, params, opts); | 447 final WMS wms = new WMS(layerId, url, params, opts); |
493 wms.setIsVisible(at.getActive() == 1); | 448 wms.setIsVisible(at.getActive() == 1); |
494 wms.setIsBaseLayer(false); | 449 wms.setIsBaseLayer(false); |
495 // We can't set the full_url attribute here because map is not set | 450 // We can't set the full_url attribute here because map is not set |
496 // at.addAttr("full_url", wms.getFullRequestString(params, null)); | 451 // at.addAttr("full_url", wms.getFullRequestString(params, null)); |
497 return wms; | 452 return wms; |
498 } | 453 } |
499 | 454 |
500 | 455 private String getLayerId(final Theme theme) { |
501 public java.util.Map<String, String> wmsUrls() { | 456 |
502 return this.wmsUrls; | 457 final AttributedTheme at = (AttributedTheme) theme; |
503 } | 458 |
504 | 459 final String name = at.getAttr("name"); |
460 final String layers = at.getAttr("layers"); | |
461 | |
462 return name + "_" + layers; | |
463 } | |
505 | 464 |
506 protected MapToolbar createControlPanel() { | 465 protected MapToolbar createControlPanel() { |
507 return new MapToolbar(this, floodMap, false); | 466 return new MapToolbar(this, this.floodMap, false); |
508 } | 467 } |
509 | |
510 | 468 |
511 protected Canvas createThemePanel() { | 469 protected Canvas createThemePanel() { |
512 Canvas c = new Canvas(); | 470 final Canvas c = new Canvas(); |
513 c.setMinWidth(300); | 471 c.setMinWidth(300); |
514 c.setWidth(200); | 472 c.setWidth(200); |
515 c.setHeight100(); | 473 c.setHeight100(); |
516 c.setCanDragResize(true); | 474 c.setCanDragResize(true); |
517 c.setBorder("1px solid black"); | 475 c.setBorder("1px solid black"); |
518 | 476 |
519 themePanel = new MapThemePanel( | 477 this.themePanel = new MapThemePanel(this.getCollectionView(), this.mode, this, new MapThemePanel.ActivateCallback() { |
520 this.getCollectionView(), | 478 @Override |
521 mode, | 479 public void activate(final Theme theme, final boolean active) { |
522 this, | 480 fireActivateTheme(theme, active); |
523 new MapThemePanel.ActivateCallback() { | 481 } |
524 @Override | 482 }, new MapThemePanel.ThemeMovedCallback() { |
525 public void activate(Theme theme, boolean active) { | 483 @Override |
526 fireActivateTheme(theme, active); | 484 public void onThemeMoved(final Theme theme, final int oldIdx, final int newIdx) { |
485 // this code synchronizes the ThemePanel and the OpenLayers | |
486 // internal order of layers. | |
487 final AttributedTheme at = (AttributedTheme) theme; | |
488 | |
489 final String layerId = getLayerId(theme); | |
490 | |
491 final Map map = getMap(); | |
492 final Layer[] layers = map.getLayersByName(layerId); | |
493 | |
494 if (layers == null || layers.length == 0) { | |
495 GWT.log("Error: Cannot find layer '" + layerId + "'"); | |
496 return; | |
527 } | 497 } |
528 }, | 498 |
529 new MapThemePanel.ThemeMovedCallback() { | 499 map.raiseLayer(layers[0], (newIdx - oldIdx) * -1); |
530 @Override | 500 map.zoomTo(map.getZoom() - 1); |
531 public void onThemeMoved(Theme theme, int oldIdx, int newIdx) { | 501 map.zoomTo(map.getZoom() + 1); |
532 // this code synchronizes the ThemePanel and the OpenLayers | 502 } |
533 // internal order of layers. | 503 }, new MapThemePanel.LayerZoomCallback() { |
534 AttributedTheme at = (AttributedTheme) theme; | 504 @Override |
535 | 505 public void onLayerZoom(final Theme theme, final String extent) { |
536 String name = at.getAttr("layers"); | 506 final Bounds zoomTo = boundsFromString(extent); |
537 Map map = getMap(); | 507 |
538 Layer[] layers = map.getLayersByName(name); | 508 if (zoomTo == null) { |
539 | 509 GWT.log("WARNING: No valid bounds for zooming found!"); |
540 if (layers == null || layers.length == 0) { | 510 return; |
541 GWT.log("Error: Cannot find layer '" + name + "'"); | |
542 return; | |
543 } | |
544 | |
545 map.raiseLayer(layers[0], (newIdx-oldIdx)*-1); | |
546 map.zoomTo(map.getZoom()-1); | |
547 map.zoomTo(map.getZoom()+1); | |
548 } | 511 } |
549 }, | 512 |
550 new MapThemePanel.LayerZoomCallback() { | 513 getMap().zoomToExtent(zoomTo); |
551 @Override | 514 } |
552 public void onLayerZoom(Theme theme, String extent) { | 515 }); |
553 Bounds zoomTo = boundsFromString(extent); | 516 this.themePanel.addRedrawRequestHandler(this); |
554 | 517 this.themePanel.addOutputParameterChangeHandler(this); |
555 if (zoomTo == null) { | 518 c.addChild(this.themePanel); |
556 GWT.log("WARNING: No valid bounds for zooming found!"); | |
557 return; | |
558 } | |
559 | |
560 getMap().zoomToExtent(zoomTo); | |
561 } | |
562 } | |
563 ); | |
564 themePanel.addRedrawRequestHandler(this); | |
565 themePanel.addOutputParameterChangeHandler(this); | |
566 c.addChild(themePanel); | |
567 | 519 |
568 return c; | 520 return c; |
569 } | 521 } |
570 | 522 |
571 | 523 private void fireActivateTheme(final Theme theme, final boolean active) { |
572 private void fireActivateTheme(Theme theme, boolean active) { | |
573 activateTheme(theme, active); | 524 activateTheme(theme, active); |
574 } | 525 } |
575 | 526 |
576 | 527 protected void activateTheme(final Theme theme, final boolean active) { |
577 protected void activateTheme(Theme theme, boolean active) { | 528 |
578 AttributedTheme at = (AttributedTheme) theme; | 529 final String layerId = getLayerId(theme); |
579 | 530 |
580 String name = at.getAttr("layers"); | 531 final Layer layer = this.floodMap.getMap().getLayerByName(layerId); |
581 Layer layer = floodMap.getMap().getLayerByName(name); | 532 |
582 | 533 GWT.log("Set visibility of '" + layerId + "': " + active); |
583 GWT.log("Set visibility of '" + name + "': " + active); | |
584 | 534 |
585 if (layer != null) { | 535 if (layer != null) { |
586 layer.setIsVisible(active); | 536 layer.setIsVisible(active); |
587 } | 537 } |
588 } | 538 } |
589 | 539 |
590 | |
591 protected void saveBarriers() { | 540 protected void saveBarriers() { |
592 Vector layer = floodMap.getBarrierLayer(); | 541 final Vector layer = this.floodMap.getBarrierLayer(); |
593 | 542 |
594 GeoJSON format = new GeoJSON(); | 543 final GeoJSON format = new GeoJSON(); |
595 String features = format.write(layer.getFeatures()); | 544 final String features = format.write(layer.getFeatures()); |
596 | 545 |
597 DataItem item = new DefaultDataItem( | 546 final DataItem item = new DefaultDataItem(BARRIERS_PARAMETER_KEY, BARRIERS_PARAMETER_KEY, features); |
598 BARRIERS_PARAMETER_KEY, BARRIERS_PARAMETER_KEY, features); | 547 |
599 | 548 final Data data = new DefaultData(BARRIERS_PARAMETER_KEY, BARRIERS_PARAMETER_KEY, "String", new DataItem[] { item }); |
600 Data data = new DefaultData( | 549 |
601 BARRIERS_PARAMETER_KEY, BARRIERS_PARAMETER_KEY, "String", | 550 final Config config = Config.getInstance(); |
602 new DataItem[] {item} ); | 551 final String locale = config.getLocale(); |
603 | 552 |
604 Config config = Config.getInstance(); | 553 this.feedService.go(locale, getArtifact(), new Data[] { data }, new AsyncCallback<Artifact>() { |
605 String locale = config.getLocale(); | 554 @Override |
606 | 555 public void onFailure(final Throwable caught) { |
607 feedService.go(locale, getArtifact(), new Data[] { data }, | 556 GWT.log("Could not save barrier geometries: " + caught.getMessage()); |
608 new AsyncCallback<Artifact>() { | 557 } |
609 @Override | 558 |
610 public void onFailure(Throwable caught) { | 559 @Override |
611 GWT.log("Could not save barrier geometries: " + | 560 public void onSuccess(final Artifact artifact) { |
612 caught.getMessage()); | 561 GWT.log("Successfully saved barrier geometries."); |
613 } | 562 } |
614 | 563 }); |
615 @Override | 564 } |
616 public void onSuccess(Artifact artifact) { | |
617 GWT.log("Successfully saved barrier geometries."); | |
618 } | |
619 } | |
620 ); | |
621 } | |
622 | |
623 | 565 |
624 @Override | 566 @Override |
625 public void onTabSelected(TabSelectedEvent tse) { | 567 public void onTabSelected(final TabSelectedEvent tse) { |
626 if(floodMap == null) { | 568 if (this.floodMap == null) { |
627 return; | 569 return; |
628 } | 570 } |
629 if(this.equals(tse.getTab())) { | 571 if (this.equals(tse.getTab())) { |
630 floodMap.activateScaleLine(true); | 572 this.floodMap.activateScaleLine(true); |
631 } | 573 } else { |
632 else { | 574 this.controlPanel.activateMeasureControl(false); |
633 controlPanel.activateMeasureControl(false); | 575 this.floodMap.activateScaleLine(false); |
634 floodMap.activateScaleLine(false); | |
635 } | 576 } |
636 } | 577 } |
637 | 578 |
638 public void toogleThemePanel() { | 579 public void toogleThemePanel() { |
639 this.themePanelCanvas.setVisible(!themePanelCanvas.isVisible()); | 580 this.themePanelCanvas.setVisible(!this.themePanelCanvas.isVisible()); |
640 | 581 |
641 // Trigger resize event handler | 582 // Trigger resize event handler |
642 doLayout(); | 583 doLayout(); |
643 } | 584 } |
644 | 585 |
645 | |
646 @Override | 586 @Override |
647 public void onOutputParameterChanged(OutputParameterChangeEvent evt) { | 587 public void onOutputParameterChanged(final OutputParameterChangeEvent evt) { |
648 GWT.log("OutputParameterChanged"); | 588 GWT.log("OutputParameterChanged"); |
649 controlPanel.updateThemes(getThemePanel().getThemeList()); | 589 this.controlPanel.updateThemes(getThemePanel().getThemeList()); |
590 } | |
591 | |
592 public String getWMSUrl(final Theme theme) { | |
593 final String layerId = getLayerId(theme); | |
594 return this.wmsUrls.get(layerId); | |
650 } | 595 } |
651 } | 596 } |
652 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |