GeoEXT 1.1 WMS Trees

Use a WMS tree for each geoserver.

by spydmobile

HTML

<script src="http://extjs.cachefly.net/ext-3.4.0/adapter/ext/ext-base.js"></script>
<script src="http://extjs.cachefly.net/ext-3.4.0/ext-all.js"></script>
<link rel="stylesheet" href="http://extjs.cachefly.net/ext-3.4.0/resources/css/ext-all.css">
<link rel="stylesheet" href="http://extjs.cachefly.net/ext-3.4.0/examples/shared/examples.css">
<script src="http://www.openlayers.org/api/2.11/OpenLayers.js"></script>
<script src="http://api.geoext.org/1.1/script/GeoExt.js"></script>
  <div id="desc"> 
            <p>This example shows how to use GeoExt.tree.WMSCapabilitiesLoader to populate a tree
            with the hierarchical structure of a WMS GetCapabilities response. The example
            also shows how to customize the loader's <tt>createNode</tt> method to add a checkbox
            with a <tt>checkchange</tt> listener that adds and removes layers to and from the map.
            </p>
            <p>See <a href="wms-tree.js">wms-tree.js</a> for the source code.</p>
        </div>

JavaScript

/**
 * 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;

var proxyUrl = "http://www.sparcsonline.com/next/sparcsmap/getinfoall?t=smjs&url=";

var nwtGeoserver = encodeURIComponent('http://gs.vm.sparcsonline.com/geoserver/wms?request=getCapabilities&outputFormat=text/javascript');


var nrcanGeoserver = encodeURIComponent('http://maps.nofc.cfs.nrcan.gc.ca:80/geoserver/wms?request=getCapabilities');


Ext.onReady(function() {

    var root = new Ext.tree.TreeNode(
  {
  nodeType: 'async',
       text: 'External Servers WMS',
      id: 'root_node'
      }
    );

    var nwt = new Ext.tree.AsyncTreeNode({
        text: 'NWT Layers',
        id: 'nwt_node',
        loader: new GeoExt.tree.WMSCapabilitiesLoader({
            //url: 'data/wmscap.xml',
            url: proxyUrl + nwtGeoserver,
            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 nrcan = new Ext.tree.AsyncTreeNode({
        id: 'nrcan_node',
        text: 'NRCAN Layers',
        loader: new GeoExt.tree.WMSCapabilitiesLoader({
            //url: 'data/wmscap.xml',
            url: proxyUrl + nrcanGeoserver,
            layerOptions: {buffer: 0, singleTile: true, ratio: 1},
            layerParams: {'TRANSPARENT': 'TRUE'},
            // customize the createNode method to add a checkbox to nodes
            createNode:...