Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/DigitizePanel.java @ 1293:e88cd17b3420
Bugfix: #233 Redraw computation table if no data was retrieved to display an error message immediatly.
flys-client/trunk@2906 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 07 Oct 2011 13:39:35 +0000 |
parents | 89a47098bcbd |
children | 17e7d5e437fb |
line wrap: on
line source
package de.intevation.flys.client.client.ui; import java.util.List; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.events.ResizedEvent; import com.smartgwt.client.widgets.events.ResizedHandler; import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; import org.gwtopenmaps.openlayers.client.Map; import org.gwtopenmaps.openlayers.client.feature.VectorFeature; import org.gwtopenmaps.openlayers.client.format.GeoJSON; import org.gwtopenmaps.openlayers.client.layer.WMS; import org.gwtopenmaps.openlayers.client.layer.WMSParams; import org.gwtopenmaps.openlayers.client.layer.WMSOptions; import de.intevation.flys.client.shared.model.Data; import de.intevation.flys.client.shared.model.DataItem; import de.intevation.flys.client.shared.model.DataList; import de.intevation.flys.client.shared.model.DefaultData; import de.intevation.flys.client.shared.model.DefaultDataItem; import de.intevation.flys.client.shared.model.MapInfo; import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.ui.map.FloodMap; import de.intevation.flys.client.client.ui.map.MapPanel; import de.intevation.flys.client.client.services.MapInfoService; import de.intevation.flys.client.client.services.MapInfoServiceAsync; public class DigitizePanel extends SelectProvider implements TabSelectedHandler { protected MapInfoServiceAsync mapInfo = GWT.create(MapInfoService.class); protected FloodMap floodMap; public static final String UESK_BARRIERS = "uesk.barriers"; public DigitizePanel() { } @Override public Canvas create(DataList list) { List<Data> data = list.getAll(); Data barriers = null; for (int i = data.size()-1; i >= 0; i--) { Data d = data.get(i); if (d.getLabel().equals(UESK_BARRIERS)) { barriers = d; data.remove(d); } } DataList clone = (DataList) list.clone(); List<Data> all = clone.getAll(); all.remove(UESK_BARRIERS); Canvas selectBox = super.create(clone); final Config cfg = Config.getInstance(); final String url = cfg.getServerUrl(); final String locale = cfg.getLocale(); DataItem[] obj = barriers.getItems(); final String[] geojson = new String[1]; for (DataItem item: obj) { if (item.getLabel().equals(UESK_BARRIERS)) { geojson[0] = item.getStringValue(); break; } } String river = getDataValue("state.winfo.river", "river"); mapInfo.getMapInfo(url, locale, river, new AsyncCallback<MapInfo>() { public void onFailure(Throwable caught) { String msg = caught.getMessage(); GWT.log("Error while fetching MapInfo: " + msg); SC.warn(MSG.getString(msg)); } public void onSuccess(MapInfo info) { createMapWidget(info, geojson[0]); } }); return selectBox; } @Override protected Data[] getData() { Data[] data = super.getData(); Data[] total = new Data[2]; DataItem item = new DefaultDataItem( UESK_BARRIERS, UESK_BARRIERS, floodMap.getFeaturesAsGeoJSON()); total[0] = data[0]; total[1] = new DefaultData( UESK_BARRIERS, null, null, new DataItem[] { item }); return total; } public void createMapWidget(MapInfo mapInfo, String geojson) { final MapPanel mapPanel = new MapPanel(mapInfo, true); floodMap = mapPanel.getFloodMap(); Map map = floodMap.getMap(); helperContainer.addMember(mapPanel); helperContainer.addResizedHandler(new ResizedHandler() { public void onResized(ResizedEvent e) { Integer height = helperContainer.getHeight(); Integer width = helperContainer.getWidth(); height = height * 99 / 100; width = width * 99 / 100; String w = String.valueOf(width) + "px"; String h = String.valueOf(height) + "px"; mapPanel.getFloodMap().setSize(w, h); } }); parameterList.registerCollectionViewTabHandler(this); WMS axis = getLayer( mapInfo.getWmsUrl(), "riveraxis", mapInfo.getProjection(), false); WMS back = getLayer( mapInfo.getBackgroundWmsUrl(), mapInfo.getBackgroundWmsLayers(), mapInfo.getProjection(), false); map.addLayer(axis); map.addLayer(back); if (geojson != null && geojson.length() > 0) { VectorFeature[] features = new GeoJSON().read(geojson); floodMap.getBarrierLayer().addFeatures(features); } map.zoomToMaxExtent(); } protected WMS getLayer(String url, String layers, String proj, boolean x) { WMSParams params = new WMSParams(); params.setLayers(layers); params.setFormat("image/png"); params.setIsTransparent(!x); WMSOptions opts = new WMSOptions(); opts.setProjection(proj); opts.setSingleTile(true); opts.setRatio(1); WMS wms = new WMS(layers, url, params, opts); wms.setIsVisible(true); wms.setIsBaseLayer(x); return wms; } public void onTabSelected(TabSelectedEvent tse) { if (tse.getTabNum () != 0) { floodMap.hideBarrierLayer(); } else { floodMap.showBarrierLayer(); } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :