Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/DigitizePanel.java @ 833:dcecdd9693a8
Added a UIProvider that displays a combobox on the left and a map widget in the helper container.
flys-client/trunk@2544 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 24 Aug 2011 08:36:51 +0000 |
parents | |
children | a7179e3a774e |
comparison
equal
deleted
inserted
replaced
832:303a923d232b | 833:dcecdd9693a8 |
---|---|
1 package de.intevation.flys.client.client.ui; | |
2 | |
3 import java.util.List; | |
4 | |
5 import com.google.gwt.core.client.GWT; | |
6 import com.google.gwt.user.client.rpc.AsyncCallback; | |
7 | |
8 import com.smartgwt.client.util.SC; | |
9 import com.smartgwt.client.widgets.Canvas; | |
10 import com.smartgwt.client.widgets.events.ResizedEvent; | |
11 import com.smartgwt.client.widgets.events.ResizedHandler; | |
12 | |
13 import org.gwtopenmaps.openlayers.client.Map; | |
14 import org.gwtopenmaps.openlayers.client.feature.VectorFeature; | |
15 import org.gwtopenmaps.openlayers.client.format.GeoJSON; | |
16 import org.gwtopenmaps.openlayers.client.layer.WMS; | |
17 import org.gwtopenmaps.openlayers.client.layer.WMSParams; | |
18 import org.gwtopenmaps.openlayers.client.layer.WMSOptions; | |
19 | |
20 import de.intevation.flys.client.shared.model.Data; | |
21 import de.intevation.flys.client.shared.model.DataItem; | |
22 import de.intevation.flys.client.shared.model.DataList; | |
23 import de.intevation.flys.client.shared.model.DefaultData; | |
24 import de.intevation.flys.client.shared.model.DefaultDataItem; | |
25 import de.intevation.flys.client.shared.model.MapInfo; | |
26 | |
27 import de.intevation.flys.client.client.Config; | |
28 import de.intevation.flys.client.client.ui.map.FloodMap; | |
29 import de.intevation.flys.client.client.ui.map.MapPanel; | |
30 import de.intevation.flys.client.client.services.MapInfoService; | |
31 import de.intevation.flys.client.client.services.MapInfoServiceAsync; | |
32 | |
33 | |
34 public class DigitizePanel extends SelectProvider { | |
35 | |
36 protected MapInfoServiceAsync mapInfo = GWT.create(MapInfoService.class); | |
37 | |
38 protected FloodMap floodMap; | |
39 | |
40 | |
41 public static final String UESK_BARRIERS = "uesk.barriers"; | |
42 | |
43 | |
44 public DigitizePanel() { | |
45 } | |
46 | |
47 | |
48 @Override | |
49 public Canvas create(DataList list) { | |
50 List<Data> data = list.getAll(); | |
51 | |
52 Data barriers = null; | |
53 for (int i = data.size()-1; i >= 0; i--) { | |
54 Data d = data.get(i); | |
55 if (d.getLabel().equals(UESK_BARRIERS)) { | |
56 barriers = d; | |
57 data.remove(d); | |
58 } | |
59 } | |
60 | |
61 Canvas selectBox = super.create(list); | |
62 | |
63 final Config cfg = Config.getInstance(); | |
64 final String url = cfg.getServerUrl(); | |
65 final String locale = cfg.getLocale(); | |
66 | |
67 DataItem[] obj = barriers.getItems(); | |
68 | |
69 final String[] geojson = new String[1]; | |
70 for (DataItem item: obj) { | |
71 if (item.getLabel().equals(UESK_BARRIERS)) { | |
72 geojson[0] = item.getStringValue(); | |
73 break; | |
74 } | |
75 } | |
76 | |
77 // TODO FIND CORRECT RIVER | |
78 mapInfo.getMapInfo(url, locale, "Saar", new AsyncCallback<MapInfo>() { | |
79 public void onFailure(Throwable caught) { | |
80 String msg = caught.getMessage(); | |
81 | |
82 GWT.log("Error while fetching MapInfo: " + msg); | |
83 SC.warn(MSG.getString(msg)); | |
84 } | |
85 | |
86 public void onSuccess(MapInfo info) { | |
87 createMapWidget(info, geojson[0]); | |
88 } | |
89 }); | |
90 | |
91 return selectBox; | |
92 } | |
93 | |
94 | |
95 @Override | |
96 protected Data[] getData() { | |
97 Data[] data = super.getData(); | |
98 Data[] total = new Data[2]; | |
99 | |
100 DataItem item = new DefaultDataItem( | |
101 UESK_BARRIERS, UESK_BARRIERS, floodMap.getFeaturesAsGeoJSON()); | |
102 | |
103 total[0] = data[0]; | |
104 total[1] = new DefaultData( | |
105 UESK_BARRIERS, null, null, new DataItem[] { item }); | |
106 | |
107 return total; | |
108 } | |
109 | |
110 | |
111 public void createMapWidget(MapInfo mapInfo, String geojson) { | |
112 final MapPanel mapPanel = new MapPanel(mapInfo, true); | |
113 | |
114 floodMap = mapPanel.getFloodMap(); | |
115 Map map = floodMap.getMap(); | |
116 | |
117 helperContainer.addMember(mapPanel); | |
118 helperContainer.addResizedHandler(new ResizedHandler() { | |
119 public void onResized(ResizedEvent e) { | |
120 Integer height = helperContainer.getHeight(); | |
121 Integer width = helperContainer.getWidth(); | |
122 | |
123 height = height * 99 / 100; | |
124 width = width * 99 / 100; | |
125 | |
126 String w = String.valueOf(width) + "px"; | |
127 String h = String.valueOf(height) + "px"; | |
128 | |
129 mapPanel.getFloodMap().setSize(w, h); | |
130 } | |
131 }); | |
132 | |
133 WMS axis = getLayer( | |
134 mapInfo.getWmsUrl(), "riveraxis", | |
135 mapInfo.getProjection(), false); | |
136 WMS back = getLayer( | |
137 mapInfo.getBackgroundWmsUrl(), mapInfo.getBackgroundWmsLayers(), | |
138 mapInfo.getProjection(), false); | |
139 | |
140 map.addLayer(axis); | |
141 map.addLayer(back); | |
142 | |
143 if (geojson != null && geojson.length() > 0) { | |
144 VectorFeature[] features = new GeoJSON().read(geojson); | |
145 floodMap.getBarrierLayer().addFeatures(features); | |
146 } | |
147 | |
148 map.zoomToMaxExtent(); | |
149 } | |
150 | |
151 | |
152 protected WMS getLayer(String url, String layers, String proj, boolean x) { | |
153 WMSParams params = new WMSParams(); | |
154 params.setLayers(layers); | |
155 params.setFormat("image/png"); | |
156 params.setIsTransparent(!x); | |
157 | |
158 WMSOptions opts = new WMSOptions(); | |
159 opts.setProjection(proj); | |
160 opts.setSingleTile(true); | |
161 opts.setRatio(1); | |
162 | |
163 WMS wms = new WMS(layers, url, params, opts); | |
164 wms.setIsVisible(true); | |
165 wms.setIsBaseLayer(x); | |
166 | |
167 return wms; | |
168 } | |
169 } | |
170 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |