view flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfo.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 source
package de.intevation.flys.client.client.ui.map;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

import com.smartgwt.client.util.SC;

import org.gwtopenmaps.openlayers.client.Map;
import org.gwtopenmaps.openlayers.client.LonLat;
import org.gwtopenmaps.openlayers.client.Pixel;
import org.gwtopenmaps.openlayers.client.event.MapClickListener;

import de.intevation.flys.client.shared.model.Theme;

import de.intevation.flys.client.client.FLYSConstants;
import de.intevation.flys.client.client.services.GFIService;
import de.intevation.flys.client.client.services.GFIServiceAsync;


public class GetFeatureInfo implements MapClickListener {

    protected GFIServiceAsync gfiService = GWT.create(GFIService.class);

    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);

    protected Map         map;
    protected List<Theme> themes;
    protected String      infoFormat;


    /**
     * @param map
     * @param themes
     * @param url
     * @param infoFormat
     */
    public GetFeatureInfo(Map map, List<Theme> themes, String infoFormat) {
        this.map        = map;
        this.themes     = themes;
        this.infoFormat = infoFormat;
    }


    public void activate(boolean activate) {
        if (activate) {
            map.addMapClickListener(this);
        }
        else {
            map.removeListener(this);
        }
    }


    @Override
    public void onClick(MapClickListener.MapClickEvent e) {
        LonLat lonlat = e.getLonLat();
        Pixel  pixel  = map.getPixelFromLonLat(lonlat);

        gfiService.query(
            themes,
            infoFormat,
            map.getExtent().toString(),
            map.getProjection(),
            (int) map.getSize().getHeight(),
            (int) map.getSize().getWidth(),
            pixel.x(), pixel.y(),
            new AsyncCallback<String>() {
            public void onFailure(Throwable e) {
                SC.warn(MSG.getString(e.getMessage()));
            }

            public void onSuccess(String response) {
                new GetFeatureInfoWindow(response).show();
            }
        });
    }
}

http://dive4elements.wald.intevation.org