[Dive4elements-commits] [PATCH 1 of 2] Request feature info on all layers and show it as html if

Wald Commits scm-commit at wald.intevation.org
Wed Apr 24 17:35:16 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1366817607 -7200
# Node ID a4ff4167be1ec9db3edd25b5b2e4e24eba68243f
# Parent  a1dd784d8b072bf786756a90a2180f0b1bdc18ad
Request feature info on all layers and show it as html if
the server does not return valid gml.

Non queryable layers produce an error message when the request
fails. This is good enough

diff -r a1dd784d8b07 -r a4ff4167be1e 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	Wed Apr 24 15:20:50 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/GFIService.java	Wed Apr 24 17:33:27 2013 +0200
@@ -7,14 +7,14 @@
 
 
 import de.intevation.flys.client.shared.exceptions.ServerException;
-import de.intevation.flys.client.shared.model.FeatureInfo;
+import de.intevation.flys.client.shared.model.FeatureInfoResponse;
 import de.intevation.flys.client.shared.model.Theme;
 
 
 @RemoteServiceRelativePath("getfeatureinfo")
 public interface GFIService extends RemoteService {
 
-    public List<FeatureInfo> query(
+    public FeatureInfoResponse query(
         Theme       theme,
         String      format,
         String      bbox,
diff -r a1dd784d8b07 -r a4ff4167be1e 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	Wed Apr 24 15:20:50 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/GFIServiceAsync.java	Wed Apr 24 17:33:27 2013 +0200
@@ -4,7 +4,7 @@
 
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
-import de.intevation.flys.client.shared.model.FeatureInfo;
+import de.intevation.flys.client.shared.model.FeatureInfoResponse;
 import de.intevation.flys.client.shared.model.Theme;
 
 
@@ -22,7 +22,7 @@
         int                   width,
         int                   x,
         int                   y,
-        AsyncCallback<List<FeatureInfo>> callback
+        AsyncCallback<FeatureInfoResponse> callback
     );
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r a1dd784d8b07 -r a4ff4167be1e 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	Wed Apr 24 15:20:50 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfo.java	Wed Apr 24 17:33:27 2013 +0200
@@ -21,6 +21,7 @@
 import de.intevation.flys.client.shared.model.FacetRecord;
 import de.intevation.flys.client.shared.model.Theme;
 import de.intevation.flys.client.shared.model.AttributedTheme;
+import de.intevation.flys.client.shared.model.FeatureInfoResponse;
 import de.intevation.flys.client.client.ui.ThemePanel;
 
 
@@ -69,6 +70,14 @@
         gfiWindow.show();
     }
 
+    protected void newGetFeatureInfoWindow(String response, String title) {
+        if (gfiWindow != null) {
+            gfiWindow.destroy();
+        }
+
+        gfiWindow = new GetFeatureInfoWindow(response, title);
+        gfiWindow.show();
+    }
 
     @Override
     public void onClick(MapClickListener.MapClickEvent e) {
@@ -90,16 +99,23 @@
                 (int) map.getSize().getHeight(),
                 (int) map.getSize().getWidth(),
                 pixel.x(), pixel.y(),
-                new AsyncCallback<List<FeatureInfo>>() {
+                new AsyncCallback<FeatureInfoResponse>() {
                     @Override
                     public void onFailure(Throwable e) {
                         SC.warn(MSG.getString(e.getMessage()));
                     }
 
                     @Override
-                    public void onSuccess(List<FeatureInfo> features) {
-                        if (features != null && !features.isEmpty())
+                    public void onSuccess(FeatureInfoResponse response) {
+                        List<FeatureInfo> features = response.getFeatures();
+                        if (features != null && !features.isEmpty()) {
                             newGetFeatureInfoWindow(features, at.getAttr("description"));
+                        } else if (response.getFeatureInfoHTML() != null) {
+                            newGetFeatureInfoWindow(response.getFeatureInfoHTML(),
+                                at.getAttr("description"));
+                        } else {
+                            GWT.log("GetFeatureInfo returned neither a list of features nor a string");
+                        }
                     }
                 }
             );
diff -r a1dd784d8b07 -r a4ff4167be1e flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfoWindow.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfoWindow.java	Wed Apr 24 15:20:50 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfoWindow.java	Wed Apr 24 17:33:27 2013 +0200
@@ -2,6 +2,7 @@
 
 import com.google.gwt.core.client.GWT;
 
+import com.smartgwt.client.widgets.HTMLPane;
 import com.smartgwt.client.widgets.Label;
 import com.smartgwt.client.widgets.Window;
 import com.smartgwt.client.widgets.layout.VLayout;
@@ -11,6 +12,7 @@
 
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.shared.model.FeatureInfo;
+import de.intevation.flys.client.shared.model.FeatureInfoResponse;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -31,6 +33,8 @@
 
     protected String title;
 
+    protected String featureInfoHTML;
+
 
     public static final int ROW_HEIGHT = 25;
 
@@ -43,6 +47,27 @@
         initLayout();
     }
 
+    public GetFeatureInfoWindow(String featureInfoHTML, String title) {
+        super();
+        features = null;
+        this.title = title;
+        this.featureInfoHTML = featureInfoHTML;
+
+        initLayoutHTML();
+    }
+
+    protected void initLayoutHTML() {
+        HTMLPane pane = new HTMLPane();
+        pane.setContents(featureInfoHTML);
+        addItem(pane);
+        setWidth(500);
+        setHeight(300);
+
+        setIsModal(false);
+//        setShowModalMask(true);
+
+        centerInPage();
+    }
 
     protected void initLayout() {
         VLayout root = new VLayout();
diff -r a1dd784d8b07 -r a4ff4167be1e 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	Wed Apr 24 15:20:50 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/GFIServiceImpl.java	Wed Apr 24 17:33:27 2013 +0200
@@ -1,11 +1,14 @@
 package de.intevation.flys.client.server;
 
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Scanner;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
@@ -20,6 +23,7 @@
 import de.intevation.flys.client.shared.exceptions.ServerException;
 import de.intevation.flys.client.shared.model.AttributedTheme;
 import de.intevation.flys.client.shared.model.FeatureInfo;
+import de.intevation.flys.client.shared.model.FeatureInfoResponse;
 import de.intevation.flys.client.shared.model.Theme;
 
 import de.intevation.flys.client.client.services.GFIService;
@@ -57,7 +61,7 @@
      *
      * @return
      */
-    public List<FeatureInfo> query(
+    public FeatureInfoResponse query(
         Theme       theme,
         String      format,
         String      bbox,
@@ -151,24 +155,42 @@
 
     protected String getUrl(Theme theme) {
         AttributedTheme attr = (AttributedTheme) theme;
-
-        if (attr.getAttrAsBoolean("queryable")) {
-            return attr.getAttr("url");
-        }
-        return null;
+        return attr.getAttr("url");
     }
 
 
-    protected List<FeatureInfo> parseResponse(InputStream is) {
+    protected FeatureInfoResponse parseResponse(InputStream is) {
         logger.debug("GFIServiceImpl.parseResponse");
 
-        Document response = XMLUtils.parseDocument(is);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        byte [] buf = new byte[1024];
 
-        List<FeatureInfo> features = new ArrayList<FeatureInfo>();
+        int r = -1;
+        try {
+            while ((r = is.read(buf)) >= 0) {
+                baos.write(buf, 0, r);
+            }
+        } catch (IOException ex) {
+            logger.warn("GetFeatureInfo response could not be read: ", ex);
+            return new FeatureInfoResponse();
+        }
 
-        parseFeatureInfos(response, features);
+        String content;
+        try {
+            content = baos.toString("UTF-8");
+        }
+        catch (UnsupportedEncodingException uee) {
+            content = baos.toString();
+        }
 
-        return features;
+        Document response = XMLUtils.parseDocument(content);
+        if (response != null) {
+            List<FeatureInfo> features = new ArrayList<FeatureInfo>();
+            parseFeatureInfos(response, features);
+            return new FeatureInfoResponse(features, null);
+        }
+        // Unable to parse just return the response as is
+        return new FeatureInfoResponse(new ArrayList<FeatureInfo>(), content);
     }
 
 


More information about the Dive4elements-commits mailing list