Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. Ext.namespace("GeoExt.examples");
  10.  
  11. // this function takes action based on the "action"
  12. // parameter, it is used as a listener to layer
  13. // nodes' "action" events
  14. GeoExt.examples.onAction = function(node, action, evt) {
  15.      
  16.     var layer = node.layer;
  17.     switch(action) {
  18.     case "down":
  19.         layer.map.raiseLayer(layer, -1);
  20.         break;
  21.     case "up":
  22.         layer.map.raiseLayer(layer, +1);
  23.         break;
  24.     case "delete":
  25.         layer.destroy();
  26.         break;
  27.     }
  28. };
  29.  
  30. // custom layer node UI class
  31. GeoExt.examples.LayerNodeUI = Ext.extend(
  32.     GeoExt.tree.LayerNodeUI,
  33.     new GeoExt.tree.TreeNodeUIEventMixin()
  34. );
  35.  
  36.    
  37. Ext.onReady(function() {
  38.     Ext.QuickTips.init();
  39.  
  40.     // the map panel
  41.    
  42.     var info;
  43.     var map = new OpenLayers.Map("map-id");
  44. maxExtent: new OpenLayers.Bounds(143.834,-43.648,148.479,-39.573)
  45.     var apiKey = "api";
  46.    
  47.     var mapPanel = new GeoExt.MapPanel({
  48.         border: true,
  49.         region: "center",
  50.         center: [1173892.7542969, 5870273.7714844],
  51.         zoom: 3,
  52.         layers: [
  53.             new OpenLayers.Layer.OSM(),
  54.  
  55.             new OpenLayers.Layer.Vector("Highlighted Features", {
  56.             displayInLayerSwitcher: false,
  57.             isBaseLayer: false
  58.         }),
  59.  
  60.             //
  61.             new OpenLayers.Layer.WMS("WMS Test polygon",
  62.                 "http://localhost:8080/geoserver/wms", {
  63.                     layers: "prova:poligoni",
  64.                     transparent: true,
  65.                 }, {
  66.                      isBaseLayer: false
  67.                      ,displayOutsideMaxExtent: true
  68.  
  69.                }),
  70.             new OpenLayers.Layer.WMS("WMS Test point",
  71.                 "http://localhost:8080/geoserver/wms", {
  72.                     layers: "prova:punti",
  73.                     transparent: true,
  74.                     format: "image/gif"
  75.                 }, {
  76.                      isBaseLayer: false
  77.                      ,displayOutsideMaxExtent: true
  78.                 })            
  79.         ]
  80.     });
  81. // FEATURE POPUP
  82.     info = new OpenLayers.Control.WMSGetFeatureInfo({
  83.             url: 'http://localhost:8080/geoserver/wms',
  84.             title: 'Identify features by clicking',
  85.             queryVisible: true,
  86.             eventListeners: {
  87.                 getfeatureinfo: function(event) {
  88.                     map.addPopup(new OpenLayers.Popup.FramedCloud(
  89.                         "chicken",
  90.                         map.getLonLatFromPixel(event.xy),
  91.                         null,
  92.                         event.text,
  93.                         null,
  94.                         true
  95.                     ));
  96.                 }
  97.             }
  98.         });
  99.         map.addControl(info);
  100.         info.activate();
  101.        
  102.         //
  103.     // the layer tree panel. In this tree the node actions are set using
  104.     // the loader's "baseAttrs" property.
  105.     var tree = new Ext.tree.TreePanel({
  106.         region: "west",
  107.         width: 250,
  108.         title: "Layer Tree",
  109.         loader: {
  110.             applyLoader: false,
  111.             uiProviders: {
  112.                 "ui": GeoExt.examples.LayerNodeUI
  113.             }
  114.         },
  115.         // apply the tree node actions plugin to layer nodes
  116.         plugins: [{
  117.             ptype: "gx_treenodeactions",
  118.             listeners: {
  119.                 action: GeoExt.examples.onAction
  120.             }
  121.         }],
  122.         root: {
  123.             nodeType: "gx_layercontainer",
  124.             loader: {
  125.                 baseAttrs: {
  126.                     radioGroup: "radiogroup",
  127.                     uiProvider: "ui",
  128.                     actions: [{
  129.                         action: "delete",
  130.                         qtip: "delete"
  131.                     }, {
  132.                         action: "up",
  133.                         qtip: "move up",
  134.                         update: function(el) {
  135.                             // "this" references the tree node
  136.                             var layer = this.layer, map = layer.map;
  137.                             if (map.getLayerIndex(layer) == map.layers.length - 1) {
  138.                                 el.addClass('disabled');
  139.                             } else {
  140.                                 el.removeClass('disabled');
  141.                             }
  142.                         }
  143.                     }, {
  144.                         action: "down",
  145.                         qtip: "move down",
  146.                         update: function(el) {
  147.                             // "this" references the tree node
  148.                             var layer = this.layer, map = layer.map;
  149.                             if (map.getLayerIndex(layer) == 1) {
  150.                                 el.addClass('disabled');
  151.                             } else {
  152.                                 el.removeClass('disabled');
  153.                             }
  154.                         }
  155.                     }]
  156.                 }
  157.             }
  158.         },
  159.         rootVisible: false,
  160.         lines: false
  161.     });
  162.  
  163.     // the viewport
  164.     new Ext.Viewport({
  165.         layout: "fit",
  166.         hideBorders: true,
  167.         items: {
  168.             layout: "border",
  169.             deferredRender: false,
  170.             items: [
  171.                 mapPanel,
  172.                 tree, {
  173.                 region: "east",
  174.                 contentEl: "desc",
  175.                 width: 250
  176.             }]
  177.         }
  178.     });
  179. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement