# HG changeset patch # User Ingo Weinzierl # Date 1319782371 0 # Node ID 28eb4dfe2cbfcf5cd2aee7b2ec5a06248f148df1 # Parent dc715351527f014e797ef548adcb65b68e709e23 Call Collection.doOut to retrieve a map config and use this config to build up an OpenLayers map. flys-client/trunk@3096 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r dc715351527f -r 28eb4dfe2cbf flys-client/ChangeLog --- a/flys-client/ChangeLog Wed Oct 26 12:33:48 2011 +0000 +++ b/flys-client/ChangeLog Fri Oct 28 06:12:51 2011 +0000 @@ -1,3 +1,30 @@ +2011-10-28 Ingo Weinzierl + + * src/main/java/de/intevation/flys/client/server/MapHelper.java: New. It + currently provides a method that parses a MapConfig from Document. + + * src/main/java/de/intevation/flys/client/shared/model/MapConfig.java: New. + This object saves values in a HashMap. Some basic information like srid, + max extent and initial extent can be set/get via methods. + + * src/main/java/de/intevation/flys/client/client/services/MapOutputServiceAsync.java, + src/main/java/de/intevation/flys/client/client/services/MapOutputService.java, + src/main/java/de/intevation/flys/client/server/MapOutputServiceImpl.java: + This service now returns an instance of MapConfig that contains some basic + information required by OpenLayers to create maps. + + * src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java: + OpenLayers maps are created using the MapConfig returned by + MapOutputService but the layers added to the map are taken from + MapThemePanel to keep the ThemePanel and the Map in sync. + + * src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants.java: Added + error strings for the case that no map config was retrieved in + MapOutputService. + 2011-10-26 Felix Wolfsteller * src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java: diff -r dc715351527f -r 28eb4dfe2cbf flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Wed Oct 26 12:33:48 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Fri Oct 28 06:12:51 2011 +0000 @@ -394,6 +394,8 @@ String error_no_feature_selected(); + String error_no_map_config(); + String warning_use_first_feature(); diff -r dc715351527f -r 28eb4dfe2cbf flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Wed Oct 26 12:33:48 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Fri Oct 28 06:12:51 2011 +0000 @@ -201,6 +201,7 @@ error_no_calc_result=No calculation results found. error_no_theme_styles_found=No style for the selected theme found. error_no_feature_selected = No object selected. +error_no_map_config = No Map configuration found. warning_use_first_feature = You have more that one object selected. The first one is used. ## map related strings diff -r dc715351527f -r 28eb4dfe2cbf flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Wed Oct 26 12:33:48 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Fri Oct 28 06:12:51 2011 +0000 @@ -202,6 +202,7 @@ error_no_calc_result=Es wurden keine Berechnungsergebnisse gefunden. error_no_theme_styles_found=Es konnten keine Stile f\u00fcr das gew\u00e4hlte Thema gefunden werden. error_no_feature_selected = Kein Objekt ausgew\u00e4hlt. +error_no_map_config = Es konnte keine Kartenkonfiguration gefunden werden. warning_use_first_feature = Sie haben mehr als ein Objekt ausgew\u00e4hlt. Das erste Objekt wird benutzt. ## map related strings diff -r dc715351527f -r 28eb4dfe2cbf flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Wed Oct 26 12:33:48 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Fri Oct 28 06:12:51 2011 +0000 @@ -196,6 +196,7 @@ error_no_calc_result=No calculation results found. error_no_theme_styles_found=No style for the selected theme found. error_no_feature_selected = No object selected. +error_no_map_config = No Map configuration found. warning_use_first_feature = You have more that one object selected. The first one is used. ## map related strings diff -r dc715351527f -r 28eb4dfe2cbf flys-client/src/main/java/de/intevation/flys/client/client/services/MapOutputService.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/services/MapOutputService.java Wed Oct 26 12:33:48 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/MapOutputService.java Fri Oct 28 06:12:51 2011 +0000 @@ -5,6 +5,7 @@ import de.intevation.flys.client.shared.exceptions.ServerException; import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.MapConfig; /** @@ -16,6 +17,6 @@ @RemoteServiceRelativePath("map") public interface MapOutputService extends RemoteService { - void doOut(Collection collection) throws ServerException; + MapConfig doOut(Collection collection) throws ServerException; } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r dc715351527f -r 28eb4dfe2cbf flys-client/src/main/java/de/intevation/flys/client/client/services/MapOutputServiceAsync.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/services/MapOutputServiceAsync.java Wed Oct 26 12:33:48 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/MapOutputServiceAsync.java Fri Oct 28 06:12:51 2011 +0000 @@ -3,6 +3,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback; import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.MapConfig; /** @@ -10,6 +11,6 @@ */ public interface MapOutputServiceAsync { - public void doOut(Collection collection, AsyncCallback callback); + public void doOut(Collection collection, AsyncCallback callback); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r dc715351527f -r 28eb4dfe2cbf flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java Wed Oct 26 12:33:48 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java Fri Oct 28 06:12:51 2011 +0000 @@ -36,6 +36,7 @@ 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.MapConfig; import de.intevation.flys.client.shared.model.Theme; import de.intevation.flys.client.shared.model.ThemeList; import de.intevation.flys.client.shared.model.OutputMode; @@ -82,22 +83,34 @@ ){ super(title, collection, collectionView, mode); - floodMap = new FloodMap(getSrid(), getMaxExtent()); - - mapService.doOut(collection, new AsyncCallback() { + mapService.doOut(collection, new AsyncCallback() { public void onFailure(Throwable caught) { GWT.log("MAP ERROR: " + caught.getMessage()); } - public void onSuccess(Void v) { + public void onSuccess(MapConfig c) { GWT.log("MAP SUCCESS!"); + + Bounds max = boundsFromString(c.getMaxExtent()); + Bounds initial = boundsFromString(c.getInitialExtent()); + + if (initial == null) { + GWT.log("Warning: No initial extent set."); + initial = max; + } + + setFloodmap(new FloodMap(c.getSrid(), max)); + + initLayout(); + initLayers(); + initBarriers(); + + GWT.log("MAX EXTENT: " + max); + GWT.log("ZOOM TO: " + initial); + getMap().zoomToExtent(initial); } } ); - - initLayout(); - initLayers(); - initBarriers(); } @@ -156,10 +169,7 @@ ThemeList themeList = themePanel.getThemeList(); int num = themeList.getThemeCount(); - - Map map = floodMap.getMap(); - Bounds extent = null; - Bounds wsplgenExtent = null; + Map map = floodMap.getMap(); for (int i = num; i >= 0; i--) { Theme theme = themeList.getThemeAt(i); @@ -170,37 +180,7 @@ } map.addLayer(layer); - - AttributedTheme at = (AttributedTheme) theme; - String tmp = at.getAttr("extent"); - - if (WSPLGEN_FACET.equals(at.getFacet())) { - // if there is a wsplgen layer, we want to zoom to - // that place initially - wsplgenExtent = boundsFromString(tmp); - } - - if (theme.getActive() == 1) { - if (extent == null) { - extent = boundsFromString(tmp); - } - else { - Bounds b = boundsFromString(tmp); - - if (b != null) { - extent.extend(b); - } - } - } } - - extent = wsplgenExtent != null ? wsplgenExtent : extent; - - GWT.log("Maps initial extent = " + extent); - - map.zoomToExtent(extent != null - ? extent - : new Bounds(-90, -180, 90, 180)); } @@ -253,6 +233,11 @@ } + protected void setFloodmap(FloodMap floodMap) { + this.floodMap = floodMap; + } + + protected Map getMap() { return floodMap.getMap(); } @@ -317,41 +302,8 @@ } - 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); - - if (theme == null) { - continue; - } - - 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) { + GWT.log("Create Bounds from String: '" + bounds + "'"); if (bounds == null || bounds.length() == 0) { return null; } diff -r dc715351527f -r 28eb4dfe2cbf flys-client/src/main/java/de/intevation/flys/client/server/MapHelper.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/MapHelper.java Fri Oct 28 06:12:51 2011 +0000 @@ -0,0 +1,89 @@ +package de.intevation.flys.client.server; + +import org.w3c.dom.Document; + +import org.apache.log4j.Logger; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.flys.client.shared.model.MapConfig; + + +public class MapHelper { + + private static final Logger logger = Logger.getLogger(MapHelper.class); + + + public static final String XPATH_SRID = + "/art:floodmap/art:srid/text()"; + + public static final String XPATH_MAX_EXTENT = + "/art:floodmap/art:maxExtent/text()"; + + public static final String XPATH_INITIAL_EXTENT = + "/art:floodmap/art:initialExtent/text()"; + + + private MapHelper() { + } + + + public static MapConfig parseConfig(Document raw) { + logger.debug("MapHelper.parseConfig"); + + logger.debug(XMLUtils.toString(raw)); + + MapConfig config = new MapConfig(); + + setSrid(config, raw); + setMaxExtent(config, raw); + setInitialExtent(config, raw); + + return config; + } + + + protected static void setSrid(MapConfig config, Document raw) { + String srid = (String) XMLUtils.xpathString( + raw, + XPATH_SRID, + ArtifactNamespaceContext.INSTANCE); + + logger.debug("Found srid: '" + srid + "'"); + + if (srid != null && srid.length() > 0) { + logger.debug("Set srid: '" + srid + "'"); + config.setSrid(srid); + } + } + + + protected static void setMaxExtent(MapConfig config, Document raw) { + String maxExtent = (String) XMLUtils.xpathString( + raw, + XPATH_MAX_EXTENT, + ArtifactNamespaceContext.INSTANCE); + + logger.debug("Found max extent: '" + maxExtent + "'"); + + if (maxExtent != null && maxExtent.length() > 0) { + logger.debug("Set max extent: '" + maxExtent + "'"); + config.setMaxExtent(maxExtent); + } + } + + + protected static void setInitialExtent(MapConfig config, Document raw) { + String initialExtent = (String) XMLUtils.xpathString( + raw, + XPATH_INITIAL_EXTENT, + ArtifactNamespaceContext.INSTANCE); + + if (initialExtent != null && initialExtent.length() > 0) { + logger.debug("Set initial extent: '" + initialExtent + "'"); + config.setInitialExtent(initialExtent); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r dc715351527f -r 28eb4dfe2cbf flys-client/src/main/java/de/intevation/flys/client/server/MapOutputServiceImpl.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/MapOutputServiceImpl.java Wed Oct 26 12:33:48 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/MapOutputServiceImpl.java Fri Oct 28 06:12:51 2011 +0000 @@ -18,6 +18,7 @@ import de.intevation.flys.client.shared.exceptions.ServerException; import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.MapConfig; import de.intevation.flys.client.client.services.MapOutputService; @@ -31,7 +32,10 @@ Logger.getLogger(MapOutputServiceImpl.class); - public void doOut(Collection collection) + public static final String ERROR_NO_MAP_CONFIG = "error_no_map_config"; + + + public MapConfig doOut(Collection collection) throws ServerException { logger.info("MapOutputServiceImpl.doOut"); @@ -48,9 +52,7 @@ Document response = XMLUtils.parseDocument(is); - logger.debug(XMLUtils.toString(response)); - - // TODO parse response document and return a MapConfig object + return MapHelper.parseConfig(response); } catch (ConnectionException e) { logger.error(e, e); @@ -58,6 +60,8 @@ catch (IOException ioe) { logger.error(ioe, ioe); } + + throw new ServerException(ERROR_NO_MAP_CONFIG); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r dc715351527f -r 28eb4dfe2cbf flys-client/src/main/java/de/intevation/flys/client/shared/model/MapConfig.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/MapConfig.java Fri Oct 28 06:12:51 2011 +0000 @@ -0,0 +1,62 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + + +public class MapConfig implements Serializable { + + public static final String ATTR_SRID = "srid"; + public static final String ATTR_MAX_EXTENT = "max_extent"; + public static final String ATTR_INITIAL_EXTENT = "initial_extent"; + + + protected Map attributes; + + + public MapConfig() { + attributes = new HashMap(); + } + + + public void setAttribute(String key, String value) { + attributes.put(key, value); + } + + + public String getAttribute(String key) { + return attributes.get(key); + } + + + public void setSrid(String srid) { + setAttribute(ATTR_SRID, srid); + } + + + public String getSrid() { + return getAttribute(ATTR_SRID); + } + + + public void setMaxExtent(String maxExtent) { + setAttribute(ATTR_MAX_EXTENT, maxExtent); + } + + + public String getMaxExtent() { + return getAttribute(ATTR_MAX_EXTENT); + } + + + public void setInitialExtent(String initialExtent) { + setAttribute(ATTR_INITIAL_EXTENT, initialExtent); + } + + + public String getInitialExtent() { + return getAttribute(ATTR_INITIAL_EXTENT); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :