PDA

View Full Version : how to add more than one service to Ext.tree.TreePanel



D. Roger Brown
18 Nov 2013, 10:49 AM
I am trying to add multiple services to the Ext.tree.TreePanel. I have a working example of the treePanel with one service that works great. How can multiple url services be added to the same TreePanel?

Thanks
Roger

D. Roger Brown
20 Nov 2013, 8:09 AM
I found the following which helped a great deal:
http://www.geoext.org/pipermail/users/2011-July/002397.html
Ended up with the following code that supports more than one service:
Also note original code was from 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"
}]
}
});

});