Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java @ 806:e50da1f74e58
The layers created in the floodmap reflect to the facets this output mode has.
flys-client/trunk@2374 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 20 Jul 2011 13:31:20 +0000 |
parents | 95cc560ce7c4 |
children | 112f95d7b286 |
comparison
equal
deleted
inserted
replaced
805:f43d06d6a4a2 | 806:e50da1f74e58 |
---|---|
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.user.client.ui.HorizontalPanel; | 4 import com.google.gwt.user.client.ui.HorizontalPanel; |
4 import com.google.gwt.user.client.ui.Widget; | 5 import com.google.gwt.user.client.ui.Widget; |
5 | 6 |
6 import com.smartgwt.client.widgets.Canvas; | 7 import com.smartgwt.client.widgets.Canvas; |
7 import com.smartgwt.client.widgets.events.ResizedEvent; | 8 import com.smartgwt.client.widgets.events.ResizedEvent; |
9 import com.smartgwt.client.widgets.layout.HLayout; | 10 import com.smartgwt.client.widgets.layout.HLayout; |
10 import com.smartgwt.client.widgets.layout.VLayout; | 11 import com.smartgwt.client.widgets.layout.VLayout; |
11 | 12 |
12 import org.gwtopenmaps.openlayers.client.Bounds; | 13 import org.gwtopenmaps.openlayers.client.Bounds; |
13 import org.gwtopenmaps.openlayers.client.LonLat; | 14 import org.gwtopenmaps.openlayers.client.LonLat; |
15 import org.gwtopenmaps.openlayers.client.Map; | |
16 import org.gwtopenmaps.openlayers.client.layer.Layer; | |
14 import org.gwtopenmaps.openlayers.client.layer.WMS; | 17 import org.gwtopenmaps.openlayers.client.layer.WMS; |
15 import org.gwtopenmaps.openlayers.client.layer.WMSParams; | 18 import org.gwtopenmaps.openlayers.client.layer.WMSParams; |
16 | 19 |
17 | 20 import de.intevation.flys.client.shared.model.AttributedTheme; |
18 import de.intevation.flys.client.shared.model.Collection; | 21 import de.intevation.flys.client.shared.model.Collection; |
22 import de.intevation.flys.client.shared.model.Theme; | |
23 import de.intevation.flys.client.shared.model.ThemeList; | |
19 import de.intevation.flys.client.shared.model.OutputMode; | 24 import de.intevation.flys.client.shared.model.OutputMode; |
20 | 25 |
21 import de.intevation.flys.client.client.ui.CollectionView; | 26 import de.intevation.flys.client.client.ui.CollectionView; |
22 import de.intevation.flys.client.client.ui.OutputTab; | 27 import de.intevation.flys.client.client.ui.OutputTab; |
23 import de.intevation.flys.client.client.ui.chart.ChartThemePanel; | 28 import de.intevation.flys.client.client.ui.ThemePanel; |
24 | 29 |
25 | 30 |
26 public class MapOutputTab extends OutputTab { | 31 public class MapOutputTab extends OutputTab { |
27 | 32 |
28 protected CollectionView parent; | 33 protected CollectionView parent; |
29 | 34 |
30 protected Canvas controlPanel; | 35 protected Canvas controlPanel; |
31 protected Canvas themePanel; | 36 protected ThemePanel themePanel; |
32 protected Widget mapPanel; | 37 protected Widget mapPanel; |
33 | 38 |
34 protected FloodMap floodMap; | 39 protected FloodMap floodMap; |
35 | 40 |
36 | 41 |
37 public MapOutputTab( | 42 public MapOutputTab( |
59 final Canvas wrapper = new Canvas(); | 64 final Canvas wrapper = new Canvas(); |
60 wrapper.setWidth100(); | 65 wrapper.setWidth100(); |
61 wrapper.setHeight100(); | 66 wrapper.setHeight100(); |
62 | 67 |
63 controlPanel = createControlPanel(wrapper); | 68 controlPanel = createControlPanel(wrapper); |
64 themePanel = createThemePanel(); | |
65 mapPanel = floodMap.getMapWidget(); | 69 mapPanel = floodMap.getMapWidget(); |
70 Canvas themePanelWrapper = createThemePanel(); | |
66 | 71 |
67 final HorizontalPanel layout = new HorizontalPanel(); | 72 final HorizontalPanel layout = new HorizontalPanel(); |
68 layout.setWidth("99%"); | 73 layout.setWidth("99%"); |
69 layout.setHeight("99%"); | 74 layout.setHeight("99%"); |
70 layout.add(mapPanel); | 75 layout.add(mapPanel); |
74 HLayout hlayout = new HLayout(); | 79 HLayout hlayout = new HLayout(); |
75 hlayout.setHeight("*"); | 80 hlayout.setHeight("*"); |
76 hlayout.setWidth100(); | 81 hlayout.setWidth100(); |
77 hlayout.setMembersMargin(2); | 82 hlayout.setMembersMargin(2); |
78 | 83 |
79 hlayout.addMember(themePanel); | 84 hlayout.addMember(themePanelWrapper); |
80 hlayout.addMember(wrapper); | 85 hlayout.addMember(wrapper); |
81 | 86 |
82 rootLayout.addMember(controlPanel); | 87 rootLayout.addMember(controlPanel); |
83 rootLayout.addMember(hlayout); | 88 rootLayout.addMember(hlayout); |
84 | 89 |
100 setPane(rootLayout); | 105 setPane(rootLayout); |
101 } | 106 } |
102 | 107 |
103 | 108 |
104 protected void initLayers() { | 109 protected void initLayers() { |
105 // TODO Initialize correct layers here | 110 ThemeList themeList = themePanel.getThemeList(); |
106 | 111 |
107 String url = "http://vmap0.tiles.osgeo.org/wms/vmap0"; | 112 int num = themeList.getThemeCount(); |
108 String layers = "basic"; | 113 |
114 Map map = floodMap.getMap(); | |
115 Bounds extent = null; | |
116 | |
117 for (int i = 1; i <= num; i++) { | |
118 Theme theme = themeList.getThemeAt(i); | |
119 Layer layer = createWMSLayer(theme); | |
120 | |
121 if (layer == null) { | |
122 continue; | |
123 } | |
124 | |
125 map.addLayer(layer); | |
126 | |
127 AttributedTheme at = (AttributedTheme) theme; | |
128 String tmp = at.getAttr("extent"); | |
129 | |
130 if (theme.getActive() == 1) { | |
131 if (extent == null) { | |
132 extent = boundsFromString(tmp); | |
133 } | |
134 else { | |
135 Bounds b = boundsFromString(tmp); | |
136 | |
137 if (b != null) { | |
138 extent.extend(b); | |
139 } | |
140 } | |
141 } | |
142 } | |
143 | |
144 map.zoomToExtent(extent != null | |
145 ? extent | |
146 : new Bounds(-90, -180, 90, 180)); | |
147 } | |
148 | |
149 | |
150 protected Bounds boundsFromString(String bounds) { | |
151 if (bounds == null || bounds.length() == 0) { | |
152 return null; | |
153 } | |
154 | |
155 String[] values = bounds.split(" "); | |
156 | |
157 if (values == null || values.length < 4) { | |
158 return null; | |
159 } | |
160 | |
161 try { | |
162 return new Bounds( | |
163 Double.valueOf(values[0]), | |
164 Double.valueOf(values[3]), | |
165 Double.valueOf(values[2]), | |
166 Double.valueOf(values[1])); | |
167 } | |
168 catch (NumberFormatException nfe) {} | |
169 | |
170 return null; | |
171 } | |
172 | |
173 | |
174 protected Layer createWMSLayer(Theme theme) { | |
175 if (theme == null) { | |
176 return null; | |
177 } | |
178 | |
179 AttributedTheme at = (AttributedTheme) theme; | |
180 | |
181 String type = at.getAttr("name"); | |
182 String desc = at.getAttr("description"); | |
183 String url = at.getAttr("url"); | |
184 String layers = at.getAttr("layers"); | |
185 | |
186 if (url == null || layers == null) { | |
187 return null; | |
188 } | |
189 | |
190 //boolean baseLayer = type.equals("floodmap.wmsbackground"); | |
109 | 191 |
110 WMSParams params = new WMSParams(); | 192 WMSParams params = new WMSParams(); |
111 params.setLayers(layers); | 193 params.setLayers(layers); |
112 params.setFormat("image/png"); | 194 params.setFormat("image/png"); |
113 params.setIsTransparent(false); | 195 params.setIsTransparent(true); |
114 params.setMaxExtent(new Bounds(90, 180, -90, -180)); | 196 params.setMaxExtent(new Bounds(90, 180, -90, -180)); |
115 | 197 |
116 WMS wms = new WMS("vmap0", url, params); | 198 WMS wms = new WMS(desc, url, params); |
117 wms.setIsBaseLayer(true); | 199 wms.setIsVisible(at.getActive() == 1); |
118 wms.setIsVisible(true); | 200 wms.setIsBaseLayer(false); |
119 | 201 |
120 floodMap.getMap().addLayer(wms); | 202 return wms; |
121 floodMap.getMap().setCenter(new LonLat(0, 0)); | |
122 } | 203 } |
123 | 204 |
124 | 205 |
125 protected Canvas createControlPanel(Canvas wrapper) { | 206 protected Canvas createControlPanel(Canvas wrapper) { |
126 return new MapToolbar(floodMap, wrapper); | 207 return new MapToolbar(floodMap, wrapper); |
131 Canvas c = new Canvas(); | 212 Canvas c = new Canvas(); |
132 c.setWidth(200); | 213 c.setWidth(200); |
133 c.setHeight100(); | 214 c.setHeight100(); |
134 c.setBorder("1px solid black"); | 215 c.setBorder("1px solid black"); |
135 | 216 |
136 ChartThemePanel ctp = new ChartThemePanel(collection, mode); | 217 themePanel = new MapThemePanel( |
137 c.addChild(ctp); | 218 collection, mode, new MapThemePanel.ActivateCallback() { |
219 public void activate(Theme theme, boolean active) { | |
220 activateTheme(theme, active); | |
221 } | |
222 }); | |
223 c.addChild(themePanel); | |
138 | 224 |
139 return c; | 225 return c; |
226 } | |
227 | |
228 | |
229 protected void activateTheme(Theme theme, boolean active) { | |
230 String name = theme.getDescription(); | |
231 Layer layer = floodMap.getMap().getLayerByName(name); | |
232 | |
233 if (layer != null) { | |
234 layer.setIsVisible(active); | |
235 } | |
140 } | 236 } |
141 } | 237 } |
142 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 238 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |