[Dive4elements-commits] [PATCH] Fix issue1254, make GetFeatureInfo work reliably

Wald Commits scm-commit at wald.intevation.org
Tue Apr 23 17:14:22 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1366730047 -7200
# Node ID af2aa716152fbb7d6ce51f320d61d072d4c9f263
# Parent  4cc59122b682ab8fc6d9c8ad5b1cdcedd3f4b95b
Fix issue1254, make GetFeatureInfo work reliably

    This reduced GetFeatureInfo to one request per layer and chooses
    the layer based on the selected theme

diff -r 4cc59122b682 -r af2aa716152f 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	Tue Apr 23 15:32:22 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Tue Apr 23 17:14:07 2013 +0200
@@ -1260,5 +1260,7 @@
 
     String wmsURLBoxTitle();
 
+    String requireTheme();
+
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 4cc59122b682 -r af2aa716152f 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	Tue Apr 23 15:32:22 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Tue Apr 23 17:14:07 2013 +0200
@@ -593,6 +593,7 @@
 attribution = &copyIntevation GmbH 2013<br>Data &copy<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>
 wmsURLMenuItem = WMS URL
 wmsURLBoxTitle = Layer WMS URL
+requireTheme = You need to choose a Layer.
 
 # Manual Points Editor
 addpoints = Add points
diff -r 4cc59122b682 -r af2aa716152f 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	Tue Apr 23 15:32:22 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Tue Apr 23 17:14:07 2013 +0200
@@ -417,6 +417,7 @@
 attribution = &copyIntevation GmbH 2013<br>Data &copy<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>
 wmsURLMenuItem = WMS URL
 wmsURLBoxTitle = WMS URL der Kartenebene
+requireTheme = Sie m\u00fcssen ein Thema ausw\u00e4hlen.
 
 # data cage
 waterlevels = Wasserst\u00e4nde
diff -r 4cc59122b682 -r af2aa716152f 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	Tue Apr 23 15:32:22 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Tue Apr 23 17:14:07 2013 +0200
@@ -415,6 +415,7 @@
 attribution = &copyIntevation GmbH 2013<br>Data &copy<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>
 wmsURLMenuItem = WMS URL
 wmsURLBoxTitle = Layer WMS URL
+requireTheme = You need to choose a Layer.
 
 # data cage
 waterlevels = Waterlevels
