comparison 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
comparison
equal deleted inserted replaced
1399:748e7c828d03 1400:96708d81eaf6
1 package de.intevation.flys.client.client.ui.map;
2
3 import com.google.gwt.core.client.GWT;
4
5 import com.smartgwt.client.widgets.Label;
6 import com.smartgwt.client.widgets.Window;
7 import com.smartgwt.client.widgets.layout.HLayout;
8 import com.smartgwt.client.widgets.layout.VLayout;
9
10 import org.gwtopenmaps.openlayers.client.feature.VectorFeature;
11 import org.gwtopenmaps.openlayers.client.format.GML;
12 import org.gwtopenmaps.openlayers.client.util.Attributes;
13 import org.gwtopenmaps.openlayers.client.util.JSObject;
14
15 import de.intevation.flys.client.client.FLYSConstants;
16
17
18 public class GetFeatureInfoWindow extends Window {
19
20 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
21
22 protected VectorFeature[] features;
23
24
25 public GetFeatureInfoWindow(String gml) {
26 super();
27 features = new GML().read(gml);
28 initLayout();
29 }
30
31
32 protected void initLayout() {
33 VLayout root = new VLayout();
34
35 for (VectorFeature feature: features) {
36 root.addMember(createFeatureRow(feature));
37 }
38
39 addItem(root);
40
41 setWidth(400);
42 setHeight(200);
43 setTitle(MSG.getFeatureInfoWindowTitle());
44
45 centerInPage();
46 }
47
48
49 protected HLayout createFeatureRow(VectorFeature feature) {
50 HLayout r = new HLayout();
51 r.setHeight(25);
52
53 String[][] attrs = extractProperties(feature);
54
55 for (String[] attr: attrs) {
56 Label l = new Label(attr[0] + ": " + attr[1]);
57 l.setHeight(25);
58 l.setBorder("1px solid black");
59 r.addMember(l);
60 }
61
62 return r;
63 }
64
65
66 protected String[][] extractProperties(VectorFeature feature) {
67 Attributes tmp = feature.getAttributes();
68 JSObject jsobj = tmp.getJSObject();
69
70 String tmpNames = jsobj.getPropertyNames();
71 String[] allNames = tmpNames.split(",");
72
73 String[][] attr = new String[allNames.length][];
74
75 for (int i = 0, n = attr.length; i < n; i++) {
76 attr[i] = new String[] {
77 allNames[i],
78 jsobj.getPropertyAsString(allNames[i]) };
79 }
80
81 return attr;
82 }
83 }
84 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org