view flys-client/src/main/java/de/intevation/flys/client/client/ui/map/FloodMap.java @ 833:dcecdd9693a8

Added a UIProvider that displays a combobox on the left and a map widget in the helper container. flys-client/trunk@2544 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 24 Aug 2011 08:36:51 +0000
parents 407de0f4b66a
children 4af1ee86b0b1
line wrap: on
line source
package de.intevation.flys.client.client.ui.map;

import org.gwtopenmaps.openlayers.client.Bounds;
import org.gwtopenmaps.openlayers.client.Map;
import org.gwtopenmaps.openlayers.client.MapOptions;
import org.gwtopenmaps.openlayers.client.MapWidget;
import org.gwtopenmaps.openlayers.client.feature.VectorFeature;
import org.gwtopenmaps.openlayers.client.format.GeoJSON;
import org.gwtopenmaps.openlayers.client.layer.Vector;
import org.gwtopenmaps.openlayers.client.layer.VectorOptions;
import org.gwtopenmaps.openlayers.client.util.JObjectArray;
import org.gwtopenmaps.openlayers.client.util.JSObject;


public class FloodMap {

    public static final String LAYER_BARRIERS = "vector_layer_barriers";

    protected MapWidget mapWidget;
    protected Map       map;
    protected Vector    barrierLayer;
    protected String    srid;
    protected Bounds    maxExtent;


    public FloodMap(String srid, Bounds maxExtent) {
        this.srid      = srid;
        this.maxExtent = maxExtent;

        MapOptions opts = new MapOptions();
        opts.setControls(new JObjectArray(new JSObject[] {}));
        opts.setNumZoomLevels(16);
        opts.setProjection(getRiverProjection());
        opts.setMaxExtent(maxExtent);
        opts.setMaxResolution(500); // TODO DO THIS ON THE FLY

        mapWidget = new MapWidget("510px", "635px", opts);
        map       = mapWidget.getMap();

        getBarrierLayer();
    }


    public MapWidget getMapWidget() {
        return mapWidget;
    }


    public Map getMap() {
        return map;
    }


    public String getRiverProjection() {
        return "EPSG:" + srid;
    }


    public Vector getBarrierLayer() {
        if (barrierLayer == null) {
            VectorOptions opts = new VectorOptions();
            opts.setProjection(getRiverProjection());
            opts.setMaxExtent(maxExtent);

            barrierLayer = new Vector(LAYER_BARRIERS, opts);
            barrierLayer.setIsBaseLayer(true);

            map.addLayer(barrierLayer);
        }

        return barrierLayer;
    }


    public String getFeaturesAsGeoJSON() {
        VectorFeature[] features = barrierLayer.getFeatures();

        if (features == null || features.length == 0) {
            return null;
        }

        return new GeoJSON().write(features);
    }


    public void setSize(String width, String height) {
        mapWidget.setWidth(width);
        mapWidget.setHeight(height);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org