Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java @ 882:d3b4010d2c89
I293: Set the style of digitized features in the map.
flys-client/trunk@2713 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 13 Sep 2011 07:18:14 +0000 |
parents | 4af1ee86b0b1 |
children | 89a47098bcbd |
comparison
equal
deleted
inserted
replaced
881:4af1ee86b0b1 | 882:d3b4010d2c89 |
---|---|
2 | 2 |
3 import org.gwtopenmaps.openlayers.client.Bounds; | 3 import org.gwtopenmaps.openlayers.client.Bounds; |
4 import org.gwtopenmaps.openlayers.client.Map; | 4 import org.gwtopenmaps.openlayers.client.Map; |
5 import org.gwtopenmaps.openlayers.client.MapOptions; | 5 import org.gwtopenmaps.openlayers.client.MapOptions; |
6 import org.gwtopenmaps.openlayers.client.MapWidget; | 6 import org.gwtopenmaps.openlayers.client.MapWidget; |
7 import org.gwtopenmaps.openlayers.client.Style; | |
8 import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener; | |
9 import org.gwtopenmaps.openlayers.client.event.VectorFeatureAddedListener.FeatureAddedEvent; | |
7 import org.gwtopenmaps.openlayers.client.feature.VectorFeature; | 10 import org.gwtopenmaps.openlayers.client.feature.VectorFeature; |
8 import org.gwtopenmaps.openlayers.client.format.GeoJSON; | 11 import org.gwtopenmaps.openlayers.client.format.GeoJSON; |
9 import org.gwtopenmaps.openlayers.client.layer.Vector; | 12 import org.gwtopenmaps.openlayers.client.layer.Vector; |
10 import org.gwtopenmaps.openlayers.client.layer.VectorOptions; | 13 import org.gwtopenmaps.openlayers.client.layer.VectorOptions; |
14 import org.gwtopenmaps.openlayers.client.util.Attributes; | |
11 import org.gwtopenmaps.openlayers.client.util.JObjectArray; | 15 import org.gwtopenmaps.openlayers.client.util.JObjectArray; |
12 import org.gwtopenmaps.openlayers.client.util.JSObject; | 16 import org.gwtopenmaps.openlayers.client.util.JSObject; |
13 | 17 |
14 | 18 |
15 public class FloodMap { | 19 public class FloodMap implements VectorFeatureAddedListener { |
16 | 20 |
17 public static final String LAYER_BARRIERS = "vector_layer_barriers"; | 21 public static final String LAYER_BARRIERS = "vector_layer_barriers"; |
18 | 22 |
19 protected MapWidget mapWidget; | 23 protected MapWidget mapWidget; |
20 protected Map map; | 24 protected Map map; |
40 | 44 |
41 getBarrierLayer(); | 45 getBarrierLayer(); |
42 } | 46 } |
43 | 47 |
44 | 48 |
49 @Override | |
50 public void onFeatureAdded(FeatureAddedEvent evt) { | |
51 VectorFeature feature = evt.getVectorFeature(); | |
52 | |
53 Attributes attrs = feature.getAttributes(); | |
54 String type = attrs.getAttributeAsString("typ"); | |
55 | |
56 if (type == null || type.length() == 0) { | |
57 return; | |
58 } | |
59 | |
60 feature.setStyle(getStyle(type)); | |
61 | |
62 // necessary, otherwise the setStyle() has no effect | |
63 barrierLayer.redraw(); | |
64 } | |
65 | |
66 | |
67 /** | |
68 * Returns an OpenLayers.Style based on a given type. | |
69 * | |
70 * @param type Type can be one of "pipe1", "pipe2", "ditch", "dam", | |
71 * "ringdike". | |
72 * | |
73 * @return an OpenLayers.Style object. | |
74 */ | |
75 public static Style getStyle(String type) { | |
76 Style style = new Style(); | |
77 | |
78 if (type.equals(DrawControl.BARRIER_PIPE1) | |
79 || type.equals(DrawControl.BARRIER_PIPE1_VALUE) | |
80 ) { | |
81 style.setFillColor("#800080"); | |
82 style.setStrokeColor("#800080"); | |
83 } | |
84 else if (type.equals(DrawControl.BARRIER_PIPE2) | |
85 || type.equals(DrawControl.BARRIER_PIPE2_VALUE) | |
86 ) { | |
87 style.setFillColor("#808080"); | |
88 style.setStrokeColor("#808080"); | |
89 } | |
90 else if (type.equals(DrawControl.BARRIER_DAM) | |
91 || type.equals(DrawControl.BARRIER_DAM_VALUE) | |
92 ) { | |
93 style.setFillColor("#008000"); | |
94 style.setStrokeColor("#008000"); | |
95 } | |
96 else if (type.equals(DrawControl.BARRIER_DITCH) | |
97 || type.equals(DrawControl.BARRIER_DITCH_VALUE) | |
98 ) { | |
99 style.setFillColor("#800000"); | |
100 style.setStrokeColor("#800000"); | |
101 } | |
102 else if (type.equals(DrawControl.BARRIER_RINGDIKE) | |
103 || type.equals(DrawControl.BARRIER_RINGDIKE_VALUE) | |
104 ) { | |
105 style.setFill(false); | |
106 style.setStrokeColor("#FF8000"); | |
107 } | |
108 | |
109 return style; | |
110 } | |
111 | |
112 | |
45 public MapWidget getMapWidget() { | 113 public MapWidget getMapWidget() { |
46 return mapWidget; | 114 return mapWidget; |
47 } | 115 } |
48 | 116 |
49 | 117 |
65 | 133 |
66 barrierLayer = new Vector(LAYER_BARRIERS, opts); | 134 barrierLayer = new Vector(LAYER_BARRIERS, opts); |
67 barrierLayer.setIsBaseLayer(true); | 135 barrierLayer.setIsBaseLayer(true); |
68 | 136 |
69 map.addLayer(barrierLayer); | 137 map.addLayer(barrierLayer); |
138 | |
139 barrierLayer.addVectorFeatureAddedListener(this); | |
70 } | 140 } |
71 | 141 |
72 return barrierLayer; | 142 return barrierLayer; |
73 } | 143 } |
74 | 144 |