view gnv/src/main/webapp/scripts/olutils.jsp @ 1138:2c00570ab3bd

merged doc
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:02 +0200
parents 3665834344a8
children
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 records = grid.getSelectionModel().getSelections();
    for (rec in records){
       
        var record = records[rec];
        // TODO: Look for something better than object
        if (typeof record == "object"){ 
        var copy = record.copy();
        copy.set("layer", record.get("layer"));
        copy.get("layer").mergeNewParams({
            format: "image/png",
            transparent: true
        });
        mapPanel.layers.add(copy);
        }
     }

}


// 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 showWarning(){
    if (store.data.length == 0){
        Ext.MessageBox.alert("<bean:message key="gnviewer.mapclient.wms.load.grid.error.title"/>", '<bean:message key="gnviewer.mapclient.wms.load.grid.error.message"/>', grid);
        return;
    }
}


function updateCapabilities() {

    var url     = capfield.getValue();
    var service = "SERVICE=WMS";
    var request = "REQUEST=GetCapabilities";
    var version = "VERSION=1.1.1";
    url = urlAppend(url, service);
    url = urlAppend(url, request);
    url = urlAppend(url, version);

    store = new GeoExt.data.WMSCapabilitiesStore({
        url: url,
        layerOptions: {singleTile: true}
    });
    store.load({
        callback: showWarning
    });
    
    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);
}
function parseGetFeatureInfoData(event) {
   var contentHTML = "<div>";
   var features = event.features;
   var first = true;
   for (feat in features){
      if (feat != 'remove'){
          var feature = features[feat];
          var attributes = feature.attributes;
          if (first){
            first = false;
          }else{
            contentHTML += "<br/>";
          }
          contentHTML += "<table>";
          for (att in attributes){
             contentHTML += "<tr><td><b>"+att+":</b></td><td>" + attributes[att] + "</td></tr>";
          }
          contentHTML += "</table>";
      }
    
   }
   contentHTML += "</div>";
   
    mapPanel.map.addPopup(new OpenLayers.Popup.FramedCloud(
                    "chicken", 
                    mapPanel.map.getLonLatFromPixel(event.xy),
                    null,
                    contentHTML,
                    null,
                    true
                ));
}

http://dive4elements.wald.intevation.org