changeset 833:dcecdd9693a8

Added a UIProvider that displays a combobox on the left and a map widget in the helper container. flys-client/trunk@2544 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 24 Aug 2011 08:36:51 +0000
parents 303a923d232b
children 77469d7f3c93
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/DigitizePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java
diffstat 5 files changed, 216 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Aug 24 08:32:23 2011 +0000
+++ b/flys-client/ChangeLog	Wed Aug 24 08:36:51 2011 +0000
@@ -1,3 +1,19 @@
+2011-08-24  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/DigitizePanel.java:
+	  New. A subclass of the SelectProvider which displays combo boxes on the
+	  left and a map panel in the helper container.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java:
+	  Added a property that allows initializing the toolbar with no digitize
+	  controls.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java:
+	  Added a method that returns the vector features as GeoJSON string.
+
+	* src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java:
+	  Creates a DigitizePanel if the uiprovider string "map_digitize" is set.
+
 2011-08-24  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/map/MapPanel.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DigitizePanel.java	Wed Aug 24 08:36:51 2011 +0000
@@ -0,0 +1,170 @@
+package de.intevation.flys.client.client.ui;
+
+import java.util.List;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+import com.smartgwt.client.util.SC;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.events.ResizedEvent;
+import com.smartgwt.client.widgets.events.ResizedHandler;
+
+import org.gwtopenmaps.openlayers.client.Map;
+import org.gwtopenmaps.openlayers.client.feature.VectorFeature;
+import org.gwtopenmaps.openlayers.client.format.GeoJSON;
+import org.gwtopenmaps.openlayers.client.layer.WMS;
+import org.gwtopenmaps.openlayers.client.layer.WMSParams;
+import org.gwtopenmaps.openlayers.client.layer.WMSOptions;
+
+import de.intevation.flys.client.shared.model.Data;
+import de.intevation.flys.client.shared.model.DataItem;
+import de.intevation.flys.client.shared.model.DataList;
+import de.intevation.flys.client.shared.model.DefaultData;
+import de.intevation.flys.client.shared.model.DefaultDataItem;
+import de.intevation.flys.client.shared.model.MapInfo;
+
+import de.intevation.flys.client.client.Config;
+import de.intevation.flys.client.client.ui.map.FloodMap;
+import de.intevation.flys.client.client.ui.map.MapPanel;
+import de.intevation.flys.client.client.services.MapInfoService;
+import de.intevation.flys.client.client.services.MapInfoServiceAsync;
+
+
+public class DigitizePanel extends SelectProvider {
+
+    protected MapInfoServiceAsync mapInfo = GWT.create(MapInfoService.class);
+
+    protected FloodMap floodMap;
+
+
+    public static final String UESK_BARRIERS = "uesk.barriers";
+
+
+    public DigitizePanel() {
+    }
+
+
+    @Override
+    public Canvas create(DataList list) {
+        List<Data> data = list.getAll();
+
+        Data barriers = null;
+        for (int i = data.size()-1; i >= 0; i--) {
+            Data d = data.get(i);
+            if (d.getLabel().equals(UESK_BARRIERS)) {
+                barriers = d;
+                data.remove(d);
+            }
+        }
+
+        Canvas selectBox = super.create(list);
+
+        final Config cfg    = Config.getInstance();
+        final String url    = cfg.getServerUrl();
+        final String locale = cfg.getLocale();
+
+        DataItem[] obj = barriers.getItems();
+
+        final String[] geojson = new String[1];
+        for (DataItem item: obj) {
+            if (item.getLabel().equals(UESK_BARRIERS)) {
+                geojson[0] = item.getStringValue();
+                break;
+            }
+        }
+
+        // TODO FIND CORRECT RIVER
+        mapInfo.getMapInfo(url, locale, "Saar", new AsyncCallback<MapInfo>() {
+            public void onFailure(Throwable caught) {
+                String msg = caught.getMessage();
+
+                GWT.log("Error while fetching MapInfo: " + msg);
+                SC.warn(MSG.getString(msg));
+            }
+
+            public void onSuccess(MapInfo info) {
+                createMapWidget(info, geojson[0]);
+            }
+        });
+
+        return selectBox;
+    }
+
+
+    @Override
+    protected Data[] getData() {
+        Data[] data  = super.getData();
+        Data[] total = new Data[2];
+
+        DataItem item = new DefaultDataItem(
+            UESK_BARRIERS, UESK_BARRIERS, floodMap.getFeaturesAsGeoJSON());
+
+        total[0] = data[0];
+        total[1] = new DefaultData(
+            UESK_BARRIERS, null, null, new DataItem[] { item });
+
+        return total;
+    }
+
+
+    public void createMapWidget(MapInfo mapInfo, String geojson) {
+        final MapPanel mapPanel = new MapPanel(mapInfo, true);
+
+        floodMap = mapPanel.getFloodMap();
+        Map map  = floodMap.getMap();
+
+        helperContainer.addMember(mapPanel);
+        helperContainer.addResizedHandler(new ResizedHandler() {
+            public void onResized(ResizedEvent e) {
+                Integer height = helperContainer.getHeight();
+                Integer width  = helperContainer.getWidth();
+
+                height = height * 99 / 100;
+                width  = width  * 99 / 100;
+
+                String w = String.valueOf(width) + "px";
+                String h = String.valueOf(height) + "px";
+
+                mapPanel.getFloodMap().setSize(w, h);
+            }
+        });
+
+        WMS axis = getLayer(
+            mapInfo.getWmsUrl(), "riveraxis",
+            mapInfo.getProjection(), false);
+        WMS back = getLayer(
+            mapInfo.getBackgroundWmsUrl(), mapInfo.getBackgroundWmsLayers(),
+            mapInfo.getProjection(), false);
+
+        map.addLayer(axis);
+        map.addLayer(back);
+
+        if (geojson != null && geojson.length() > 0) {
+            VectorFeature[] features = new GeoJSON().read(geojson);
+            floodMap.getBarrierLayer().addFeatures(features);
+        }
+
+        map.zoomToMaxExtent();
+    }
+
+
+    protected WMS getLayer(String url, String layers, String proj, boolean x) {
+        WMSParams params = new WMSParams();
+        params.setLayers(layers);
+        params.setFormat("image/png");
+        params.setIsTransparent(!x);
+
+        WMSOptions opts = new WMSOptions();
+        opts.setProjection(proj);
+        opts.setSingleTile(true);
+        opts.setRatio(1);
+
+        WMS wms = new WMS(layers, url, params, opts);
+        wms.setIsVisible(true);
+        wms.setIsBaseLayer(x);
+
+        return wms;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Wed Aug 24 08:32:23 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Wed Aug 24 08:36:51 2011 +0000
@@ -49,6 +49,9 @@
         else if (uiProvider.equals("noinput")) {
             return new NoInputPanel();
         }
+        else if (uiProvider.equals("map_digitize")) {
+            return new DigitizePanel();
+        }
         else {
             return new SelectProvider();
         }
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java	Wed Aug 24 08:32:23 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java	Wed Aug 24 08:36:51 2011 +0000
@@ -4,6 +4,8 @@
 import org.gwtopenmaps.openlayers.client.Map;
 import org.gwtopenmaps.openlayers.client.MapOptions;
 import org.gwtopenmaps.openlayers.client.MapWidget;
+import org.gwtopenmaps.openlayers.client.feature.VectorFeature;
+import org.gwtopenmaps.openlayers.client.format.GeoJSON;
 import org.gwtopenmaps.openlayers.client.layer.Vector;
 import org.gwtopenmaps.openlayers.client.layer.VectorOptions;
 import org.gwtopenmaps.openlayers.client.util.JObjectArray;
@@ -70,6 +72,17 @@
     }
 
 
+    public String getFeaturesAsGeoJSON() {
+        VectorFeature[] features = barrierLayer.getFeatures();
+
+        if (features == null || features.length == 0) {
+            return null;
+        }
+
+        return new GeoJSON().write(features);
+    }
+
+
     public void setSize(String width, String height) {
         mapWidget.setWidth(width);
         mapWidget.setHeight(height);
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java	Wed Aug 24 08:32:23 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java	Wed Aug 24 08:36:51 2011 +0000
@@ -50,6 +50,11 @@
 
 
     public MapToolbar(FloodMap floodMap, Canvas wrapper) {
+        this(floodMap, wrapper, true);
+    }
+
+
+    public MapToolbar(FloodMap floodMap, Canvas wrapper, boolean digitize) {
         super();
 
         setWidth100();
@@ -67,19 +72,23 @@
         zoomBoxButton   = createZoomBoxControl();
         zoomOutButton   = createZoomOutControl();
         panButton       = createPanControl();
-        position        = createMousePosition(wrapper);
         drawControl     = createDrawControl();
         selectButton    = createSelectFeatureControl();
+        measureControl  = createMeasureControl();
+        position        = createMousePosition(wrapper);
         removeButton    = createRemoveFeatureControl();
-        measureControl  = createMeasureControl();
 
         addMember(zoomToMaxButton);
         addMember(zoomBoxButton);
         addMember(zoomOutButton);
         addMember(panButton);
-        addMember(drawControl);
-        addMember(selectButton);
-        addMember(removeButton);
+
+        if (digitize) {
+            addMember(drawControl);
+            addMember(selectButton);
+            addMember(removeButton);
+        }
+
         addMember(measureControl);
         addMember(spacer);
         addMember(position);

http://dive4elements.wald.intevation.org