source:
trunk/workshop-routing-foss4g/web/GeoExt/examples/tree-legend.js
@
78
Revision 76, 3.5 KB checked in by djay, 13 years ago (diff) | |
---|---|
|
Line | |
---|---|
1 | /** |
2 | * Copyright (c) 2008-2009 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[tree-legend] |
10 | * Tree Legend |
11 | * ----------- |
12 | * Render layer nodes with legends. |
13 | */ |
14 | |
15 | // custom layer node UI class |
16 | var LayerNodeUI = Ext.extend( |
17 | GeoExt.tree.LayerNodeUI, |
18 | new GeoExt.tree.TreeNodeUIEventMixin() |
19 | ); |
20 | |
21 | Ext.onReady(function() { |
22 | var mapPanel = new GeoExt.MapPanel({ |
23 | region: "center", |
24 | center: [146.1569825, -41.6109735], |
25 | zoom: 6, |
26 | layers: [ |
27 | new OpenLayers.Layer.WMS("Tasmania State Boundaries", |
28 | "http://demo.opengeo.org/geoserver/wms", { |
29 | layers: "topp:tasmania_state_boundaries" |
30 | }, { |
31 | buffer: 0, |
32 | // exclude this layer from layer container nodes |
33 | displayInLayerSwitcher: false |
34 | }), |
35 | new OpenLayers.Layer.WMS("Water", |
36 | "http://demo.opengeo.org/geoserver/wms", { |
37 | layers: "topp:tasmania_water_bodies", |
38 | transparent: true, |
39 | format: "image/gif" |
40 | }, { |
41 | buffer: 0 |
42 | }), |
43 | new OpenLayers.Layer.WMS("Cities", |
44 | "http://demo.opengeo.org/geoserver/wms", { |
45 | layers: "topp:tasmania_cities", |
46 | transparent: true, |
47 | format: "image/gif" |
48 | }, { |
49 | buffer: 0 |
50 | }), |
51 | new OpenLayers.Layer.WMS("Tasmania Roads", |
52 | "http://demo.opengeo.org/geoserver/wms", { |
53 | layers: "topp:tasmania_roads", |
54 | transparent: true, |
55 | format: "image/gif" |
56 | }, { |
57 | buffer: 0 |
58 | }) |
59 | ] |
60 | }); |
61 | |
62 | var tree = new Ext.tree.TreePanel({ |
63 | region: "east", |
64 | title: "Layers", |
65 | width: 250, |
66 | autoScroll: true, |
67 | enableDD: true, |
68 | // apply the tree node component plugin to layer nodes |
69 | plugins: [{ |
70 | ptype: "gx_treenodecomponent" |
71 | }], |
72 | loader: { |
73 | applyLoader: false, |
74 | uiProviders: { |
75 | "custom_ui": LayerNodeUI |
76 | } |
77 | }, |
78 | root: { |
79 | nodeType: "gx_layercontainer", |
80 | loader: { |
81 | baseAttrs: { |
82 | uiProvider: "custom_ui" |
83 | }, |
84 | createNode: function(attr) { |
85 | // add a WMS legend to each node created |
86 | attr.component = { |
87 | xtype: "gx_wmslegend", |
88 | layerRecord: mapPanel.layers.getByLayer(attr.layer), |
89 | showTitle: false, |
90 | // custom class for css positioning |
91 | // see tree-legend.html |
92 | cls: "legend" |
93 | } |
94 | return GeoExt.tree.LayerLoader.prototype.createNode.call(this, attr); |
95 | } |
96 | } |
97 | }, |
98 | rootVisible: false, |
99 | lines: false |
100 | }); |
101 | |
102 | new Ext.Viewport({ |
103 | layout: "fit", |
104 | hideBorders: true, |
105 | items: { |
106 | layout: "border", |
107 | items: [ |
108 | mapPanel, tree, { |
109 | contentEl: desc, |
110 | region: "west", |
111 | width: 250, |
112 | bodyStyle: {padding: "5px"} |
113 | } |
114 | ] |
115 | } |
116 | }); |
117 | }); |
Note: See TracBrowser
for help on using the repository browser.