comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java @ 825:1b9b7e9ab219

Save and reload user defined geometries (barriers) in the map. flys-client/trunk@2522 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 22 Aug 2011 13:29:55 +0000
parents 407de0f4b66a
children c89a42950d11
comparison
equal deleted inserted replaced
824:3fe265b47675 825:1b9b7e9ab219
1 package de.intevation.flys.client.client.ui.map; 1 package de.intevation.flys.client.client.ui.map;
2 2
3 import java.util.List;
4
3 import com.google.gwt.core.client.GWT; 5 import com.google.gwt.core.client.GWT;
6 import com.google.gwt.user.client.rpc.AsyncCallback;
4 import com.google.gwt.user.client.ui.HorizontalPanel; 7 import com.google.gwt.user.client.ui.HorizontalPanel;
5 import com.google.gwt.user.client.ui.Widget; 8 import com.google.gwt.user.client.ui.Widget;
6 9
7 import com.smartgwt.client.widgets.Canvas; 10 import com.smartgwt.client.widgets.Canvas;
8 import com.smartgwt.client.widgets.events.ResizedEvent; 11 import com.smartgwt.client.widgets.events.ResizedEvent;
10 import com.smartgwt.client.widgets.layout.HLayout; 13 import com.smartgwt.client.widgets.layout.HLayout;
11 import com.smartgwt.client.widgets.layout.VLayout; 14 import com.smartgwt.client.widgets.layout.VLayout;
12 15
13 import org.gwtopenmaps.openlayers.client.Bounds; 16 import org.gwtopenmaps.openlayers.client.Bounds;
14 import org.gwtopenmaps.openlayers.client.Map; 17 import org.gwtopenmaps.openlayers.client.Map;
18 import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener;
19 import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener.FeatureAddedEvent;
20 import org.gwtopenmaps.openlayers.client.event.VectorFeatureRemovedListener;
21 import org.gwtopenmaps.openlayers.client.event.VectorFeatureRemovedListener.FeatureRemovedEvent;
22 import org.gwtopenmaps.openlayers.client.feature.VectorFeature;
23 import org.gwtopenmaps.openlayers.client.format.GeoJSON;
15 import org.gwtopenmaps.openlayers.client.layer.Layer; 24 import org.gwtopenmaps.openlayers.client.layer.Layer;
25 import org.gwtopenmaps.openlayers.client.layer.Vector;
16 import org.gwtopenmaps.openlayers.client.layer.WMS; 26 import org.gwtopenmaps.openlayers.client.layer.WMS;
17 import org.gwtopenmaps.openlayers.client.layer.WMSParams; 27 import org.gwtopenmaps.openlayers.client.layer.WMSParams;
18 import org.gwtopenmaps.openlayers.client.layer.WMSOptions; 28 import org.gwtopenmaps.openlayers.client.layer.WMSOptions;
19 29
30 import de.intevation.flys.client.shared.model.Artifact;
31 import de.intevation.flys.client.shared.model.ArtifactDescription;
20 import de.intevation.flys.client.shared.model.AttributedTheme; 32 import de.intevation.flys.client.shared.model.AttributedTheme;
21 import de.intevation.flys.client.shared.model.Collection; 33 import de.intevation.flys.client.shared.model.Collection;
34 import de.intevation.flys.client.shared.model.Data;
35 import de.intevation.flys.client.shared.model.DataItem;
36 import de.intevation.flys.client.shared.model.DataList;
37 import de.intevation.flys.client.shared.model.DefaultData;
38 import de.intevation.flys.client.shared.model.DefaultDataItem;
22 import de.intevation.flys.client.shared.model.Theme; 39 import de.intevation.flys.client.shared.model.Theme;
23 import de.intevation.flys.client.shared.model.ThemeList; 40 import de.intevation.flys.client.shared.model.ThemeList;
24 import de.intevation.flys.client.shared.model.OutputMode; 41 import de.intevation.flys.client.shared.model.OutputMode;
25 42
43 import de.intevation.flys.client.client.Config;
44 import de.intevation.flys.client.client.services.StepForwardService;
45 import de.intevation.flys.client.client.services.StepForwardServiceAsync;
26 import de.intevation.flys.client.client.ui.CollectionView; 46 import de.intevation.flys.client.client.ui.CollectionView;
27 import de.intevation.flys.client.client.ui.OutputTab; 47 import de.intevation.flys.client.client.ui.OutputTab;
28 import de.intevation.flys.client.client.ui.ThemePanel; 48 import de.intevation.flys.client.client.ui.ThemePanel;
29 49
30 50
31 public class MapOutputTab extends OutputTab { 51 public class MapOutputTab extends OutputTab {
32 52
33 public static final String DEFAULT_SRID = "4326"; 53 public static final String DEFAULT_SRID = "4326";
34 54
55 public static final String BARRIERS_PARAMETER_KEY = "uesk.barriers";
56
57
58 protected StepForwardServiceAsync feedService =
59 GWT.create(StepForwardService.class);
35 60
36 protected CollectionView parent; 61 protected CollectionView parent;
37 62
38 protected Canvas controlPanel; 63 protected MapToolbar controlPanel;
39 protected ThemePanel themePanel; 64 protected ThemePanel themePanel;
40 protected Widget mapPanel; 65 protected Widget mapPanel;
41 66
42 protected FloodMap floodMap; 67 protected FloodMap floodMap;
43 68
53 78
54 floodMap = new FloodMap(getSrid(), getMaxExtent()); 79 floodMap = new FloodMap(getSrid(), getMaxExtent());
55 80
56 initLayout(); 81 initLayout();
57 initLayers(); 82 initLayers();
83 initBarriers();
58 } 84 }
59 85
60 86
61 protected void initLayout() { 87 protected void initLayout() {
62 VLayout rootLayout = new VLayout(); 88 VLayout rootLayout = new VLayout();
147 GWT.log("Maps initial extent = " + extent); 173 GWT.log("Maps initial extent = " + extent);
148 174
149 map.zoomToExtent(extent != null 175 map.zoomToExtent(extent != null
150 ? extent 176 ? extent
151 : new Bounds(-90, -180, 90, 180)); 177 : new Bounds(-90, -180, 90, 180));
178 }
179
180
181 protected void initBarriers() {
182 Vector vector = floodMap.getBarrierLayer();
183 vector.addVectorFeatureAddedListener(
184 new VectorFeatureAddedListener() {
185 public void onFeatureAdded(FeatureAddedEvent e) {
186 saveBarriers();
187 }
188 }
189 );
190
191 vector.addVectorFeatureRemovedListener(
192 new VectorFeatureRemovedListener() {
193 public void onFeatureRemoved(FeatureRemovedEvent e) {
194 saveBarriers();
195 }
196 }
197 );
198
199
200 Artifact artifact = getArtifact();
201
202 if (artifact == null) {
203 return;
204 }
205
206 ArtifactDescription desc = artifact.getArtifactDescription();
207
208 String geojson = getGeoJSONFromStatic(desc);
209 geojson = geojson != null ? geojson : getGeoJSONFromDynamic(desc);
210
211 if (geojson == null || geojson.length() == 0) {
212 GWT.log("No geojson string found -> no barriers existing.");
213 return;
214 }
215
216 GeoJSON reader = new GeoJSON();
217 VectorFeature[] features = reader.read(geojson);
218
219 vector.addFeatures(features);
220 }
221
222
223 protected String getGeoJSONFromDynamic(ArtifactDescription desc) {
224 DataList list = desc.getCurrentData();
225
226 List<Data> datas = list.getAll();
227 for (Data data: datas) {
228 String key = data.getLabel();
229
230 if (key != null && key.equals(BARRIERS_PARAMETER_KEY)) {
231 DataItem def = data.getDefault();
232
233 if (def != null) {
234 return def.getStringValue();
235 }
236 }
237 }
238
239 return null;
240 }
241
242
243 protected String getGeoJSONFromStatic(ArtifactDescription desc) {
244 // TODO Implement this method, if there are reachable states right after
245 // the floodmap state - which is currently not the case.
246 return null;
247 }
248
249
250 public Artifact getArtifact() {
251 return parent.getArtifact();
152 } 252 }
153 253
154 254
155 public ThemeList getThemeList() { 255 public ThemeList getThemeList() {
156 return collection.getThemeList(mode.getName()); 256 return collection.getThemeList(mode.getName());
262 362
263 return wms; 363 return wms;
264 } 364 }
265 365
266 366
267 protected Canvas createControlPanel(Canvas wrapper) { 367 protected MapToolbar createControlPanel(Canvas wrapper) {
268 return new MapToolbar(floodMap, wrapper); 368 return new MapToolbar(floodMap, wrapper);
269 } 369 }
270 370
271 371
272 protected Canvas createThemePanel() { 372 protected Canvas createThemePanel() {
293 393
294 if (layer != null) { 394 if (layer != null) {
295 layer.setIsVisible(active); 395 layer.setIsVisible(active);
296 } 396 }
297 } 397 }
398
399
400 protected void saveBarriers() {
401 Vector layer = floodMap.getBarrierLayer();
402
403 GeoJSON format = new GeoJSON();
404 String features = format.write(layer.getFeatures());
405
406 DataItem item = new DefaultDataItem(
407 BARRIERS_PARAMETER_KEY, BARRIERS_PARAMETER_KEY, features);
408
409 Data data = new DefaultData(
410 BARRIERS_PARAMETER_KEY, BARRIERS_PARAMETER_KEY, "String",
411 new DataItem[] {item} );
412
413 Config config = Config.getInstance();
414 final String url = config.getServerUrl();
415 final String locale = config.getLocale();
416
417 feedService.go(url, locale, getArtifact(), new Data[] { data },
418 new AsyncCallback<Artifact>() {
419 public void onFailure(Throwable caught) {
420 GWT.log("Could not save barrier geometries: " +
421 caught.getMessage());
422 }
423
424 public void onSuccess(Artifact artifact) {
425 GWT.log("Successfully saved barrier geometries.");
426 }
427 }
428 );
429 }
298 } 430 }
299 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 431 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org