Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java @ 800:95cc560ce7c4
Added map controls for digitizing and removing barriers.
flys-client/trunk@2321 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 12 Jul 2011 13:43:49 +0000 |
parents | f4299b90c996 |
children | d45ad7fd3027 |
comparison
equal
deleted
inserted
replaced
799:f4299b90c996 | 800:95cc560ce7c4 |
---|---|
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.widgets.Canvas; | |
6 import com.smartgwt.client.widgets.ImgButton; | 7 import com.smartgwt.client.widgets.ImgButton; |
7 import com.smartgwt.client.widgets.events.ClickEvent; | 8 import com.smartgwt.client.widgets.events.ClickEvent; |
8 import com.smartgwt.client.widgets.events.ClickHandler; | 9 import com.smartgwt.client.widgets.events.ClickHandler; |
9 import com.smartgwt.client.widgets.layout.HLayout; | 10 import com.smartgwt.client.widgets.layout.HLayout; |
10 | 11 |
11 import org.gwtopenmaps.openlayers.client.Map; | 12 import org.gwtopenmaps.openlayers.client.Map; |
12 import org.gwtopenmaps.openlayers.client.control.DragPan; | 13 import org.gwtopenmaps.openlayers.client.control.DragPan; |
14 import org.gwtopenmaps.openlayers.client.control.SelectFeature; | |
15 import org.gwtopenmaps.openlayers.client.control.SelectFeatureOptions; | |
13 import org.gwtopenmaps.openlayers.client.control.ZoomBox; | 16 import org.gwtopenmaps.openlayers.client.control.ZoomBox; |
17 import org.gwtopenmaps.openlayers.client.feature.VectorFeature; | |
18 import org.gwtopenmaps.openlayers.client.layer.Vector; | |
19 import org.gwtopenmaps.openlayers.client.util.Attributes; | |
14 | 20 |
15 import de.intevation.flys.client.client.FLYSConstants; | 21 import de.intevation.flys.client.client.FLYSConstants; |
22 import de.intevation.flys.client.client.utils.EnableDisableCmd; | |
16 | 23 |
17 | 24 |
18 /** | 25 /** |
19 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
20 */ | 27 */ |
21 public class MapToolbar extends HLayout { | 28 public class MapToolbar extends HLayout { |
22 | 29 |
23 /** The message class that provides i18n strings.*/ | 30 public static final String MARK_TO_DELETE = "mark.delete"; |
31 | |
24 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | 32 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); |
25 | 33 |
26 protected FloodMap floodMap; | 34 protected FloodMap floodMap; |
27 protected DragPan pan; | 35 protected DragPan pan; |
28 protected ZoomBox zoomBox; | 36 protected ZoomBox zoomBox; |
37 protected SelectFeature selectFeature; | |
29 | 38 |
30 protected ImgButton zoomToMaxButton; | 39 protected ImgButton zoomToMaxButton; |
31 protected ImgButton zoomBoxButton; | 40 protected ImgButton zoomBoxButton; |
32 protected ImgButton zoomOutButton; | 41 protected ImgButton zoomOutButton; |
33 protected ImgButton panButton; | 42 protected ImgButton panButton; |
34 | 43 protected ImgButton selectButton; |
35 | 44 protected ImgButton removeButton; |
36 public MapToolbar(FloodMap floodMap) { | 45 |
46 protected DrawControl drawControl; | |
47 | |
48 protected Canvas position; | |
49 | |
50 | |
51 public MapToolbar(FloodMap floodMap, Canvas wrapper) { | |
37 super(); | 52 super(); |
38 | 53 |
39 setWidth100(); | 54 setWidth100(); |
40 setHeight(30); | 55 setHeight(30); |
41 setMembersMargin(10); | 56 setMembersMargin(10); |
42 setPadding(5); | 57 setPadding(5); |
43 setBorder("1px solid black"); | 58 setBorder("1px solid black"); |
44 | 59 |
45 this.floodMap = floodMap; | 60 this.floodMap = floodMap; |
46 | 61 |
62 Canvas spacer = new Canvas(); | |
63 spacer.setWidth("*"); | |
64 | |
47 zoomToMaxButton = createMaxExtentControl(); | 65 zoomToMaxButton = createMaxExtentControl(); |
48 zoomBoxButton = createZoomBoxControl(); | 66 zoomBoxButton = createZoomBoxControl(); |
49 zoomOutButton = createZoomOutControl(); | 67 zoomOutButton = createZoomOutControl(); |
50 panButton = createPanControl(); | 68 panButton = createPanControl(); |
69 position = createMousePosition(wrapper); | |
70 drawControl = createDrawControl(); | |
71 selectButton = createSelectFeatureControl(); | |
72 removeButton = createRemoveFeatureControl(); | |
51 | 73 |
52 addMember(zoomToMaxButton); | 74 addMember(zoomToMaxButton); |
53 addMember(zoomBoxButton); | 75 addMember(zoomBoxButton); |
54 addMember(zoomOutButton); | 76 addMember(zoomOutButton); |
55 addMember(panButton); | 77 addMember(panButton); |
78 addMember(drawControl); | |
79 addMember(selectButton); | |
80 addMember(removeButton); | |
81 addMember(spacer); | |
82 addMember(position); | |
56 } | 83 } |
57 | 84 |
58 | 85 |
59 protected Map getMap() { | 86 protected Map getMap() { |
60 return floodMap.getMap(); | 87 return floodMap.getMap(); |
83 zoomBox.deactivate(); | 110 zoomBox.deactivate(); |
84 } | 111 } |
85 } | 112 } |
86 | 113 |
87 | 114 |
115 protected void activateDrawFeature(boolean activate) { | |
116 drawControl.activate(activate); | |
117 } | |
118 | |
119 | |
120 protected void activateSelectFeature(boolean activate) { | |
121 if (activate) { | |
122 selectButton.select(); | |
123 selectFeature.activate(); | |
124 } | |
125 else { | |
126 selectButton.deselect(); | |
127 selectFeature.deactivate(); | |
128 } | |
129 } | |
130 | |
131 | |
132 protected ImgButton createButton(String img, ClickHandler handler) { | |
133 ImgButton btn = new ImgButton(); | |
134 | |
135 String baseUrl = GWT.getHostPageBaseURL(); | |
136 btn.setSrc(baseUrl + img); | |
137 btn.setWidth(20); | |
138 btn.setHeight(20); | |
139 btn.setShowDown(false); | |
140 btn.setShowRollOver(false); | |
141 btn.setShowDisabled(false); | |
142 btn.setShowDisabledIcon(true); | |
143 btn.setShowDownIcon(false); | |
144 btn.setShowFocusedIcon(false); | |
145 | |
146 if (handler != null) { | |
147 btn.addClickHandler(handler); | |
148 } | |
149 | |
150 return btn; | |
151 } | |
152 | |
153 | |
154 protected ImgButton createToggleButton( | |
155 String img, | |
156 final EnableDisableCmd cmd | |
157 ) { | |
158 final ImgButton btn = new ImgButton(); | |
159 | |
160 String baseUrl = GWT.getHostPageBaseURL(); | |
161 btn.setSrc(baseUrl + img); | |
162 btn.setActionType(SelectionType.CHECKBOX); | |
163 btn.setSize(20); | |
164 btn.setShowRollOver(false); | |
165 btn.setSelected(false); | |
166 btn.addClickHandler(new ClickHandler() { | |
167 public void onClick(ClickEvent e) { | |
168 if (btn.isSelected()) { | |
169 cmd.enable(); | |
170 } | |
171 else { | |
172 cmd.disable(); | |
173 } | |
174 } | |
175 }); | |
176 | |
177 return btn; | |
178 } | |
179 | |
180 | |
88 protected ImgButton createMaxExtentControl() { | 181 protected ImgButton createMaxExtentControl() { |
89 ImgButton zoomToMax = new ImgButton(); | 182 ImgButton zoomToMax = createButton(MSG.zoom_all(), new ClickHandler() { |
90 | |
91 String baseUrl = GWT.getHostPageBaseURL(); | |
92 zoomToMax.setSrc(baseUrl + MSG.zoom_all()); | |
93 zoomToMax.setWidth(20); | |
94 zoomToMax.setHeight(20); | |
95 zoomToMax.setShowDown(false); | |
96 zoomToMax.setShowRollOver(false); | |
97 zoomToMax.setShowDisabled(false); | |
98 zoomToMax.setShowDisabledIcon(true); | |
99 zoomToMax.setShowDownIcon(false); | |
100 zoomToMax.setShowFocusedIcon(false); | |
101 | |
102 zoomToMax.addClickHandler(new ClickHandler() { | |
103 public void onClick(ClickEvent event) { | 183 public void onClick(ClickEvent event) { |
104 floodMap.getMap().zoomToMaxExtent(); | 184 floodMap.getMap().zoomToMaxExtent(); |
105 } | 185 } |
106 }); | 186 }); |
107 | 187 |
110 | 190 |
111 | 191 |
112 protected ImgButton createZoomBoxControl() { | 192 protected ImgButton createZoomBoxControl() { |
113 zoomBox = new ZoomBox(); | 193 zoomBox = new ZoomBox(); |
114 | 194 |
115 final ImgButton button = new ImgButton(); | 195 EnableDisableCmd cmd = new EnableDisableCmd() { |
116 | 196 public void enable() { |
117 String baseUrl = GWT.getHostPageBaseURL(); | 197 activateZoomBox(true); |
118 button.setSrc(baseUrl + MSG.zoom_in()); | 198 activatePan(false); |
119 button.setActionType(SelectionType.CHECKBOX); | 199 activateDrawFeature(false); |
120 button.setSize(20); | 200 activateSelectFeature(false); |
121 button.setShowRollOver(false); | 201 } |
122 button.setSelected(false); | 202 |
123 | 203 public void disable() { |
124 button.addClickHandler(new ClickHandler() { | 204 activateZoomBox(false); |
125 public void onClick(ClickEvent e) { | 205 } |
126 if (button.isSelected()) { | 206 }; |
127 activatePan(false); | 207 |
128 activateZoomBox(true); | 208 ImgButton button = createToggleButton(MSG.zoom_in(), cmd); |
129 } | 209 Map map = getMap(); |
130 else { | |
131 activateZoomBox(false); | |
132 } | |
133 } | |
134 }); | |
135 | |
136 Map map = getMap(); | |
137 map.addControl(zoomBox); | 210 map.addControl(zoomBox); |
138 | 211 |
139 return button; | 212 return button; |
140 } | 213 } |
141 | 214 |
142 | 215 |
143 protected ImgButton createZoomOutControl() { | 216 protected ImgButton createZoomOutControl() { |
144 ImgButton zoomOut = new ImgButton(); | 217 ImgButton zoomOut = createButton(MSG.zoom_out(), new ClickHandler() { |
145 | |
146 String baseUrl = GWT.getHostPageBaseURL(); | |
147 zoomOut.setSrc(baseUrl + MSG.zoom_out()); | |
148 zoomOut.setWidth(20); | |
149 zoomOut.setHeight(20); | |
150 zoomOut.setShowDown(false); | |
151 zoomOut.setShowRollOver(false); | |
152 zoomOut.setShowDisabled(false); | |
153 zoomOut.setShowDisabledIcon(true); | |
154 zoomOut.setShowDownIcon(false); | |
155 zoomOut.setShowFocusedIcon(false); | |
156 | |
157 zoomOut.addClickHandler(new ClickHandler() { | |
158 public void onClick(ClickEvent event) { | 218 public void onClick(ClickEvent event) { |
159 Map map = floodMap.getMap(); | 219 Map map = floodMap.getMap(); |
160 int level = map.getZoom(); | 220 int level = map.getZoom(); |
161 | 221 |
162 if (level > 1) { | 222 if (level > 1) { |
169 } | 229 } |
170 | 230 |
171 | 231 |
172 protected ImgButton createPanControl() { | 232 protected ImgButton createPanControl() { |
173 pan = new DragPan(); | 233 pan = new DragPan(); |
174 | 234 getMap().addControl(pan); |
175 final ImgButton button = new ImgButton(); | 235 |
176 | 236 EnableDisableCmd cmd = new EnableDisableCmd() { |
177 String baseUrl = GWT.getHostPageBaseURL(); | 237 public void enable() { |
178 button.setSrc(baseUrl + MSG.pan()); | 238 activateZoomBox(false); |
179 button.setActionType(SelectionType.CHECKBOX); | 239 activatePan(true); |
180 button.setSize(20); | 240 activateDrawFeature(false); |
181 button.setShowRollOver(false); | 241 activateSelectFeature(false); |
182 button.setSelected(false); | 242 } |
183 | 243 |
184 button.addClickHandler(new ClickHandler() { | 244 public void disable() { |
185 public void onClick(ClickEvent e) { | 245 activatePan(false); |
186 if (button.isSelected()) { | 246 } |
187 activateZoomBox(false); | 247 }; |
188 activatePan(true); | 248 |
189 } | 249 final ImgButton button = createToggleButton(MSG.pan(), cmd); |
190 else { | |
191 activatePan(false); | |
192 } | |
193 } | |
194 }); | |
195 | |
196 Map map = getMap(); | |
197 map.addControl(pan); | |
198 | 250 |
199 return button; | 251 return button; |
252 } | |
253 | |
254 | |
255 protected DrawControl createDrawControl() { | |
256 EnableDisableCmd cmd = new EnableDisableCmd() { | |
257 public void enable() { | |
258 activateZoomBox(false); | |
259 activatePan(false); | |
260 activateDrawFeature(true); | |
261 activateSelectFeature(false); | |
262 } | |
263 | |
264 public void disable() { | |
265 activateDrawFeature(false); | |
266 } | |
267 }; | |
268 return new DrawControl(getMap(), floodMap.getBarrierLayer(), cmd); | |
269 } | |
270 | |
271 | |
272 protected ImgButton createSelectFeatureControl() { | |
273 SelectFeatureOptions opts = new SelectFeatureOptions(); | |
274 | |
275 // VectorFeatures selected by the SelectFeature control are manually | |
276 // marked with the string "mark.delete". The control to remove selected | |
277 // features makes use of this string to determine if the feature should | |
278 // be deleted (is marked) or not. Actually, we would like to use the | |
279 // OpenLayers native mechanism to select features, but for some reason | |
280 // this doesn't work here. After a feature has been selected, the layer | |
281 // still has no selected features. | |
282 opts.onSelect(new SelectFeature.SelectFeatureListener() { | |
283 public void onFeatureSelected(VectorFeature feature) { | |
284 Attributes attr = feature.getAttributes(); | |
285 attr.setAttribute(MARK_TO_DELETE, 1); | |
286 } | |
287 }); | |
288 | |
289 opts.onUnSelect(new SelectFeature.UnselectFeatureListener() { | |
290 public void onFeatureUnselected(VectorFeature feature) { | |
291 Attributes attr = feature.getAttributes(); | |
292 attr.setAttribute(MARK_TO_DELETE, 0); | |
293 } | |
294 }); | |
295 | |
296 selectFeature = new SelectFeature(floodMap.getBarrierLayer(), opts); | |
297 getMap().addControl(selectFeature); | |
298 | |
299 EnableDisableCmd cmd = new EnableDisableCmd() { | |
300 public void enable() { | |
301 activateDrawFeature(false); | |
302 activatePan(false); | |
303 activateZoomBox(false); | |
304 activateSelectFeature(true); | |
305 } | |
306 | |
307 public void disable() { | |
308 activateSelectFeature(false); | |
309 } | |
310 }; | |
311 | |
312 ImgButton button = createToggleButton(MSG.selectFeature(), cmd); | |
313 | |
314 return button; | |
315 } | |
316 | |
317 | |
318 protected ImgButton createRemoveFeatureControl() { | |
319 ImgButton remove = createButton(MSG.removeFeature(),new ClickHandler() { | |
320 public void onClick(ClickEvent event) { | |
321 Vector barriers = floodMap.getBarrierLayer(); | |
322 VectorFeature[] features = barriers.getFeatures(); | |
323 | |
324 if (features == null || features.length == 0) { | |
325 return; | |
326 } | |
327 | |
328 for (int i = features.length-1; i >= 0; i--) { | |
329 VectorFeature feature = features[i]; | |
330 | |
331 Attributes attr = feature.getAttributes(); | |
332 int del = attr.getAttributeAsInt(MARK_TO_DELETE); | |
333 | |
334 if (del == 1) { | |
335 barriers.removeFeature(feature); | |
336 feature.destroy(); | |
337 } | |
338 } | |
339 } | |
340 }); | |
341 | |
342 return remove; | |
343 } | |
344 | |
345 | |
346 protected Canvas createMousePosition(Canvas mapWrapper) { | |
347 return new MapPositionPanel(floodMap.getMapWidget(), mapWrapper); | |
200 } | 348 } |
201 } | 349 } |
202 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 350 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |