如何让Ext.tree.TreePanel显示多个服务

时间:2013-11-18 22:43:56

标签: javascript-framework extjs3

我正在尝试向Ext.tree.TreePanel添加多个服务。我有一个使用一个服务的treePanel的工作示例。如何将多个URL服务添加到同一个TreePanel?

2 个答案:

答案 0 :(得分:0)

如果我理解你的问题,你必须合并两个网络服务的回复。

答案 1 :(得分:0)

我发现以下内容有很大帮助: http://www.geoext.org/pipermail/users/2011-July/002397.html 结束以下支持多个服务的代码: 另请注意原始代码来自http://www.geoext.org/examples.html

罗杰

var tree, mapPanel;
/**
 * Copyright (c) 2008-2011 The Open Source Geospatial Foundation
 *
 * Published under the BSD license.
 * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
 * of the license.
 */

/** api: example[wms-tree]
 *  WMS Capabilities Tree
 *  ---------------------
 *  Create a tree loader from WMS capabilities documents.
 */
var tree, mapPanel;

Ext.onReady(function() {
OpenLayers.ProxyHost="cgi-bin/prox.cgi?url=";
    var wms_child = new Ext.tree.AsyncTreeNode({
        text: 'GeoServer Demo WMS',
        loader: new GeoExt.tree.WMSCapabilitiesLoader({
            url: "WMSServer.xml",
            layerOptions: {buffer: 0, singleTile: true, ratio: 1},
            layerParams: {'TRANSPARENT': 'TRUE'},
            // customize the createNode method to add a checkbox to nodes
            createNode: function(attr) {
                attr.checked = attr.leaf ? false : undefined;
                return GeoExt.tree.WMSCapabilitiesLoader.prototype.createNode.apply(this, [attr]);
            }
        })
    });

    var wms_child1 = new Ext.tree.AsyncTreeNode({
        text: 'GeoServer Demo WMS',
        loader: new GeoExt.tree.WMSCapabilitiesLoader({
            url: "WMSServer_USGSTopo.xml",
            layerOptions: {buffer: 0, singleTile: true, ratio: 1},
            layerParams: {'TRANSPARENT': 'TRUE'},
            // customize the createNode method to add a checkbox to nodes
            createNode: function(attr) {
                attr.checked = attr.leaf ? false : undefined;
                return GeoExt.tree.WMSCapabilitiesLoader.prototype.createNode.apply(this, [attr]);
            }
        })
    });

    // TreePanel root node, which will contains the future nodes (keywords  
    //folders, and layers inside these folders)
var root = new Ext.tree.TreeNode({
         expanded: true, // allow children autoload, and thus layers  autoload
         text: 'Texttexttexttexttext'
});

root.appendChild(wms_child); //add the WMS child
root.appendChild(wms_child1); //add the WFS child

    tree = new Ext.tree.TreePanel({
        region: 'west',
        width: 250,
        rootVisible: false, //hide the root node, but not its children
        root: root,
        listeners: {
            // Add layers to the map when ckecked, remove when unchecked.
            // Note that this does not take care of maintaining the layer
            // order on the map.
            'checkchange': function(node, checked) { 
                if (checked === true) {
                    mapPanel.map.addLayer(node.attributes.layer); 
                } else {
                    mapPanel.map.removeLayer(node.attributes.layer);
                }
            }
        }
    });

    mapPanel = new GeoExt.MapPanel({
        zoom: 2,
        layers: [
        new OpenLayers.Layer.WMS(
                "Medford",
                "http://services.nationalmap.gov/ArcGIS/services/transportation/MapServer/WMSServer",
                {layers: '6'},
                {isBaseLayer: false}
            )
        ],
        region: 'center'
    });

    new Ext.Viewport({
        layout: "fit",
        hideBorders: true,
        items: {
            layout: "border",
            deferredRender: false,
            items: [mapPanel, tree, {
                contentEl: "desc",
                region: "east",
                bodyStyle: {"padding": "5px"},
                collapsible: true,
                collapseMode: "mini",
                split: true,
                width: 200,
                title: "Description"
            }]
        }
    });

});