teichmann@5835: package org.dive4elements.river.client.client.ui.map; ingo@1400: ingo@1400: import java.util.List; ingo@1400: ingo@1400: import com.google.gwt.core.client.GWT; ingo@1400: import com.google.gwt.user.client.rpc.AsyncCallback; ingo@1400: ingo@1400: import com.smartgwt.client.util.SC; aheinecke@5794: import com.smartgwt.client.widgets.grid.ListGridRecord; ingo@1400: ingo@1400: import org.gwtopenmaps.openlayers.client.Map; ingo@1400: import org.gwtopenmaps.openlayers.client.LonLat; ingo@1400: import org.gwtopenmaps.openlayers.client.Pixel; ingo@1400: import org.gwtopenmaps.openlayers.client.event.MapClickListener; ingo@1400: teichmann@5835: import org.dive4elements.river.client.shared.model.FeatureInfo; ingo@1400: teichmann@5835: import org.dive4elements.river.client.client.FLYSConstants; teichmann@5835: import org.dive4elements.river.client.client.services.GFIService; teichmann@5835: import org.dive4elements.river.client.client.services.GFIServiceAsync; teichmann@5835: import org.dive4elements.river.client.shared.model.FacetRecord; teichmann@5835: import org.dive4elements.river.client.shared.model.Theme; teichmann@5835: import org.dive4elements.river.client.shared.model.AttributedTheme; teichmann@5835: import org.dive4elements.river.client.shared.model.FeatureInfoResponse; teichmann@5835: import org.dive4elements.river.client.client.ui.ThemePanel; ingo@1400: ingo@1400: ingo@1400: public class GetFeatureInfo implements MapClickListener { ingo@1400: ingo@1400: protected GFIServiceAsync gfiService = GWT.create(GFIService.class); ingo@1400: ingo@1400: protected FLYSConstants MSG = GWT.create(FLYSConstants.class); ingo@1400: ingo@2439: protected GetFeatureInfoWindow gfiWindow; ingo@2439: ingo@1404: protected Map map; ingo@1404: protected ThemePanel themePanel; ingo@1404: protected String infoFormat; ingo@1400: ingo@1400: ingo@1400: /** ingo@1400: * @param map ingo@1400: * @param themes ingo@1400: * @param url ingo@1400: * @param infoFormat ingo@1400: */ ingo@1404: public GetFeatureInfo(Map map, ThemePanel themePanel, String infoFormat) { ingo@1400: this.map = map; ingo@1404: this.themePanel = themePanel; ingo@1400: this.infoFormat = infoFormat; ingo@1400: } ingo@1400: ingo@1400: ingo@1400: public void activate(boolean activate) { ingo@1400: if (activate) { ingo@1400: map.addMapClickListener(this); ingo@1400: } ingo@1400: else { ingo@1400: map.removeListener(this); ingo@1400: } ingo@1400: } ingo@1400: ingo@1400: aheinecke@5813: protected void newGetFeatureInfoWindow(List features, String title) { ingo@2439: if (gfiWindow != null) { ingo@2439: gfiWindow.destroy(); ingo@2439: } ingo@2439: aheinecke@5813: gfiWindow = new GetFeatureInfoWindow(features, title); ingo@2439: gfiWindow.show(); ingo@2439: } ingo@2439: aheinecke@5818: protected void newGetFeatureInfoWindow(String response, String title) { aheinecke@5818: if (gfiWindow != null) { aheinecke@5818: gfiWindow.destroy(); aheinecke@5818: } aheinecke@5818: aheinecke@5818: gfiWindow = new GetFeatureInfoWindow(response, title); aheinecke@5818: gfiWindow.show(); aheinecke@5818: } ingo@2439: ingo@1400: @Override ingo@1400: public void onClick(MapClickListener.MapClickEvent e) { ingo@1400: LonLat lonlat = e.getLonLat(); ingo@1400: Pixel pixel = map.getPixelFromLonLat(lonlat); ingo@1400: aheinecke@5794: if (themePanel.getSelectedRecords().length == 0) { aheinecke@5794: SC.say(MSG.requireTheme()); aheinecke@5794: } ingo@1400: aheinecke@5794: for (ListGridRecord rec : themePanel.getSelectedRecords()) { aheinecke@5794: Theme act_theme = ((FacetRecord)rec).getTheme(); aheinecke@5813: final AttributedTheme at = (AttributedTheme)act_theme; aheinecke@5794: gfiService.query( aheinecke@5794: act_theme, aheinecke@5794: infoFormat, aheinecke@5794: map.getExtent().toString(), aheinecke@5794: map.getProjection(), aheinecke@5794: (int) map.getSize().getHeight(), aheinecke@5794: (int) map.getSize().getWidth(), aheinecke@5794: pixel.x(), pixel.y(), aheinecke@5818: new AsyncCallback() { aheinecke@5794: @Override aheinecke@5794: public void onFailure(Throwable e) { aheinecke@5794: SC.warn(MSG.getString(e.getMessage())); aheinecke@5794: } aheinecke@5794: aheinecke@5794: @Override aheinecke@5818: public void onSuccess(FeatureInfoResponse response) { aheinecke@5818: List features = response.getFeatures(); aheinecke@5818: if (features != null && !features.isEmpty()) { aheinecke@5813: newGetFeatureInfoWindow(features, at.getAttr("description")); aheinecke@5818: } else if (response.getFeatureInfoHTML() != null) { aheinecke@5818: newGetFeatureInfoWindow(response.getFeatureInfoHTML(), aheinecke@5818: at.getAttr("description")); aheinecke@5818: } else { aheinecke@5818: GWT.log("GetFeatureInfo returned neither a list of features nor a string"); aheinecke@5818: } aheinecke@5794: } aheinecke@5794: } aheinecke@5794: ); aheinecke@5794: break; // More intelligent handling when more then one is selected aheinecke@5794: } ingo@1400: } ingo@1400: }