Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapToolbar.java @ 799:f4299b90c996
Added controls to navigate in the map.
flys-client/trunk@2318 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 11 Jul 2011 13:29:57 +0000 |
parents | |
children | 95cc560ce7c4 |
comparison
equal
deleted
inserted
replaced
798:7061c2e66039 | 799:f4299b90c996 |
---|---|
1 package de.intevation.flys.client.client.ui.map; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 | |
5 import com.smartgwt.client.types.SelectionType; | |
6 import com.smartgwt.client.widgets.ImgButton; | |
7 import com.smartgwt.client.widgets.events.ClickEvent; | |
8 import com.smartgwt.client.widgets.events.ClickHandler; | |
9 import com.smartgwt.client.widgets.layout.HLayout; | |
10 | |
11 import org.gwtopenmaps.openlayers.client.Map; | |
12 import org.gwtopenmaps.openlayers.client.control.DragPan; | |
13 import org.gwtopenmaps.openlayers.client.control.ZoomBox; | |
14 | |
15 import de.intevation.flys.client.client.FLYSConstants; | |
16 | |
17 | |
18 /** | |
19 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
20 */ | |
21 public class MapToolbar extends HLayout { | |
22 | |
23 /** The message class that provides i18n strings.*/ | |
24 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
25 | |
26 protected FloodMap floodMap; | |
27 protected DragPan pan; | |
28 protected ZoomBox zoomBox; | |
29 | |
30 protected ImgButton zoomToMaxButton; | |
31 protected ImgButton zoomBoxButton; | |
32 protected ImgButton zoomOutButton; | |
33 protected ImgButton panButton; | |
34 | |
35 | |
36 public MapToolbar(FloodMap floodMap) { | |
37 super(); | |
38 | |
39 setWidth100(); | |
40 setHeight(30); | |
41 setMembersMargin(10); | |
42 setPadding(5); | |
43 setBorder("1px solid black"); | |
44 | |
45 this.floodMap = floodMap; | |
46 | |
47 zoomToMaxButton = createMaxExtentControl(); | |
48 zoomBoxButton = createZoomBoxControl(); | |
49 zoomOutButton = createZoomOutControl(); | |
50 panButton = createPanControl(); | |
51 | |
52 addMember(zoomToMaxButton); | |
53 addMember(zoomBoxButton); | |
54 addMember(zoomOutButton); | |
55 addMember(panButton); | |
56 } | |
57 | |
58 | |
59 protected Map getMap() { | |
60 return floodMap.getMap(); | |
61 } | |
62 | |
63 | |
64 protected void activatePan(boolean activate) { | |
65 if (activate) { | |
66 panButton.select(); | |
67 pan.activate(); | |
68 } | |
69 else { | |
70 panButton.deselect(); | |
71 pan.deactivate(); | |
72 } | |
73 } | |
74 | |
75 | |
76 protected void activateZoomBox(boolean activate) { | |
77 if (activate) { | |
78 zoomBoxButton.select(); | |
79 zoomBox.activate(); | |
80 } | |
81 else { | |
82 zoomBoxButton.deselect(); | |
83 zoomBox.deactivate(); | |
84 } | |
85 } | |
86 | |
87 | |
88 protected ImgButton createMaxExtentControl() { | |
89 ImgButton zoomToMax = new ImgButton(); | |
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) { | |
104 floodMap.getMap().zoomToMaxExtent(); | |
105 } | |
106 }); | |
107 | |
108 return zoomToMax; | |
109 } | |
110 | |
111 | |
112 protected ImgButton createZoomBoxControl() { | |
113 zoomBox = new ZoomBox(); | |
114 | |
115 final ImgButton button = new ImgButton(); | |
116 | |
117 String baseUrl = GWT.getHostPageBaseURL(); | |
118 button.setSrc(baseUrl + MSG.zoom_in()); | |
119 button.setActionType(SelectionType.CHECKBOX); | |
120 button.setSize(20); | |
121 button.setShowRollOver(false); | |
122 button.setSelected(false); | |
123 | |
124 button.addClickHandler(new ClickHandler() { | |
125 public void onClick(ClickEvent e) { | |
126 if (button.isSelected()) { | |
127 activatePan(false); | |
128 activateZoomBox(true); | |
129 } | |
130 else { | |
131 activateZoomBox(false); | |
132 } | |
133 } | |
134 }); | |
135 | |
136 Map map = getMap(); | |
137 map.addControl(zoomBox); | |
138 | |
139 return button; | |
140 } | |
141 | |
142 | |
143 protected ImgButton createZoomOutControl() { | |
144 ImgButton zoomOut = new ImgButton(); | |
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) { | |
159 Map map = floodMap.getMap(); | |
160 int level = map.getZoom(); | |
161 | |
162 if (level > 1) { | |
163 map.zoomTo(level-1); | |
164 } | |
165 } | |
166 }); | |
167 | |
168 return zoomOut; | |
169 } | |
170 | |
171 | |
172 protected ImgButton createPanControl() { | |
173 pan = new DragPan(); | |
174 | |
175 final ImgButton button = new ImgButton(); | |
176 | |
177 String baseUrl = GWT.getHostPageBaseURL(); | |
178 button.setSrc(baseUrl + MSG.pan()); | |
179 button.setActionType(SelectionType.CHECKBOX); | |
180 button.setSize(20); | |
181 button.setShowRollOver(false); | |
182 button.setSelected(false); | |
183 | |
184 button.addClickHandler(new ClickHandler() { | |
185 public void onClick(ClickEvent e) { | |
186 if (button.isSelected()) { | |
187 activateZoomBox(false); | |
188 activatePan(true); | |
189 } | |
190 else { | |
191 activatePan(false); | |
192 } | |
193 } | |
194 }); | |
195 | |
196 Map map = getMap(); | |
197 map.addControl(pan); | |
198 | |
199 return button; | |
200 } | |
201 } | |
202 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |