Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/GetFeatureInfo.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfo.java@a4ff4167be1e |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.client.ui.map; | |
2 | |
3 import java.util.List; | |
4 | |
5 import com.google.gwt.core.client.GWT; | |
6 import com.google.gwt.user.client.rpc.AsyncCallback; | |
7 | |
8 import com.smartgwt.client.util.SC; | |
9 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
10 | |
11 import org.gwtopenmaps.openlayers.client.Map; | |
12 import org.gwtopenmaps.openlayers.client.LonLat; | |
13 import org.gwtopenmaps.openlayers.client.Pixel; | |
14 import org.gwtopenmaps.openlayers.client.event.MapClickListener; | |
15 | |
16 import de.intevation.flys.client.shared.model.FeatureInfo; | |
17 | |
18 import de.intevation.flys.client.client.FLYSConstants; | |
19 import de.intevation.flys.client.client.services.GFIService; | |
20 import de.intevation.flys.client.client.services.GFIServiceAsync; | |
21 import de.intevation.flys.client.shared.model.FacetRecord; | |
22 import de.intevation.flys.client.shared.model.Theme; | |
23 import de.intevation.flys.client.shared.model.AttributedTheme; | |
24 import de.intevation.flys.client.shared.model.FeatureInfoResponse; | |
25 import de.intevation.flys.client.client.ui.ThemePanel; | |
26 | |
27 | |
28 public class GetFeatureInfo implements MapClickListener { | |
29 | |
30 protected GFIServiceAsync gfiService = GWT.create(GFIService.class); | |
31 | |
32 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
33 | |
34 protected GetFeatureInfoWindow gfiWindow; | |
35 | |
36 protected Map map; | |
37 protected ThemePanel themePanel; | |
38 protected String infoFormat; | |
39 | |
40 | |
41 /** | |
42 * @param map | |
43 * @param themes | |
44 * @param url | |
45 * @param infoFormat | |
46 */ | |
47 public GetFeatureInfo(Map map, ThemePanel themePanel, String infoFormat) { | |
48 this.map = map; | |
49 this.themePanel = themePanel; | |
50 this.infoFormat = infoFormat; | |
51 } | |
52 | |
53 | |
54 public void activate(boolean activate) { | |
55 if (activate) { | |
56 map.addMapClickListener(this); | |
57 } | |
58 else { | |
59 map.removeListener(this); | |
60 } | |
61 } | |
62 | |
63 | |
64 protected void newGetFeatureInfoWindow(List<FeatureInfo> features, String title) { | |
65 if (gfiWindow != null) { | |
66 gfiWindow.destroy(); | |
67 } | |
68 | |
69 gfiWindow = new GetFeatureInfoWindow(features, title); | |
70 gfiWindow.show(); | |
71 } | |
72 | |
73 protected void newGetFeatureInfoWindow(String response, String title) { | |
74 if (gfiWindow != null) { | |
75 gfiWindow.destroy(); | |
76 } | |
77 | |
78 gfiWindow = new GetFeatureInfoWindow(response, title); | |
79 gfiWindow.show(); | |
80 } | |
81 | |
82 @Override | |
83 public void onClick(MapClickListener.MapClickEvent e) { | |
84 LonLat lonlat = e.getLonLat(); | |
85 Pixel pixel = map.getPixelFromLonLat(lonlat); | |
86 | |
87 if (themePanel.getSelectedRecords().length == 0) { | |
88 SC.say(MSG.requireTheme()); | |
89 } | |
90 | |
91 for (ListGridRecord rec : themePanel.getSelectedRecords()) { | |
92 Theme act_theme = ((FacetRecord)rec).getTheme(); | |
93 final AttributedTheme at = (AttributedTheme)act_theme; | |
94 gfiService.query( | |
95 act_theme, | |
96 infoFormat, | |
97 map.getExtent().toString(), | |
98 map.getProjection(), | |
99 (int) map.getSize().getHeight(), | |
100 (int) map.getSize().getWidth(), | |
101 pixel.x(), pixel.y(), | |
102 new AsyncCallback<FeatureInfoResponse>() { | |
103 @Override | |
104 public void onFailure(Throwable e) { | |
105 SC.warn(MSG.getString(e.getMessage())); | |
106 } | |
107 | |
108 @Override | |
109 public void onSuccess(FeatureInfoResponse response) { | |
110 List<FeatureInfo> features = response.getFeatures(); | |
111 if (features != null && !features.isEmpty()) { | |
112 newGetFeatureInfoWindow(features, at.getAttr("description")); | |
113 } else if (response.getFeatureInfoHTML() != null) { | |
114 newGetFeatureInfoWindow(response.getFeatureInfoHTML(), | |
115 at.getAttr("description")); | |
116 } else { | |
117 GWT.log("GetFeatureInfo returned neither a list of features nor a string"); | |
118 } | |
119 } | |
120 } | |
121 ); | |
122 break; // More intelligent handling when more then one is selected | |
123 } | |
124 } | |
125 } |