Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/client/ui/DigitizePanel.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/client/ui/DigitizePanel.java@4f935415bb20 |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.client.ui; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 import com.google.gwt.user.client.rpc.AsyncCallback; | |
5 import com.smartgwt.client.types.VerticalAlignment; | |
6 import com.smartgwt.client.util.SC; | |
7 import com.smartgwt.client.widgets.Canvas; | |
8 import com.smartgwt.client.widgets.Label; | |
9 import com.smartgwt.client.widgets.events.ParentMovedEvent; | |
10 import com.smartgwt.client.widgets.events.ParentMovedHandler; | |
11 import com.smartgwt.client.widgets.events.ResizedEvent; | |
12 import com.smartgwt.client.widgets.events.ResizedHandler; | |
13 import com.smartgwt.client.widgets.events.VisibilityChangedEvent; | |
14 import com.smartgwt.client.widgets.events.VisibilityChangedHandler; | |
15 import com.smartgwt.client.widgets.layout.VLayout; | |
16 import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; | |
17 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; | |
18 | |
19 import de.intevation.flys.client.client.Config; | |
20 import de.intevation.flys.client.client.FLYS; | |
21 import de.intevation.flys.client.client.FLYSConstants; | |
22 import de.intevation.flys.client.client.services.MapInfoService; | |
23 import de.intevation.flys.client.client.services.MapInfoServiceAsync; | |
24 import de.intevation.flys.client.client.ui.map.FloodMap; | |
25 import de.intevation.flys.client.client.ui.map.MapPanel; | |
26 import de.intevation.flys.client.shared.model.Data; | |
27 import de.intevation.flys.client.shared.model.DataItem; | |
28 import de.intevation.flys.client.shared.model.DataList; | |
29 import de.intevation.flys.client.shared.model.DefaultData; | |
30 import de.intevation.flys.client.shared.model.DefaultDataItem; | |
31 import de.intevation.flys.client.shared.model.MapInfo; | |
32 | |
33 import java.util.List; | |
34 | |
35 import org.gwtopenmaps.openlayers.client.Map; | |
36 import org.gwtopenmaps.openlayers.client.control.Attribution; | |
37 import org.gwtopenmaps.openlayers.client.layer.TransitionEffect; | |
38 import org.gwtopenmaps.openlayers.client.layer.WMS; | |
39 import org.gwtopenmaps.openlayers.client.layer.WMSOptions; | |
40 import org.gwtopenmaps.openlayers.client.layer.WMSParams; | |
41 | |
42 | |
43 public class DigitizePanel | |
44 extends SelectProvider | |
45 implements TabSelectedHandler, VisibilityChangedHandler { | |
46 | |
47 private static final long serialVersionUID = 3529775660871273314L; | |
48 | |
49 protected MapInfoServiceAsync mapInfo = GWT.create(MapInfoService.class); | |
50 | |
51 protected FloodMap floodMap; | |
52 | |
53 protected MapPanel mapPanel; | |
54 | |
55 public static final String UESK_BARRIERS = "uesk.barriers"; | |
56 | |
57 /** The message class that provides i18n strings. */ | |
58 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
59 | |
60 public DigitizePanel() { | |
61 } | |
62 | |
63 | |
64 @Override | |
65 public Canvas create(DataList list) { | |
66 helperContainer.addVisibilityChangedHandler(this); | |
67 | |
68 DataList clone = (DataList) list.clone(); | |
69 List<Data> all = clone.getAll(); | |
70 all.remove(UESK_BARRIERS); | |
71 | |
72 Canvas widget = createWidget(list); | |
73 | |
74 final Config cfg = Config.getInstance(); | |
75 final String locale = cfg.getLocale(); | |
76 | |
77 String river = getDataValue("state.winfo.river", "river"); | |
78 mapInfo.getMapInfo(locale, river, new AsyncCallback<MapInfo>() { | |
79 @Override | |
80 public void onFailure(Throwable caught) { | |
81 String msg = caught.getMessage(); | |
82 | |
83 GWT.log("Error while fetching MapInfo: " + msg); | |
84 SC.warn(FLYS.getExceptionString(MSG, caught)); | |
85 } | |
86 | |
87 @Override | |
88 public void onSuccess(MapInfo info) { | |
89 createMapWidget(info); | |
90 } | |
91 }); | |
92 | |
93 return widget; | |
94 } | |
95 | |
96 | |
97 /** | |
98 * This method creates the content of the widget. | |
99 * | |
100 * @param data The {@link DataList} object. | |
101 * | |
102 * @return a combobox. | |
103 */ | |
104 @Override | |
105 protected Canvas createWidget(DataList data) { | |
106 GWT.log("DigitizePanel - createWidget()"); | |
107 | |
108 VLayout layout = new VLayout(); | |
109 layout.setAlign(VerticalAlignment.TOP); | |
110 layout.setHeight(25); | |
111 | |
112 int size = data.size(); | |
113 | |
114 for (int i = 0; i < size; i++) { | |
115 Data d = data.get(i); | |
116 | |
117 Label label = new Label(d.getDescription()); | |
118 label.setValign(VerticalAlignment.TOP); | |
119 label.setHeight(20); | |
120 label.setWidth(400); | |
121 | |
122 layout.addMember(label); | |
123 layout.addMember(getNextButton()); | |
124 } | |
125 | |
126 layout.setAlign(VerticalAlignment.TOP); | |
127 | |
128 return layout; | |
129 } | |
130 | |
131 | |
132 @Override | |
133 protected Data[] getData() { | |
134 final Data[] total = new Data[1]; | |
135 | |
136 if (floodMap != null) { | |
137 DataItem item = new DefaultDataItem( | |
138 UESK_BARRIERS, UESK_BARRIERS, floodMap.getFeaturesAsGeoJSON()); | |
139 total[0] = new DefaultData( | |
140 UESK_BARRIERS, null, null, new DataItem[] { item }); | |
141 } | |
142 else { | |
143 // Happens when OpenLayers is missing | |
144 GWT.log("floodMap is null -> OpenLayers missing?"); | |
145 } | |
146 | |
147 return total; | |
148 } | |
149 | |
150 | |
151 public void createMapWidget(MapInfo mapInfo) { | |
152 mapPanel = new MapPanel(mapInfo, true); | |
153 | |
154 floodMap = mapPanel.getFloodMap(); | |
155 Map map = floodMap.getMap(); | |
156 | |
157 helperContainer.addResizedHandler(new ResizedHandler() { | |
158 @Override | |
159 public void onResized(ResizedEvent event) { | |
160 mapPanel.doLayout(helperContainer.getWidth(), helperContainer.getHeight()); | |
161 } | |
162 }); | |
163 helperContainer.addParentMovedHandler(new ParentMovedHandler() { | |
164 @Override | |
165 public void onParentMoved(ParentMovedEvent event) { | |
166 mapPanel.getFloodMap().updateSize(); | |
167 } | |
168 }); | |
169 helperContainer.addVisibilityChangedHandler(new VisibilityChangedHandler() { | |
170 @Override | |
171 public void onVisibilityChanged(VisibilityChangedEvent event) { | |
172 mapPanel.doLayout(helperContainer.getWidth(), helperContainer.getHeight()); | |
173 } | |
174 }); | |
175 helperContainer.addMember(mapPanel); | |
176 | |
177 parameterList.registerCollectionViewTabHandler(this); | |
178 | |
179 WMS axis = getLayer( | |
180 mapInfo.getWmsUrl(), mapInfo.getWmsLayers(), | |
181 mapInfo.getProjection(), false, true); | |
182 WMS back = getLayer( | |
183 mapInfo.getBackgroundWmsUrl(), mapInfo.getBackgroundWmsLayers(), | |
184 mapInfo.getProjection(), false, false); | |
185 | |
186 map.addLayer(back); | |
187 map.addLayer(axis); | |
188 | |
189 String hws = getDataValue("state.winfo.uesk.dc-hws", "uesk.hws"); | |
190 if (hws != null && hws.length() > 0) { | |
191 WMS hwsLayer = getLayer( | |
192 //TODO: Use Mapinfo to get hws layer infos. | |
193 mapInfo.getWmsUrl().replace("river", "user"), | |
194 "ms_layer-hws-lines" + artifact.getUuid(), | |
195 mapInfo.getProjection(), | |
196 false, true); | |
197 map.addLayer(hwsLayer); | |
198 } | |
199 String userRgd = getDataValue("state.winfo.uesk.user-rgd", "uesk.user-rgd"); | |
200 if (userRgd != null && userRgd.length() > 0) { | |
201 WMS userLayer = getLayer( | |
202 //TODO: Use Mapinfo to get hws layer infos. | |
203 mapInfo.getWmsUrl().replace("river", "user"), | |
204 "ms_layer-user-rgd" + artifact.getUuid(), | |
205 mapInfo.getProjection(), | |
206 false, true); | |
207 map.addLayer(userLayer); | |
208 } | |
209 map.addControl(new Attribution()); | |
210 map.zoomToMaxExtent(); | |
211 | |
212 mapPanel.doLayout(helperContainer.getWidth(), helperContainer.getHeight()); | |
213 } | |
214 | |
215 | |
216 protected WMS getLayer(String url, String layers, String proj, boolean isBaseLayer, boolean singleTiled) { | |
217 final WMSParams params = new WMSParams(); | |
218 params.setLayers(layers); | |
219 params.setFormat("image/png"); | |
220 params.setIsTransparent(!isBaseLayer); | |
221 | |
222 final WMSOptions opts = new WMSOptions(); | |
223 opts.setProjection(proj); | |
224 opts.setSingleTile(false); // FIXME: Make working... | |
225 opts.setTransitionEffect(TransitionEffect.RESIZE); | |
226 opts.setRatio(1); | |
227 opts.setBuffer(0); | |
228 if (layers.equals("OSM-WMS-Dienst")) { | |
229 opts.setAttribution(MSG.attribution()); | |
230 } | |
231 final WMS wms = new WMS(layers, url, params, opts); | |
232 wms.setIsVisible(true); | |
233 wms.setIsBaseLayer(isBaseLayer); | |
234 | |
235 return wms; | |
236 } | |
237 | |
238 | |
239 @Override | |
240 public void onTabSelected(TabSelectedEvent tse) { | |
241 if (tse.getTabNum () != 0) { | |
242 floodMap.hideBarrierLayer(); | |
243 } | |
244 else { | |
245 floodMap.showBarrierLayer(); | |
246 } | |
247 } | |
248 | |
249 @Override | |
250 public void onVisibilityChanged(VisibilityChangedEvent vce) { | |
251 if (!vce.getIsVisible()) { | |
252 floodMap.hideBarrierLayer(); | |
253 mapPanel.getMapToolbar().activateDrawFeature(false); | |
254 } | |
255 else { | |
256 floodMap.showBarrierLayer(); | |
257 } | |
258 } | |
259 } | |
260 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |