source:
trunk/workshop-routing-foss4g/web/GeoExt/examples/layercontainer.js
@
77
Revision 76, 2.5 KB checked in by djay, 13 years ago (diff) | |
---|---|
|
Line | |
---|---|
1 | /** |
2 | * Copyright (c) 2008-2010 The Open Source Geospatial Foundation |
3 | * |
4 | * Published under the BSD license. |
5 | * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text |
6 | * of the license. |
7 | */ |
8 | |
9 | /** api: example[layercontainer] |
10 | * Layer Tree |
11 | * ---------- |
12 | * Create a layer tree with a LayerContainer. |
13 | */ |
14 | |
15 | var store, tree, panel; |
16 | Ext.onReady(function() { |
17 | |
18 | // create a new WMS capabilities store |
19 | store = new GeoExt.data.WMSCapabilitiesStore({ |
20 | url: "data/wmscap.xml" |
21 | }); |
22 | // load the store with records derived from the doc at the above url |
23 | store.load(); |
24 | |
25 | // create a grid to display records from the store |
26 | var grid = new Ext.grid.GridPanel({ |
27 | title: "WMS Capabilities", |
28 | store: store, |
29 | cm: new Ext.grid.ColumnModel([ |
30 | {header: "Name", dataIndex: "name", sortable: true}, |
31 | {id: "title", header: "Title", dataIndex: "title", sortable: true} |
32 | ]), |
33 | sm: new Ext.grid.RowSelectionModel({singleSelect:true}), |
34 | autoExpandColumn: "title", |
35 | renderTo: "capgrid", |
36 | height: 300, |
37 | width: 350, |
38 | floating: true, |
39 | x: 10, |
40 | y: 0, |
41 | bbar: ["->", { |
42 | text: "Add Layer", |
43 | handler: function() { |
44 | var record = grid.getSelectionModel().getSelected(); |
45 | if(record) { |
46 | var copy = record.copy(); |
47 | // Ext 3.X does not allow circular references in objects passed |
48 | // to record.set |
49 | copy.data["layer"] = record.getLayer(); |
50 | copy.getLayer().mergeNewParams({ |
51 | format: "image/png", |
52 | transparent: "true" |
53 | }); |
54 | panel.layers.add(copy); |
55 | panel.map.zoomToExtent( |
56 | OpenLayers.Bounds.fromArray(copy.get("llbbox")) |
57 | ); |
58 | } |
59 | } |
60 | }] |
61 | }); |
62 | |
63 | // create a map panel |
64 | panel = new GeoExt.MapPanel({ |
65 | renderTo: "mappanel", |
66 | width: 350, |
67 | height: 300, |
68 | floating: true, |
69 | x: 570, |
70 | y: 0 |
71 | }); |
72 | |
73 | tree = new Ext.tree.TreePanel({ |
74 | renderTo: "tree", |
75 | root: new GeoExt.tree.LayerContainer({ |
76 | text: 'Map Layers', |
77 | layerStore: panel.layers, |
78 | leaf: false, |
79 | expanded: true |
80 | }), |
81 | enableDD: true, |
82 | width: 170, |
83 | height: 300, |
84 | floating: true, |
85 | x: 380, |
86 | y: 0 |
87 | }); |
88 | |
89 | |
90 | }); |
Note: See TracBrowser
for help on using the repository browser.