view gnv/src/main/webapp/scripts/olutils.jsp @ 988:556e16cc4da5

Switch to tiled layers with one tile to prevent problems in the layertree and the legendgraphicpanel gnv/trunk@1176 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 08 Jun 2010 13:57:05 +0000
parents 42da41835b54
children e3301755bd3c
line wrap: on
line source
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
function handleMeasurements(event) {
    var geometry = event.geometry;
    var units    = event.units;
    var order    = event.order;
    var measure  = event.measure;
    var element  = document.getElementById('measurements');
    
    var out = "";
    if(order == 1) {
        out += "L\u00e4nge: " + measure.toFixed(3) + " " + units;
    } else {
        out += "Fl\u00e4che: " + measure.toFixed(3) + " " + units + "<sup>2</sup>";
    }

    element.innerHTML=out;
};



function readWMC(merge) {
    var layers = mapPanel.layers;
    map    = mapPanel.map;

    var format = new OpenLayers.Format.WMC({'layerOptions': {buffer: 0}});
    var text = document.getElementById("wmc").value;

    merge = true;
    if(merge) {
        try {
            map = format.read(text, {map: map});
        } catch(err) {
            document.getElementById("wmc").value = err;
        }
    } else {
        map.destroy();
        try {
            var jsonFormat = new OpenLayers.Format.JSON();
            var mapOptions = jsonFormat.read();
            map = format.read(text, {map: mapOptions});
        } catch(err) {
            document.getElementById("wmc").value = err;
        }
    }

    // create MapPanel
    mapPanel = new GeoExt.MapPanel({
        border: true,
        title: "Karte",
        region: "center",
        map: map,
        zoom: 1,
        layers: map.layers
    });
}


function writeWMC(merge) {
    var format = new OpenLayers.Format.WMC({'layerOptions': {buffer: 0}});

    try {
        var text = format.write(map);
        document.getElementById("wmc").value = text;
    } catch(err) {
        document.getElementById("wmc").value = err;
    }
}



function toggleGetFeatureInfo(evt) {
    if (infoActive) {
        infoControls.click.deactivate();
        infoActive = false;
    }
    else {
        infoControls.click.activate();
        infoActive = true;
    }
}


function showInfo(evt) {
}


function addLayer() {
    var record = grid.getSelectionModel().getSelected();
    
    if (record) {
        var copy = record.copy();
        copy.set("layer", record.get("layer"));
        copy.get("layer").mergeNewParams({
            format: "image/png",
            transparent: true
        });

        mapPanel.layers.add(copy);
        mapPanel.map.zoomToExtent(OpenLayers.Bounds.fromArray(copy.get("llbbox")));
    }
}


// this is just copied from OpenLayers.Util
function urlAppend(url, paramStr) {
    var newUrl = url;
    if(paramStr) {
        var parts = (url + " ").split(/[?&]/);
        newUrl += (parts.pop() === " " ?
            paramStr :
            parts.length ? "&" + paramStr : "?" + paramStr);
    }
    return newUrl;
}


function updateCapabilities() {
    var ele = Ext.Element.get('capfield');

    var url     = ele.getValue();
    var service = "SERVICE=WMS";
    var request = "REQUEST=GetCapabilities";
    url = urlAppend(url, service);
    url = urlAppend(url, request);

    store = new GeoExt.data.WMSCapabilitiesStore({
        url: url
    });
    store.load();

    grid.destroy();
    grid = new Ext.grid.GridPanel({
        id: 'wmsgrid',
        collapsible: false,
        split: false,
        border: true,
        // TODO: autoHeight might cause trouble
        autoHeight: true,
        overflow: 'auto',
        store: store,
        cm: new Ext.grid.ColumnModel([
        {
            header: '<bean:message key="gnviewer.mapclient.wms.load.grid.name"/>',
            dataIndex: 'name',
            sortable: true
        },
        {
            id: 'title',
            header: '<bean:message key="gnviewer.mapclient.wms.load.grid.title"/>',
            dataIndex: 'title',
            sortable: true
        }]),
        renderTo: 'capgrid',
        bbar: [{
            text: '<bean:message key="gnviewer.mapclient.wms.load.addlayer"/>',
            handler: addLayer
        }]
    });
}


function editFeature(e) {
    var feature = e.feature;

    // TODO SET FEATURE ATTRIBUTES
    //feature.attributes['lawa'] = 999;
    //feature.attributes['lawa_id'] = 999;
    //feature.attributes['w_gwk_lawa'] = 999;
    //feature.attributes['w_wrrl'] = 999;
    //feature.attributes['length_fee'] = 999;
}

function updateControls() {
    var controls = panel.controls;

    controls.remove(drawPointControl);
    controls.remove(drawPathControl);
    controls.remove(drawPolygonControl);

    panel.destroy();
    panel = new OpenLayers.Control.Panel();
    panel.addControls(controls);

    if (points.getVisibility())
        panel.addControls(drawPointControl);
    if (lines.getVisibility())
        panel.addControls(drawPathControl);
    if (polygons.getVisibility())
        panel.addControls(drawPolygonControl);

    map.addControl(panel);
}

http://dive4elements.wald.intevation.org