# HG changeset patch # User Ingo Weinzierl # Date 1315898294 0 # Node ID d3b4010d2c898c89d038d628c1430c63f90b06df # Parent 4af1ee86b0b19bed3c76c6d0e4daab1b18b38ecb I293: Set the style of digitized features in the map. flys-client/trunk@2713 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 4af1ee86b0b1 -r d3b4010d2c89 flys-client/ChangeLog --- a/flys-client/ChangeLog Tue Sep 13 04:57:47 2011 +0000 +++ b/flys-client/ChangeLog Tue Sep 13 07:18:14 2011 +0000 @@ -1,3 +1,13 @@ +2011-09-13 Ingo Weinzierl + + flys/issue293 (Karte: Farbliche Anpassung der digitalisierten Objekte) + + * src/main/java/de/intevation/flys/client/client/ui/map/DrawControl.java, + src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java: Set + style attribute for newly created vector features. The styled is based + on the "type" attribute of a feature. FloodMap.getStyle(String type) + returns the Style for the specified type. + 2011-09-13 Ingo Weinzierl flys/issue289 (Karte: Messen von Strecken und Flächen in falscher diff -r 4af1ee86b0b1 -r d3b4010d2c89 flys-client/src/main/java/de/intevation/flys/client/client/ui/map/DrawControl.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/DrawControl.java Tue Sep 13 04:57:47 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/DrawControl.java Tue Sep 13 07:18:14 2011 +0000 @@ -39,6 +39,12 @@ public static final String BARRIER_DAM = "dam"; public static final String BARRIER_RINGDIKE = "ring_dike"; + public static final String BARRIER_PIPE1_VALUE = "Rohr 1"; + public static final String BARRIER_PIPE2_VALUE = "Rohr 2"; + public static final String BARRIER_DITCH_VALUE = "Graben"; + public static final String BARRIER_DAM_VALUE = "Damm"; + public static final String BARRIER_RINGDIKE_VALUE = "Ringdeich"; + public static final String FIELD_BARRIER_TYPE = "field_barrier_type"; @@ -139,21 +145,25 @@ if (type == null || type.length() == 0) { type = getSelectedType(); + feature.setStyle(FloodMap.getStyle(type)); + if (type.equals(BARRIER_PIPE1)) { - attrs.setAttribute("typ", "Rohr 1"); + attrs.setAttribute("typ", BARRIER_PIPE1_VALUE); } else if (type.equals(BARRIER_PIPE2)) { - attrs.setAttribute("typ", "Rohr 2"); + attrs.setAttribute("typ", BARRIER_PIPE2_VALUE); } else if (type.equals(BARRIER_DAM)) { - attrs.setAttribute("typ", "Damm"); + attrs.setAttribute("typ", BARRIER_DAM_VALUE); } else if (type.equals(BARRIER_DITCH)) { - attrs.setAttribute("typ", "Graben"); + attrs.setAttribute("typ", BARRIER_DITCH_VALUE); } else if (type.equals(BARRIER_RINGDIKE)) { - attrs.setAttribute("typ", "Ringdeich"); + attrs.setAttribute("typ", BARRIER_RINGDIKE_VALUE); } + + layer.redraw(); } } diff -r 4af1ee86b0b1 -r d3b4010d2c89 flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java Tue Sep 13 04:57:47 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java Tue Sep 13 07:18:14 2011 +0000 @@ -4,15 +4,19 @@ import org.gwtopenmaps.openlayers.client.Map; import org.gwtopenmaps.openlayers.client.MapOptions; import org.gwtopenmaps.openlayers.client.MapWidget; +import org.gwtopenmaps.openlayers.client.Style; +import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener; +import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener.FeatureAddedEvent; 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.Attributes; import org.gwtopenmaps.openlayers.client.util.JObjectArray; import org.gwtopenmaps.openlayers.client.util.JSObject; -public class FloodMap { +public class FloodMap implements VectorFeatureAddedListener { public static final String LAYER_BARRIERS = "vector_layer_barriers"; @@ -42,6 +46,70 @@ } + @Override + public void onFeatureAdded(FeatureAddedEvent evt) { + VectorFeature feature = evt.getVectorFeature(); + + Attributes attrs = feature.getAttributes(); + String type = attrs.getAttributeAsString("typ"); + + if (type == null || type.length() == 0) { + return; + } + + feature.setStyle(getStyle(type)); + + // necessary, otherwise the setStyle() has no effect + barrierLayer.redraw(); + } + + + /** + * Returns an OpenLayers.Style based on a given type. + * + * @param type Type can be one of "pipe1", "pipe2", "ditch", "dam", + * "ringdike". + * + * @return an OpenLayers.Style object. + */ + public static Style getStyle(String type) { + Style style = new Style(); + + if (type.equals(DrawControl.BARRIER_PIPE1) + || type.equals(DrawControl.BARRIER_PIPE1_VALUE) + ) { + style.setFillColor("#800080"); + style.setStrokeColor("#800080"); + } + else if (type.equals(DrawControl.BARRIER_PIPE2) + || type.equals(DrawControl.BARRIER_PIPE2_VALUE) + ) { + style.setFillColor("#808080"); + style.setStrokeColor("#808080"); + } + else if (type.equals(DrawControl.BARRIER_DAM) + || type.equals(DrawControl.BARRIER_DAM_VALUE) + ) { + style.setFillColor("#008000"); + style.setStrokeColor("#008000"); + } + else if (type.equals(DrawControl.BARRIER_DITCH) + || type.equals(DrawControl.BARRIER_DITCH_VALUE) + ) { + style.setFillColor("#800000"); + style.setStrokeColor("#800000"); + } + else if (type.equals(DrawControl.BARRIER_RINGDIKE) + || type.equals(DrawControl.BARRIER_RINGDIKE_VALUE) + ) { + style.setFill(false); + style.setStrokeColor("#FF8000"); + } + + return style; + } + + public MapWidget getMapWidget() { return mapWidget; } @@ -67,6 +135,8 @@ barrierLayer.setIsBaseLayer(true); map.addLayer(barrierLayer); + + barrierLayer.addVectorFeatureAddedListener(this); } return barrierLayer;