comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java @ 1315:cf0f906921de

#297 Implemented a window to adjust elevations of geometries in the map. flys-client/trunk@2954 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 13 Oct 2011 09:08:43 +0000
parents 22dc88b17253
children 45b9b1fc26e2
comparison
equal deleted inserted replaced
1314:4c716bec7822 1315:cf0f906921de
1 package de.intevation.flys.client.client.ui.map; 1 package de.intevation.flys.client.client.ui.map;
2 2
3 import com.google.gwt.core.client.GWT; 3 import com.google.gwt.core.client.GWT;
4 4
5 import com.smartgwt.client.types.SelectionType; 5 import com.smartgwt.client.types.SelectionType;
6 import com.smartgwt.client.util.SC;
6 import com.smartgwt.client.widgets.Canvas; 7 import com.smartgwt.client.widgets.Canvas;
7 import com.smartgwt.client.widgets.ImgButton; 8 import com.smartgwt.client.widgets.ImgButton;
8 import com.smartgwt.client.widgets.events.ClickEvent; 9 import com.smartgwt.client.widgets.events.ClickEvent;
9 import com.smartgwt.client.widgets.events.ClickHandler; 10 import com.smartgwt.client.widgets.events.ClickHandler;
10 import com.smartgwt.client.widgets.layout.HLayout; 11 import com.smartgwt.client.widgets.layout.HLayout;
25 /** 26 /**
26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
27 */ 28 */
28 public class MapToolbar extends HLayout { 29 public class MapToolbar extends HLayout {
29 30
30 public static final String MARK_TO_DELETE = "mark.delete";
31
32 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); 31 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
33 32
34 protected FloodMap floodMap; 33 protected FloodMap floodMap;
35 protected DragPan pan; 34 protected DragPan pan;
36 protected ZoomBox zoomBox; 35 protected ZoomBox zoomBox;
40 protected ImgButton zoomBoxButton; 39 protected ImgButton zoomBoxButton;
41 protected ImgButton zoomOutButton; 40 protected ImgButton zoomOutButton;
42 protected ImgButton panButton; 41 protected ImgButton panButton;
43 protected ImgButton selectButton; 42 protected ImgButton selectButton;
44 protected ImgButton removeButton; 43 protected ImgButton removeButton;
44 protected ImgButton elevationButton;
45 45
46 protected DrawControl drawControl; 46 protected DrawControl drawControl;
47 protected MeasureControl measureControl; 47 protected MeasureControl measureControl;
48 48
49 protected Canvas position; 49 protected Canvas position;
75 drawControl = createDrawControl(); 75 drawControl = createDrawControl();
76 selectButton = createSelectFeatureControl(); 76 selectButton = createSelectFeatureControl();
77 measureControl = createMeasureControl(); 77 measureControl = createMeasureControl();
78 position = createMousePosition(wrapper); 78 position = createMousePosition(wrapper);
79 removeButton = createRemoveFeatureControl(); 79 removeButton = createRemoveFeatureControl();
80 elevationButton = createElevationControl();
80 81
81 addMember(zoomToMaxButton); 82 addMember(zoomToMaxButton);
82 addMember(zoomBoxButton); 83 addMember(zoomBoxButton);
83 addMember(zoomOutButton); 84 addMember(zoomOutButton);
84 addMember(panButton); 85 addMember(panButton);
85 86
86 if (digitize) { 87 if (digitize) {
87 addMember(drawControl); 88 addMember(drawControl);
88 addMember(selectButton); 89 addMember(selectButton);
89 addMember(removeButton); 90 addMember(removeButton);
91 addMember(elevationButton);
90 } 92 }
91 93
92 addMember(measureControl); 94 addMember(measureControl);
93 addMember(spacer); 95 addMember(spacer);
94 addMember(position); 96 addMember(position);
308 // this doesn't work here. After a feature has been selected, the layer 310 // this doesn't work here. After a feature has been selected, the layer
309 // still has no selected features. 311 // still has no selected features.
310 opts.onSelect(new SelectFeature.SelectFeatureListener() { 312 opts.onSelect(new SelectFeature.SelectFeatureListener() {
311 public void onFeatureSelected(VectorFeature feature) { 313 public void onFeatureSelected(VectorFeature feature) {
312 Attributes attr = feature.getAttributes(); 314 Attributes attr = feature.getAttributes();
313 attr.setAttribute(MARK_TO_DELETE, 1); 315 attr.setAttribute(FloodMap.MARK_SELECTED, 1);
314 } 316 }
315 }); 317 });
316 318
317 opts.onUnSelect(new SelectFeature.UnselectFeatureListener() { 319 opts.onUnSelect(new SelectFeature.UnselectFeatureListener() {
318 public void onFeatureUnselected(VectorFeature feature) { 320 public void onFeatureUnselected(VectorFeature feature) {
319 Attributes attr = feature.getAttributes(); 321 Attributes attr = feature.getAttributes();
320 attr.setAttribute(MARK_TO_DELETE, 0); 322 attr.setAttribute(FloodMap.MARK_SELECTED, 0);
321 } 323 }
322 }); 324 });
323 325
324 selectFeature = new SelectFeature(floodMap.getBarrierLayer(), opts); 326 selectFeature = new SelectFeature(floodMap.getBarrierLayer(), opts);
325 getMap().addControl(selectFeature); 327 getMap().addControl(selectFeature);
357 359
358 for (int i = features.length-1; i >= 0; i--) { 360 for (int i = features.length-1; i >= 0; i--) {
359 VectorFeature feature = features[i]; 361 VectorFeature feature = features[i];
360 362
361 Attributes attr = feature.getAttributes(); 363 Attributes attr = feature.getAttributes();
362 int del = attr.getAttributeAsInt(MARK_TO_DELETE); 364 int del = attr.getAttributeAsInt(FloodMap.MARK_SELECTED);
363 365
364 if (del == 1) { 366 if (del == 1) {
365 barriers.removeFeature(feature); 367 barriers.removeFeature(feature);
366 feature.destroy(); 368 feature.destroy();
367 } 369 }
370 }); 372 });
371 373
372 remove.setTooltip(MSG.removeObject()); 374 remove.setTooltip(MSG.removeObject());
373 375
374 return remove; 376 return remove;
377 }
378
379
380 protected ImgButton createElevationControl() {
381 ImgButton btn = createButton(MSG.adjustElevation(), new ClickHandler() {
382 public void onClick(ClickEvent evt) {
383 Vector barriers = floodMap.getBarrierLayer();
384 VectorFeature[] features = barriers.getFeatures();
385
386 VectorFeature feature = null;
387
388 if (features == null || features.length == 0) {
389 SC.warn("No Feature selected!");
390 return;
391 }
392
393 for (VectorFeature f: features) {
394 Attributes attr = f.getAttributes();
395 if (attr.getAttributeAsInt(FloodMap.MARK_SELECTED) == 1) {
396 if (feature == null) {
397 feature = f;
398 }
399 else {
400 SC.warn("More than 1 Feature selected!");
401 }
402 }
403 }
404
405 new ElevationWindow(floodMap, feature).show();
406 }
407 });
408
409 btn.setTooltip(MSG.adjustElevationTooltip());
410
411 return btn;
375 } 412 }
376 413
377 414
378 protected Canvas createMousePosition(Canvas mapWrapper) { 415 protected Canvas createMousePosition(Canvas mapWrapper) {
379 return new MapPositionPanel(floodMap.getMapWidget(), mapWrapper); 416 return new MapPositionPanel(floodMap.getMapWidget(), mapWrapper);

http://dive4elements.wald.intevation.org