Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. // create a new WMS capabilities store
  2. store = new GeoExt.data.WMSCapabilitiesStore({
  3. url: "data/agar.xml",
  4. autoLoad: true
  5. });
  6.  
  7. // load the store with records derived from the doc at the above url
  8. store.load();
  9.  
  10. // create a grid to display records from the store
  11. var grid = new Ext.grid.GridPanel({
  12. title: "WMS Capabilities",
  13.  
  14. autoHeight: true,
  15. hideBorders: false,
  16. border: true,
  17. frame: true,
  18. columnLines: true,
  19. draggable: true,
  20.  
  21. collapseMode: "mini",
  22. allowDrag: true,
  23.  
  24. allowDrop: true,
  25.  
  26. viewConfig: {
  27. scrollOffset: 0},
  28.  
  29.  
  30. autoScroll: true,
  31. xtype: "gx_mappanel",
  32. store: store,
  33. cm: new Ext.grid.ColumnModel([
  34. {header: "Name", dataIndex: "name", sortable: true},
  35. {id: "title", header: "Title", dataIndex: "title", sortable: true}
  36. ]),
  37. sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
  38. autoExpandColumn: "title",
  39. renderTo: "capgrid",
  40. height: 300,
  41. width: 350,
  42. floating: true,
  43.  
  44. x: 900,
  45. y: 100,
  46.  
  47. bbar: ["->", {
  48. text: "Add Layer",
  49. handler: function() {
  50. var record = grid.getSelectionModel().getSelected();
  51. if(record) {
  52. var copy = record.copy();
  53. // Ext 3.X does not allow circular references in objects passed
  54. // to record.set
  55. copy.data["layer"] = record.getLayer();
  56. copy.getLayer().mergeNewParams({
  57. format: "image/png",
  58. transparent: "true"
  59. });
  60. mapPanel.layers.add(copy);
  61. mapPanel.map.zoomToExtent(extent
  62. //OpenLayers.Bounds.fromArray(copy.get("llbbox"))
  63. );
  64. }
  65. }
  66. }
  67. /* , {
  68. text: "Cancel",
  69. handler: function() {
  70. grid.hide();
  71. }
  72. } */
  73. ]
  74. });
  75.  
  76.  
  77. // create a map panel with some layers that we will show in our layer tree
  78. // below.
  79. mapPanel = new GeoExt.MapPanel({
  80. border: true,
  81. region: "center",
  82. // we do not want all overlays, to try the OverlayLayerContainer
  83. map: new OpenLayers.Map({allOverlays: false, maxExtent: extent}),
  84. center: [8508188, 2578129],
  85. zoom: 6,
  86.  
  87. layers: [
  88. new OpenLayers.Layer.Google("Google") ,
  89. new OpenLayers.Layer.OSM("OSM") ,
  90. new OpenLayers.Layer.Bing({
  91. name: "Bing",
  92. type: "Road",
  93. key: "AjtUzWJBHlI3Ma_Ke6Qv2fGRXEs0ua5hUQi54ECwfXTiWsitll4AkETZDihjcfeI",
  94.  
  95. {
  96. isBaseLayer: false,
  97.  
  98. buffer: 0,
  99. // exclude this layer from layer container nodes
  100. displayInLayerSwitcher: false,
  101. visibility: false
  102. }
  103. )
  104.  
  105.  
  106.  
  107.  
  108. // create a group layer (with several layers in the "layers" param)
  109. // to show how the LayerParamLoader works
  110.  
  111. ]
  112. });
  113.  
  114.  
  115.  
  116.  
  117. // create our own layer node UI class, using the TreeNodeUIEventMixin
  118. var LayerNodeUI = Ext.extend(GeoExt.tree.LayerNodeUI, new GeoExt.tree.TreeNodeUIEventMixin());
  119.  
  120. // using OpenLayers.Format.JSON to create a nice formatted string of the
  121. // configuration for editing it in the UI
  122. var treeConfig = [{
  123. nodeType: "gx_baselayercontainer"
  124. }, {
  125. nodeType: "gx_overlaylayercontainer",
  126. expanded: true,
  127. // render the nodes inside this container with a radio button,
  128. // and assign them the group "foo".
  129. loader: {
  130. baseAttrs: {
  131. radioGroup: "foo",
  132. uiProvider: "layernodeui"
  133. }
  134. }
  135. }, {
  136. nodeType: "gx_layer",
  137. layer: name + " "+"Layers",
  138. isLeaf: false,
  139. // create subnodes for the layers in the LAYERS param. If we assign
  140. // a loader to a LayerNode and do not provide a loader class, a
  141. // LayerParamLoader will be assumed.
  142. loader: {
  143. param: "LAYERS"
  144. }
  145. }];
  146. // The line below is only needed for this example, because we want to allow
  147. // interactive modifications of the tree configuration using the
  148. // "Show/Edit Tree Config" button. Don't use this line in your code.
  149. treeConfig = new OpenLayers.Format.JSON().write(treeConfig, true);
  150.  
  151. // create the tree with the configuration from above
  152. tree = new Ext.tree.TreePanel({
  153. border: true,
  154. region: "west",
  155. title: "Layers",
  156. width: 200,
  157. split: true,
  158.  
  159. collapsible: true,
  160. collapseMode: "mini",
  161. autoScroll: true,
  162. /* plugins: [
  163. new GeoExt.plugins.TreeNodeRadioButton({
  164. listeners: {
  165. "radiochange": function(node) {
  166. alert(node.text + " is now the active layer.");
  167. }
  168. }
  169. })
  170. ], */
  171. loader: new Ext.tree.TreeLoader({
  172. // applyLoader has to be set to false to not interfer with loaders
  173. // of nodes further down the tree hierarchy
  174. applyLoader: false,
  175. uiProviders: {
  176. "layernodeui": LayerNodeUI
  177. }
  178. }),
  179. root: {
  180. nodeType: "async",
  181. layerStore: mapPanel.layers,
  182. // the children property of an Ext.tree.AsyncTreeNode is used to
  183. // provide an initial set of layer nodes. We use the treeConfig
  184. // from above, that we created with OpenLayers.Format.JSON.write.
  185. children: Ext.decode(treeConfig)
  186. // Don't use the line above in your application. Instead, use
  187. //children: treeConfig
  188.  
  189. },
  190. listeners: {
  191. "radiochange": function(node){
  192. alert(node.layer.name + " is now the the active layer.");
  193. }
  194. },
  195. rootVisible: false,
  196. lines: false,
  197.  
  198.  
  199. });
  200.  
  201. // register a listener for the getfeatureinfo event on the control
  202. control.events.on({
  203. getfeatureinfo: function(event) {
  204. //close existing popup
  205. if (popup) {
  206. popup.destroy();
  207. }
  208. popup = new GeoExt.Popup({
  209. title: "Feature Info",
  210. map: mapPanel.map,
  211. lonlat: mapPanel.map.getLonLatFromPixel(event.xy),
  212. width: 250,
  213. height: 250,
  214. autoScroll: true,
  215. collapsible: true,
  216. bodyStyle: {padding: 5},
  217. //html: event.text
  218. html: e.featureInfo.attributes.LAT
  219. });
  220. popup.show();
  221. }
  222. });
  223.  
  224. mapPanel.map.addControl(control);
  225. control.activate();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement