Mercurial > dive4elements > river
view 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 |
line wrap: on
line source
package de.intevation.flys.client.client.ui.map; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Widget; 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.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; import org.gwtopenmaps.openlayers.client.Bounds; import org.gwtopenmaps.openlayers.client.LonLat; import org.gwtopenmaps.openlayers.client.Map; import org.gwtopenmaps.openlayers.client.layer.Layer; import org.gwtopenmaps.openlayers.client.layer.WMS; import org.gwtopenmaps.openlayers.client.layer.WMSParams; import de.intevation.flys.client.shared.model.AttributedTheme; import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.Theme; import de.intevation.flys.client.shared.model.ThemeList; import de.intevation.flys.client.shared.model.OutputMode; import de.intevation.flys.client.client.ui.CollectionView; import de.intevation.flys.client.client.ui.OutputTab; import de.intevation.flys.client.client.ui.ThemePanel; public class MapOutputTab extends OutputTab { protected CollectionView parent; protected Canvas controlPanel; protected ThemePanel themePanel; protected Widget mapPanel; protected FloodMap floodMap; public MapOutputTab( String title, Collection collection, OutputMode mode, CollectionView collectionView ){ super(title, collection, mode); this.parent = collectionView; floodMap = new FloodMap(); initLayout(); initLayers(); } protected void initLayout() { VLayout rootLayout = new VLayout(); rootLayout.setHeight100(); rootLayout.setWidth100(); rootLayout.setMembersMargin(2); final Canvas wrapper = new Canvas(); wrapper.setWidth100(); wrapper.setHeight100(); controlPanel = createControlPanel(wrapper); mapPanel = floodMap.getMapWidget(); Canvas themePanelWrapper = createThemePanel(); final HorizontalPanel layout = new HorizontalPanel(); layout.setWidth("99%"); layout.setHeight("99%"); layout.add(mapPanel); wrapper.addChild(layout); HLayout hlayout = new HLayout(); hlayout.setHeight("*"); hlayout.setWidth100(); hlayout.setMembersMargin(2); hlayout.addMember(themePanelWrapper); hlayout.addMember(wrapper); rootLayout.addMember(controlPanel); rootLayout.addMember(hlayout); wrapper.addResizedHandler(new ResizedHandler() { public void onResized(ResizedEvent e) { Integer height = wrapper.getHeight(); Integer width = wrapper.getWidth(); height = height * 99 / 100; width = width * 99 / 100; String w = String.valueOf(width) + "px"; String h = String.valueOf(height) + "px"; floodMap.setSize(w, h); } }); setPane(rootLayout); } protected void initLayers() { ThemeList themeList = themePanel.getThemeList(); int num = themeList.getThemeCount(); Map map = floodMap.getMap(); Bounds extent = null; for (int i = 1; i <= num; i++) { Theme theme = themeList.getThemeAt(i); Layer layer = createWMSLayer(theme); if (layer == null) { continue; } map.addLayer(layer); AttributedTheme at = (AttributedTheme) theme; String tmp = at.getAttr("extent"); if (theme.getActive() == 1) { if (extent == null) { extent = boundsFromString(tmp); } else { Bounds b = boundsFromString(tmp); if (b != null) { extent.extend(b); } } } } map.zoomToExtent(extent != null ? extent : new Bounds(-90, -180, 90, 180)); } protected Bounds boundsFromString(String bounds) { if (bounds == null || bounds.length() == 0) { return null; } String[] values = bounds.split(" "); if (values == null || values.length < 4) { return null; } try { return new Bounds( Double.valueOf(values[0]), Double.valueOf(values[3]), Double.valueOf(values[2]), Double.valueOf(values[1])); } catch (NumberFormatException nfe) {} return null; } protected Layer createWMSLayer(Theme theme) { if (theme == null) { return null; } AttributedTheme at = (AttributedTheme) theme; String type = at.getAttr("name"); String desc = at.getAttr("description"); String url = at.getAttr("url"); String layers = at.getAttr("layers"); if (url == null || layers == null) { return null; } //boolean baseLayer = type.equals("floodmap.wmsbackground"); WMSParams params = new WMSParams(); params.setLayers(layers); params.setFormat("image/png"); params.setIsTransparent(true); params.setMaxExtent(new Bounds(90, 180, -90, -180)); WMS wms = new WMS(desc, url, params); wms.setIsVisible(at.getActive() == 1); wms.setIsBaseLayer(false); return wms; } protected Canvas createControlPanel(Canvas wrapper) { return new MapToolbar(floodMap, wrapper); } protected Canvas createThemePanel() { Canvas c = new Canvas(); c.setWidth(200); c.setHeight100(); c.setBorder("1px solid black"); themePanel = new MapThemePanel( collection, mode, new MapThemePanel.ActivateCallback() { public void activate(Theme theme, boolean active) { activateTheme(theme, active); } }); c.addChild(themePanel); return c; } protected void activateTheme(Theme theme, boolean active) { String name = theme.getDescription(); Layer layer = floodMap.getMap().getLayerByName(name); if (layer != null) { layer.setIsVisible(active); } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :