view gnv/src/main/webapp/scripts/viewport.jsp @ 1016:3665834344a8

Issue317: Provide a Comboboy with given WMS instead of an Textfield gnv/trunk@1244 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 29 Jun 2010 15:41:10 +0000
parents e2c4e9886dc3
children cce6596560e6
line wrap: on
line source
<%@page import="de.intevation.gnv.action.sessionmodel.SessionModelFactory"%>
<%@page import="de.intevation.gnv.action.MapClientStandaloneAction"%>
<%@page import="de.intevation.gnv.artifactdatabase.objects.map.MapService"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%
boolean standalone = request.getParameter(MapClientStandaloneAction.MAPCLIENTSTANDALONE_KEY) != null &&
request.getParameter(MapClientStandaloneAction.MAPCLIENTSTANDALONE_KEY).equals("true");
MapService mapService = SessionModelFactory.getInstance().getSessionModel(request).getLocalMapService();
%>
OpenLayers.ImgPath = "images/ol/";
OpenLayers.ProxyHost= "/cgi-bin/proxy.cgi?url=";
OpenLayers.Lang.setCode('<%=SessionModelFactory.getInstance().getSessionModel(request).getCurrentLocale().getLanguage() %>');
Ext.BLANK_IMAGE_URL = "scripts/openlayers/OpenLayers-2.9/theme/default/img/blank.gif";

/**
 * XXX
 * Change specific attributes for map, wfs-t, etc here. Do not change these
 * settings inline the code!
 */
PROJECTION     = "EPSG:4326";
MAX_EXTENT     = new OpenLayers.Bounds(-90,-180,90,180);
CURRENT_EXTENT = new OpenLayers.Bounds(<%=mapService.getBBoxValue().replace(' ',',')%>);
INITIAL_CENTER = new OpenLayers.LonLat(5, 55);
GETFEATUREINFO_URL = "<%=mapService.getURL()%>";

Ext.onReady(function() {

    /* this function call initialized the layers that are defined by the user.
     * The variable 'layer' and 'layers' are initialized in this function as
     * well, that are used in the following code! So do not remove this function
     * call.
     */
    initLayers();

    var options = {
        maxExtent: MAX_EXTENT,
        projection: PROJECTION,
        controls: [],
        units: 'm'
    };


/* ------------------------ Create map and add controls ---------------------*/
    // create map
    map      = new OpenLayers.Map(options);
    map.displayProjection = new OpenLayers.Projection(PROJECTION);

    // add controls
    

    var nav   = new OpenLayers.Control.NavigationHistory();
    nav.previous.title = "<bean:message key="gnviewer.mapclient.controls.nav.previous.title"/>";
    nav.next.title = "<bean:message key="gnviewer.mapclient.controls.nav.next.title"/>";
    map.addControl(nav);

    panel = new OpenLayers.Control.Panel();
    controls = {
        previous: nav.previous,
        next    : nav.next,
        navigate: new OpenLayers.Control.MouseDefaults(
            {
                displayClass: 'olControlPan',
                title:'<bean:message key="gnviewer.mapclient.controls.navigate.title"/>'
            }
        ),
        zoombox: new OpenLayers.Control.ZoomBox(
            {
                displayClass: 'olControlZoomBox',
                title: '<bean:message key="gnviewer.mapclient.controls.zoombox.title"/>'
            }
        ),
        info : new OpenLayers.Control.WMSGetFeatureInfo({
            displayClass: "olControlFeatureInfo",
            url: GETFEATUREINFO_URL, 
            title: '<bean:message key="gnviewer.mapclient.controls.info.title"/>',
            queryVisible: true,
            infoFormat: 'application/vnd.ogc.gml',
            eventListeners: {
                getfeatureinfo: parseGetFeatureInfoData
            }
        })
    };
    
    for (var key in controls) {
        panel.addControls([controls[key]]);
    }

    map.addControl(panel);
    map.addControl(new OpenLayers.Control.PanZoomBar({zoomWorldIcon: 'true'}));
    map.addControl(new OpenLayers.Control.MouseDefaults());
    // Displaying the mouse postion 
    mousePosition = new OpenLayers.Control.MousePosition();
    map.addControl(mousePosition);

/* --------------------------------------------------------------------------- */

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

    //map.setCenter(INITIAL_CENTER);


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

    grid = new Ext.grid.GridPanel({
        id: 'wmsgrid',
        collapsible: false,
        split: false,
        border: true,
        //height: 400,
        autoHeight: true,
        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
        }]
    });
    var cap = new Ext.Panel({
        id: 'wmspanel',
        border: true,
        region: 'east',
        title: '<bean:message key="gnviewer.mapclient.wms.load.title"/>',
        collapsible: false,
        split: false,
        height: 400,
        contentEl: 'cap'
        
    });
    
    var capstore = new Ext.data.SimpleStore({
        fields: ['name','url'],
        data : [['<bean:message key="gnviewer.mapclient.wms.local.service.name"/>','<%=mapService.getURL()%>'],<jsp:include page="/WEB-INF/config/reachable-servers.conf" />]
    });
    capfield = new Ext.form.ComboBox({
        id: 'capfield',
        store: capstore,
        displayField:'name',
        width: 245,
        valueField: 'url',
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true,
        renderTo: 'urlinput',
        editable: false,
        value: '<%=mapService.getURL()%>'
        
    });
    


    var capbutton = new Ext.Button({
        id: 'capbutton',
        region: 'west',
        handler: updateCapabilities,
        text: '<bean:message key="gnviewer.mapclient.wms.load.bt.text"/>',
        tooltip: '<bean:message key="gnviewer.mapclient.wms.load.bt.tooltip"/>',
        renderTo: 'urlbutton'
    });




/* --------------------------- Layer Tree ----------------------------------- */


    // LayerTree
    var tree = new Ext.tree.TreePanel({
        border: true,
        enableDD: true,
        region: "east",
        title: "<bean:message key="gnviewer.mapclient.layercontrol"/>",
        width: 200,
        split: true,
        collapsible: false,
        collapseMode: "mini",
        autoScroll: true,
        loader: new Ext.tree.TreeLoader({
            applyLoader: false,
        }),
        root: {
            nodeType: "async",
            children: [{
                nodeType: "gx_baselayercontainer",
                text: "<bean:message key="gnviewer.mapclient.layercontrol.baselayer"/>",
                expanded: true
            }, {
                nodeType: "gx_overlaylayercontainer",
                text: "<bean:message key="gnviewer.mapclient.layercontrol.overlay"/>",
                expanded: true,
                loader: {
                    filter: function(record) {
                        var layer = record.get("layer");
                        return layer.displayInLayerSwitcher === true &&
                               layer.isBaseLayer === false;
                    }
                }
            }]
        },
        rootVisible: false,
        lines: false
    });

/*-------------------------------- Feature grid -------------------------------*/

    // create legend paneclass="headerLineLinksl
    legendPanel = new GeoExt.LegendPanel({
        id: 'legendpanel',
        dynamic: true,
        border: true,
        title: '<bean:message key="gnviewer.mapclient.legend"/>',
        collapsible: false,
        split: false,
        defaults: {
            labelCls: 'legend',
            style: 'padding: 5px'
        },
        bodyStyle: 'padding:5px',
        width: 250,
        autoScroll: true,
        region: 'east',
    }); 


// use separate panels
    // Create GUI
       
    var mylegend = new Ext.Panel(
        {
            region: "west",
            title: '',
            split: true,
            width: 250,
            minSize: 225,
            maxSize: 400,
            collapsible: false,
            overflow: 'auto',
            margins: '0 0 0 5',
            layout: 'accordion',
            layoutConfig: {
                animate: true,
                activeOnTop: false
            },
            items: [
                tree,
                legendPanel,
                cap
            ]
        }
        );
    <%if (!standalone){%>
    // The main panel
    new Ext.Panel({
        renderTo: "mapcontainer",
        layout: "border",
        height: 400,
        items: [mapPanel, mylegend]
    });
    <%}else{ %>
    // Create GUI
    new Ext.Viewport({
        layout: "border",
        items: [
          {
            region: "north",
            contentEl: "headline",
            cls: 'title',
            height: 40
          },
          mylegend,
          mapPanel
        ]
    });
    <%}%>
    map.zoomToExtent(CURRENT_EXTENT);
});

http://dive4elements.wald.intevation.org