diff -r 4cc59122b682 -r af2aa716152f flys-client/src/main/java/de/intevation/flys/client/client/services/GFIService.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/GFIService.java	Tue Apr 23 15:32:22 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/GFIService.java	Tue Apr 23 17:14:07 2013 +0200
@@ -15,7 +15,7 @@
 public interface GFIService extends RemoteService {
 
     public List<FeatureInfo> query(
-        List<Theme> themes,
+        Theme       theme,
         String      format,
         String      bbox,
         String      projection,
diff -r 4cc59122b682 -r af2aa716152f flys-client/src/main/java/de/intevation/flys/client/client/services/GFIServiceAsync.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/GFIServiceAsync.java	Tue Apr 23 15:32:22 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/GFIServiceAsync.java	Tue Apr 23 17:14:07 2013 +0200
@@ -14,7 +14,7 @@
 public interface GFIServiceAsync {
 
     void query(
-        List<Theme>           themes,
+        Theme                 theme,
         String                format,
         String                bbox,
         String                projection,
diff -r 4cc59122b682 -r af2aa716152f flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java	Tue Apr 23 15:32:22 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java	Tue Apr 23 17:14:07 2013 +0200
@@ -79,7 +79,6 @@
     /** The collection view*/
     protected CollectionView view;
 
-
     /**
      * Setup Grid, navigation bar.
      * @param collection Collection for which to show themes.
@@ -158,6 +157,9 @@
         return getCollection().getThemeList(mode.getName());
     }
 
+    public ListGridRecord[] getSelectedRecords() {
+        return list.getSelectedRecords();
+    }
 
     /**
      * Registers a new OutputParameterChangeHandler.
diff -r 4cc59122b682 -r af2aa716152f flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfo.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfo.java	Tue Apr 23 15:32:22 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfo.java	Tue Apr 23 17:14:07 2013 +0200
@@ -6,6 +6,7 @@
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
 import com.smartgwt.client.util.SC;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
 
 import org.gwtopenmaps.openlayers.client.Map;
 import org.gwtopenmaps.openlayers.client.LonLat;
@@ -17,6 +18,8 @@
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.services.GFIService;
 import de.intevation.flys.client.client.services.GFIServiceAsync;
+import de.intevation.flys.client.shared.model.FacetRecord;
+import de.intevation.flys.client.shared.model.Theme;
 import de.intevation.flys.client.client.ui.ThemePanel;
 
 
@@ -71,22 +74,34 @@
         LonLat lonlat = e.getLonLat();
         Pixel  pixel  = map.getPixelFromLonLat(lonlat);
 
-        gfiService.query(
-            themePanel.getThemeList().getActiveThemes(),
-            infoFormat,
-            map.getExtent().toString(),
-            map.getProjection(),
-            (int) map.getSize().getHeight(),
-            (int) map.getSize().getWidth(),
-            pixel.x(), pixel.y(),
-            new AsyncCallback<List<FeatureInfo>>() {
-            public void onFailure(Throwable e) {
-                SC.warn(MSG.getString(e.getMessage()));
-            }
+        if (themePanel.getSelectedRecords().length == 0) {
+            SC.say(MSG.requireTheme());
+        }
 
-            public void onSuccess(List<FeatureInfo> features) {
-                newGetFeatureInfoWindow(features);
-            }
-        });
+        for (ListGridRecord rec : themePanel.getSelectedRecords()) {
+            Theme act_theme = ((FacetRecord)rec).getTheme();
+            gfiService.query(
+                act_theme,
+                infoFormat,
+                map.getExtent().toString(),
+                map.getProjection(),
+                (int) map.getSize().getHeight(),
+                (int) map.getSize().getWidth(),
+                pixel.x(), pixel.y(),
+                new AsyncCallback<List<FeatureInfo>>() {
+                    @Override
+                    public void onFailure(Throwable e) {
+                        SC.warn(MSG.getString(e.getMessage()));
+                    }
+
+                    @Override
+                    public void onSuccess(List<FeatureInfo> features) {
+                        if (features != null && !features.isEmpty())
+                            newGetFeatureInfoWindow(features);
+                    }
+                }
+            );
+            break; // More intelligent handling when more then one is selected
+        }
     }
 }
diff -r 4cc59122b682 -r af2aa716152f flys-client/src/main/java/de/intevation/flys/client/server/GFIServiceImpl.java
--- a/flys-client/src/main/java/de/intevation/flys/client/server/GFIServiceImpl.java	Tue Apr 23 15:32:22 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/GFIServiceImpl.java	Tue Apr 23 17:14:07 2013 +0200
@@ -47,7 +47,7 @@
 
 
     /**
-     * @param themes
+     * @param theme
      * @param format
      * @param bbox
      * @param height
@@ -58,7 +58,7 @@
      * @return
      */
     public List<FeatureInfo> query(
-        List<Theme> themes,
+        Theme       theme,
         String      format,
         String      bbox,
         String      projection,
@@ -71,7 +71,7 @@
         logger.info("GFIServiceImpl.query");
 
         String path = createGetFeautureInfoURL(
-            themes, format, bbox, projection, height, width, x, y);
+            theme, format, bbox, projection, height, width, x, y);
 
         logger.debug("URL=" + path);
 
@@ -96,7 +96,7 @@
 
     /**
      * @param map
-     * @param themes
+     * @param theme
      * @param format
      * @param x
      * @param y
@@ -104,7 +104,7 @@
      * @return
      */
     protected String createGetFeautureInfoURL(
-        List<Theme> themes,
+        Theme       theme,
         String      infoFormat,
         String      bbox,
         String      projection,
@@ -114,13 +114,13 @@
         int         y
     ) throws ServerException
     {
-        String url = getUrl(themes);
+        String url = getUrl(theme);
 
         if (url == null || url.length() == 0) {
             throw new ServerException(ERR_NO_VALID_GFI_URL);
         }
 
-        String layers = createLayersString(themes);
+        String layers = ((AttributedTheme)theme).getAttr("layers");
 
         StringBuilder sb = new StringBuilder();
         sb.append(url);
@@ -149,39 +149,16 @@
     }
 
 
-    protected String getUrl(List<Theme> themes) {
-        for (Theme t: themes) {
-            AttributedTheme attr = (AttributedTheme) t;
+    protected String getUrl(Theme theme) {
+        AttributedTheme attr = (AttributedTheme) theme;
 
-            if (attr.getAttrAsBoolean("queryable")) {
-                return attr.getAttr("url");
-            }
+        if (attr.getAttrAsBoolean("queryable")) {
+            return attr.getAttr("url");
         }
-
         return null;
     }
 
 
-    protected String createLayersString(List<Theme> themes) {
-        StringBuilder sb = new StringBuilder();
-        boolean first = true;
-
-        for (Theme theme: themes) {
-            AttributedTheme layer = (AttributedTheme) theme;
-            if (layer.getAttrAsBoolean("queryable")) {
-                if (!first) {
-                    sb.append(",");
-                }
-
-                sb.append(layer.getAttr("layers"));
-                first = false;
-            }
-        }
-
-        return sb.toString();
-    }
-
-
     protected List<FeatureInfo> parseResponse(InputStream is) {
         logger.debug("GFIServiceImpl.parseResponse");
 


More information about the Dive4elements-commits mailing list