Mercurial > dive4elements > river
changeset 5818:a4ff4167be1e
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
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 24 Apr 2013 17:33:27 +0200 |
parents | a1dd784d8b07 |
children | 1722b0c47f5b |
files | flys-client/src/main/java/de/intevation/flys/client/client/services/GFIService.java flys-client/src/main/java/de/intevation/flys/client/client/services/GFIServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfo.java flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfoWindow.java flys-client/src/main/java/de/intevation/flys/client/server/GFIServiceImpl.java |
diffstat | 5 files changed, 81 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- 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,
--- 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 :
--- 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"); + } } } );
--- 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();
--- 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); }