PageRenderTime 1124ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/tree-actions.js

https://github.com/alediator/geoext
JavaScript | 156 lines | 130 code | 7 blank | 19 comment | 6 complexity | 3bc860c0e03246a87536dd53e81b14cd MD5 | raw file
Possible License(s): BSD-3-Clause
  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. Ext.namespace("GeoExt.examples");
  9. // this function takes action based on the "action"
  10. // parameter, it is used as a listener to layer
  11. // nodes' "action" events
  12. GeoExt.examples.onAction = function(node, action, evt) {
  13. var layer = node.layer;
  14. switch(action) {
  15. case "down":
  16. layer.map.raiseLayer(layer, -1);
  17. break;
  18. case "up":
  19. layer.map.raiseLayer(layer, +1);
  20. break;
  21. case "delete":
  22. layer.destroy();
  23. break;
  24. }
  25. };
  26. // custom layer node UI class
  27. GeoExt.examples.LayerNodeUI = Ext.extend(
  28. GeoExt.tree.LayerNodeUI,
  29. new GeoExt.tree.TreeNodeUIEventMixin()
  30. );
  31. Ext.onReady(function() {
  32. Ext.QuickTips.init();
  33. // the map panel
  34. var mapPanel = new GeoExt.MapPanel({
  35. border: true,
  36. region: "center",
  37. center: [146.1569825, -41.6109735],
  38. zoom: 6,
  39. layers: [
  40. new OpenLayers.Layer.WMS("Tasmania State Boundaries",
  41. "http://demo.opengeo.org/geoserver/wms", {
  42. layers: "topp:tasmania_state_boundaries"
  43. }, {
  44. buffer: 0,
  45. // exclude this layer from layer container nodes
  46. displayInLayerSwitcher: false
  47. }),
  48. new OpenLayers.Layer.WMS("Water",
  49. "http://demo.opengeo.org/geoserver/wms", {
  50. layers: "topp:tasmania_water_bodies",
  51. transparent: true,
  52. format: "image/gif"
  53. }, {
  54. buffer: 0
  55. }),
  56. new OpenLayers.Layer.WMS("Cities",
  57. "http://demo.opengeo.org/geoserver/wms", {
  58. layers: "topp:tasmania_cities",
  59. transparent: true,
  60. format: "image/gif"
  61. }, {
  62. buffer: 0
  63. }),
  64. new OpenLayers.Layer.WMS("Tasmania Roads",
  65. "http://demo.opengeo.org/geoserver/wms", {
  66. layers: "topp:tasmania_roads",
  67. transparent: true,
  68. format: "image/gif"
  69. }, {
  70. buffer: 0
  71. })
  72. ]
  73. });
  74. // the layer tree panel. In this tree the node actions are set using
  75. // the loader's "baseAttrs" property.
  76. var tree = new Ext.tree.TreePanel({
  77. region: "west",
  78. width: 250,
  79. title: "Layer Tree",
  80. loader: {
  81. applyLoader: false,
  82. uiProviders: {
  83. "ui": GeoExt.examples.LayerNodeUI
  84. }
  85. },
  86. // apply the tree node actions plugin to layer nodes
  87. plugins: [{
  88. ptype: "gx_treenodeactions",
  89. listeners: {
  90. action: GeoExt.examples.onAction
  91. }
  92. }],
  93. root: {
  94. nodeType: "gx_layercontainer",
  95. loader: {
  96. baseAttrs: {
  97. radioGroup: "radiogroup",
  98. uiProvider: "ui",
  99. actions: [{
  100. action: "delete",
  101. qtip: "delete"
  102. }, {
  103. action: "up",
  104. qtip: "move up",
  105. update: function(el) {
  106. // "this" references the tree node
  107. var layer = this.layer, map = layer.map;
  108. if (map.getLayerIndex(layer) == map.layers.length - 1) {
  109. el.addClass('disabled');
  110. } else {
  111. el.removeClass('disabled');
  112. }
  113. }
  114. }, {
  115. action: "down",
  116. qtip: "move down",
  117. update: function(el) {
  118. // "this" references the tree node
  119. var layer = this.layer, map = layer.map;
  120. if (map.getLayerIndex(layer) == 1) {
  121. el.addClass('disabled');
  122. } else {
  123. el.removeClass('disabled');
  124. }
  125. }
  126. }]
  127. }
  128. }
  129. },
  130. rootVisible: false,
  131. lines: false
  132. });
  133. // the viewport
  134. new Ext.Viewport({
  135. layout: "fit",
  136. hideBorders: true,
  137. items: {
  138. layout: "border",
  139. deferredRender: false,
  140. items: [
  141. mapPanel,
  142. tree, {
  143. region: "east",
  144. contentEl: "desc",
  145. width: 250
  146. }]
  147. }
  148. });
  149. });