ingo@1400: package de.intevation.flys.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: ingo@1402: import de.intevation.flys.client.shared.model.FeatureInfo; ingo@1400: ingo@1400: import de.intevation.flys.client.client.FLYSConstants; ingo@1400: import de.intevation.flys.client.client.services.GFIService; ingo@1400: import de.intevation.flys.client.client.services.GFIServiceAsync; aheinecke@5794: import de.intevation.flys.client.shared.model.FacetRecord; aheinecke@5794: import de.intevation.flys.client.shared.model.Theme; ingo@1404: import de.intevation.flys.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: ingo@2439: protected void newGetFeatureInfoWindow(List features) { ingo@2439: if (gfiWindow != null) { ingo@2439: gfiWindow.destroy(); ingo@2439: } ingo@2439: ingo@2439: gfiWindow = new GetFeatureInfoWindow(features); ingo@2439: gfiWindow.show(); ingo@2439: } ingo@2439: 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@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@5794: 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@5794: public void onSuccess(List features) { aheinecke@5794: if (features != null && !features.isEmpty()) aheinecke@5794: newGetFeatureInfoWindow(features); aheinecke@5794: } aheinecke@5794: } aheinecke@5794: ); aheinecke@5794: break; // More intelligent handling when more then one is selected aheinecke@5794: } ingo@1400: } ingo@1400: }