Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java @ 823:407de0f4b66a
Set the map projection and its max extent dynamically - information extracted from facets.
flys-client/trunk@2515 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 19 Aug 2011 15:57:23 +0000 |
parents | 112f95d7b286 |
children | 1b9b7e9ab219 |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java Fri Aug 12 15:51:51 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java Fri Aug 19 15:57:23 2011 +0000 @@ -1,5 +1,6 @@ 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; @@ -14,6 +15,7 @@ import org.gwtopenmaps.openlayers.client.layer.Layer; 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.AttributedTheme; import de.intevation.flys.client.shared.model.Collection; @@ -28,6 +30,9 @@ public class MapOutputTab extends OutputTab { + public static final String DEFAULT_SRID = "4326"; + + protected CollectionView parent; protected Canvas controlPanel; @@ -46,7 +51,7 @@ super(title, collection, mode); this.parent = collectionView; - floodMap = new FloodMap(); + floodMap = new FloodMap(getSrid(), getMaxExtent()); initLayout(); initLayers(); @@ -139,12 +144,66 @@ } } - map.zoomToExtent(extent != null + GWT.log("Maps initial extent = " + extent); + + map.zoomToExtent(extent != null ? extent : new Bounds(-90, -180, 90, 180)); } + public ThemeList getThemeList() { + return collection.getThemeList(mode.getName()); + } + + + public String getSrid() { + ThemeList themeList = getThemeList(); + + int num = themeList.getThemeCount(); + + for (int i = 1; i <= num; i++) { + AttributedTheme theme = (AttributedTheme) themeList.getThemeAt(i); + String srid = theme.getAttr("srid"); + + if (srid != null && srid.length() > 0) { + return srid; + } + } + + return DEFAULT_SRID; + } + + + public Bounds getMaxExtent() { + ThemeList themeList = getThemeList(); + + int num = themeList.getThemeCount(); + + Bounds extent = null; + + for (int i = 1; i <= num; i++) { + AttributedTheme theme = (AttributedTheme) themeList.getThemeAt(i); + String tmp = theme.getAttr("extent"); + + if (theme.getActive() == 1) { + if (extent == null) { + extent = boundsFromString(tmp); + } + else { + Bounds b = boundsFromString(tmp); + + if (b != null) { + extent.extend(b); + } + } + } + } + + return extent; + } + + protected Bounds boundsFromString(String bounds) { if (bounds == null || bounds.length() == 0) { return null; @@ -159,9 +218,9 @@ try { return new Bounds( Double.valueOf(values[0]), - Double.valueOf(values[3]), + Double.valueOf(values[1]), Double.valueOf(values[2]), - Double.valueOf(values[1])); + Double.valueOf(values[3])); } catch (NumberFormatException nfe) {} @@ -191,9 +250,13 @@ 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); + WMSOptions opts = new WMSOptions(); + opts.setProjection("EPSG:" + getSrid()); + opts.setSingleTile(true); + opts.setRatio(1); + + WMS wms = new WMS(desc, url, params, opts); wms.setIsVisible(at.getActive() == 1); wms.setIsBaseLayer(false);