comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java @ 5609:80e8ef91223c

Fix for #802: digitized pipes and dikes should be visible now
author Christian Lins <christian.lins@intevation.de>
date Tue, 09 Apr 2013 12:44:57 +0200
parents 4bf3b89b38d5
children 4f935415bb20
comparison
equal deleted inserted replaced
5608:62513c9183ba 5609:80e8ef91223c
42 getBarrierLayer(); 42 getBarrierLayer();
43 } 43 }
44 44
45 45
46 public void recreateWidget(int width, int height) { 46 public void recreateWidget(int width, int height) {
47 MapOptions opts = new MapOptions(); 47 final MapOptions opts = new MapOptions();
48 opts.setControls(new JObjectArray(new JSObject[] {})); 48 opts.setControls(new JObjectArray(new JSObject[] {}));
49 opts.setNumZoomLevels(16); 49 opts.setNumZoomLevels(16);
50 opts.setProjection(getRiverProjection()); 50 opts.setProjection(getRiverProjection());
51 opts.setMaxExtent(maxExtent); 51 opts.setMaxExtent(maxExtent);
52 opts.setUnits("m"); 52 opts.setUnits("m");
61 } 61 }
62 62
63 63
64 @Override 64 @Override
65 public void onFeatureAdded(FeatureAddedEvent evt) { 65 public void onFeatureAdded(FeatureAddedEvent evt) {
66 VectorFeature feature = evt.getVectorFeature(); 66 final VectorFeature feature = evt.getVectorFeature();
67 67
68 Attributes attrs = feature.getAttributes(); 68 final Attributes attrs = feature.getAttributes();
69 String type = attrs.getAttributeAsString("typ"); 69 final String type = attrs.getAttributeAsString("typ");
70 70
71 if (type == null || type.length() == 0) { 71 if (type == null || type.length() == 0) {
72 return; 72 return;
73 } 73 }
74 74
75 Style style = getStyle(type); 75 final Style style = getStyle(type);
76 if (style != null) { 76 if (style != null) {
77 feature.setStyle(style); 77 feature.setStyle(style);
78 } 78 }
79 79
80 // necessary, otherwise the setStyle() has no effect 80 // necessary, otherwise the setStyle() has no effect
81 barrierLayer.redraw(); 81 getBarrierLayer().redraw();
82 } 82 }
83 83
84 84
85 /** 85 /**
86 * Returns an OpenLayers.Style based on a given type. 86 * Returns an OpenLayers.Style based on a given type.
89 * "ringdike". 89 * "ringdike".
90 * 90 *
91 * @return an OpenLayers.Style object. 91 * @return an OpenLayers.Style object.
92 */ 92 */
93 public static Style getStyle(String type) { 93 public static Style getStyle(String type) {
94 Style style = new Style(); 94 final Style style = new Style();
95 95
96 if (type == null) { 96 if (type == null) {
97 return null; 97 return null;
98 } 98 }
99 99
152 } 152 }
153 153
154 154
155 public Vector getBarrierLayer() { 155 public Vector getBarrierLayer() {
156 if (barrierLayer == null) { 156 if (barrierLayer == null) {
157 VectorOptions opts = new VectorOptions(); 157 final VectorOptions opts = new VectorOptions();
158 opts.setProjection(getRiverProjection()); 158 opts.setProjection(getRiverProjection());
159 opts.setMaxExtent(getMaxExtent()); 159 opts.setMaxExtent(getMaxExtent());
160 160
161 barrierLayer = new Vector(LAYER_BARRIERS, opts); 161 barrierLayer = new Vector(LAYER_BARRIERS, opts);
162 barrierLayer.setIsBaseLayer(true); 162 barrierLayer.setIsBaseLayer(true);
173 173
174 public String getFeaturesAsGeoJSON() { 174 public String getFeaturesAsGeoJSON() {
175 // disable features before exporting to GeoJSON 175 // disable features before exporting to GeoJSON
176 disableFeatures(); 176 disableFeatures();
177 177
178 VectorFeature[] features = barrierLayer.getFeatures(); 178 final VectorFeature[] features = barrierLayer.getFeatures();
179 179
180 if (features == null || features.length == 0) { 180 if (features == null || features.length == 0) {
181 return null; 181 return null;
182 } 182 }
183 183
186 186
187 187
188 public void setSize(String width, String height) { 188 public void setSize(String width, String height) {
189 mapWidget.setWidth(width); 189 mapWidget.setWidth(width);
190 mapWidget.setHeight(height); 190 mapWidget.setHeight(height);
191 int currentZoom = map.getZoom(); 191 final int currentZoom = map.getZoom();
192 LonLat currentCenter = map.getCenter(); 192 final LonLat currentCenter = map.getCenter();
193 map.updateSize(); 193 map.updateSize();
194 map.zoomTo(currentZoom); 194 map.zoomTo(currentZoom);
195 map.setCenter(currentCenter); 195 map.setCenter(currentCenter);
196 } 196 }
197 197
198 198
199 public void addLayer(Layer layer) { 199 public void addLayer(Layer layer) {
200 if (layer != null) { 200 if (layer != null) {
201 map.addLayer(layer); 201 map.addLayer(layer);
202 202
203 int index = map.getLayerIndex(layer); 203 final int index = map.getLayerIndex(layer);
204 int newIndex = index * (-1) + 1; 204 final int newIndex = index * (-1) + 1;
205 205
206 map.raiseLayer(layer, newIndex); 206 map.raiseLayer(layer, newIndex);
207 207
208 update(); 208 update();
209 } 209 }
210 } 210 }
211 211
212 212
213 public void hideBarrierLayer () { 213 public void hideBarrierLayer () {
214 if (barrierLayer != null) { 214 if (getBarrierLayer() != null) {
215 barrierLayer.setIsVisible(false); 215 barrierLayer.setIsVisible(false);
216 } 216 }
217 } 217 }
218 218
219 public void showBarrierLayer () { 219 public void showBarrierLayer () {
220 if (barrierLayer != null) { 220 if (getBarrierLayer() != null) {
221 barrierLayer.setIsVisible(true); 221 barrierLayer.setIsVisible(true);
222 } 222 }
223 } 223 }
224 224
225 225
233 public void selectFeatures(VectorFeature[] features) { 233 public void selectFeatures(VectorFeature[] features) {
234 if (features == null || features.length == 0) { 234 if (features == null || features.length == 0) {
235 return; 235 return;
236 } 236 }
237 237
238 for (VectorFeature feature: features) { 238 for (final VectorFeature feature: features) {
239 Attributes attr = feature.getAttributes(); 239 final Attributes attr = feature.getAttributes();
240 240
241 if (attr.getAttributeAsInt(MARK_SELECTED) == 1) { 241 if (attr.getAttributeAsInt(MARK_SELECTED) == 1) {
242 continue; 242 continue;
243 } 243 }
244 244
245 attr.setAttribute(MARK_SELECTED, 1); 245 attr.setAttribute(MARK_SELECTED, 1);
246 246
247 Style style = feature.getStyle(); 247 final Style style = feature.getStyle();
248 double strokeWidth = style.getStrokeWidth(); 248 final double strokeWidth = style.getStrokeWidth();
249 249
250 style.setStrokeWidth(strokeWidth+SELECTED_STROKE_WIDTH); 250 style.setStrokeWidth(strokeWidth+SELECTED_STROKE_WIDTH);
251 } 251 }
252 252
253 getBarrierLayer().redraw(); 253 getBarrierLayer().redraw();
254 } 254 }
255 255
256 256
257 public void disableFeatures() { 257 public void disableFeatures() {
258 Vector barriers = getBarrierLayer(); 258 final Vector barriers = getBarrierLayer();
259 VectorFeature[] features = barriers.getFeatures(); 259 final VectorFeature[] features = barriers.getFeatures();
260 260
261 if (features == null || features.length == 0) { 261 if (features == null || features.length == 0) {
262 return; 262 return;
263 } 263 }
264 264
276 public void disableFeatures(VectorFeature[] features) { 276 public void disableFeatures(VectorFeature[] features) {
277 if (features == null || features.length == 0) { 277 if (features == null || features.length == 0) {
278 return; 278 return;
279 } 279 }
280 280
281 for (VectorFeature feature: features) { 281 for (final VectorFeature feature: features) {
282 Attributes attr = feature.getAttributes(); 282 final Attributes attr = feature.getAttributes();
283 283
284 if (attr.getAttributeAsInt(MARK_SELECTED) == 0) { 284 if (attr.getAttributeAsInt(MARK_SELECTED) == 0) {
285 continue; 285 continue;
286 } 286 }
287 287
288 attr.setAttribute(FloodMap.MARK_SELECTED, 0); 288 attr.setAttribute(FloodMap.MARK_SELECTED, 0);
289 289
290 Style style = feature.getStyle(); 290 final Style style = feature.getStyle();
291 double strokeWidth = style.getStrokeWidth(); 291 final double strokeWidth = style.getStrokeWidth();
292 292
293 style.setStrokeWidth(strokeWidth-SELECTED_STROKE_WIDTH); 293 style.setStrokeWidth(strokeWidth-SELECTED_STROKE_WIDTH);
294 } 294 }
295 295
296 getBarrierLayer().redraw(); 296 getBarrierLayer().redraw();
297 } 297 }
298 298
299 299
300 public void update() { 300 public void update() {
301 Layer[] layers = map.getLayers(); 301 final Layer[] layers = map.getLayers();
302 302
303 for (Layer l: layers) { 303 for (final Layer l: layers) {
304 l.redraw(); 304 l.redraw();
305 } 305 }
306
307 getBarrierLayer(); // Raises Z-Index to 1000 again
306 } 308 }
307 309
308 310
309 public void activateScaleLine(boolean activate) { 311 public void activateScaleLine(boolean activate) {
310 if (activate) { 312 if (activate) {
311 ScaleLineOptions slOpts = new ScaleLineOptions(); 313 final ScaleLineOptions slOpts = new ScaleLineOptions();
312 slOpts.setBottomInUnits("m"); 314 slOpts.setBottomInUnits("m");
313 slOpts.setBottomOutUnits("km"); 315 slOpts.setBottomOutUnits("km");
314 slOpts.setTopInUnits(""); 316 slOpts.setTopInUnits("");
315 slOpts.setTopOutUnits(""); 317 slOpts.setTopOutUnits("");
316 318

http://dive4elements.wald.intevation.org