diff flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfoWindow.java @ 1400:96708d81eaf6

Added an initial GetFeatureInfo tool to get information about points in the map. flys-client/trunk@3285 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 17 Nov 2011 16:20:55 +0000
parents
children 15ef3d3081b7
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfoWindow.java	Thu Nov 17 16:20:55 2011 +0000
@@ -0,0 +1,84 @@
+package de.intevation.flys.client.client.ui.map;
+
+import com.google.gwt.core.client.GWT;
+
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.Window;
+import com.smartgwt.client.widgets.layout.HLayout;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import org.gwtopenmaps.openlayers.client.feature.VectorFeature;
+import org.gwtopenmaps.openlayers.client.format.GML;
+import org.gwtopenmaps.openlayers.client.util.Attributes;
+import org.gwtopenmaps.openlayers.client.util.JSObject;
+
+import de.intevation.flys.client.client.FLYSConstants;
+
+
+public class GetFeatureInfoWindow extends Window {
+
+    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
+
+    protected VectorFeature[] features;
+
+
+    public GetFeatureInfoWindow(String gml) {
+        super();
+        features = new GML().read(gml);
+        initLayout();
+    }
+
+
+    protected void initLayout() {
+        VLayout root = new VLayout();
+
+        for (VectorFeature feature: features) {
+            root.addMember(createFeatureRow(feature));
+        }
+
+        addItem(root);
+
+        setWidth(400);
+        setHeight(200);
+        setTitle(MSG.getFeatureInfoWindowTitle());
+
+        centerInPage();
+    }
+
+
+    protected HLayout createFeatureRow(VectorFeature feature) {
+        HLayout r = new HLayout();
+        r.setHeight(25);
+
+        String[][] attrs = extractProperties(feature);
+
+        for (String[] attr: attrs) {
+            Label l = new Label(attr[0] + ": " + attr[1]);
+            l.setHeight(25);
+            l.setBorder("1px solid black");
+            r.addMember(l);
+        }
+
+        return r;
+    }
+
+
+    protected String[][] extractProperties(VectorFeature feature) {
+        Attributes tmp   = feature.getAttributes();
+        JSObject   jsobj = tmp.getJSObject();
+
+        String   tmpNames = jsobj.getPropertyNames();
+        String[] allNames = tmpNames.split(",");
+
+        String[][] attr = new String[allNames.length][];
+
+        for (int i = 0, n = attr.length; i < n; i++) {
+            attr[i] = new String[] {
+                allNames[i],
+                jsobj.getPropertyAsString(allNames[i]) };
+        }
+
+        return attr;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org