Advertisement
Guest User

Untitled

a guest
Jul 26th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 7.90 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title> WEBSIG</title>
  5.         <script src="OpenLayers-2.9.1/lib/Firebug/firebug.js"></script>
  6.         <script src="Ext-3.2.1/adapter/ext/ext-base.js" type="text/javascript"></script>
  7.         <script src="Ext-3.2.1/ext-all.js"  type="text/javascript"></script>
  8.         <link rel="stylesheet" type="text/css" href="Ext-3.2.1/resources/css/ext-all.css" />
  9.         <script src="http://openlayers.org/api/OpenLayers.js" type="text/javascript"></script>
  10.         <script src="GeoExt/lib/GeoExt.js" type="text/javascript"></script>
  11.         <link rel="stylesheet" type="text/css" href="GeoExt/resources/css/geoext-all-debug.css"/>
  12.         <script src="DrawPoints.js" type="text/javascript"></script>
  13.         <script src="proj4js-1.0.1/lib/proj4js.js" type="text/javascript"></script>
  14.         <script type="text/javascript">
  15.  
  16.  
  17.     </script>
  18.     </head>
  19.     <body>
  20.         <div id="map-id"></div>
  21.         <script type="text/javascript">
  22.        
  23.                
  24.      // declara projecção usada
  25.      var epsg_900913 = new OpenLayers.Projection("EPSG:900913");
  26.      
  27.    
  28.    
  29.         //função pgrouting
  30.          function pgrouting(store, layer, method) {
  31.          if (layer.features.length == 2) {
  32.          
  33.              // apagar rota anterior
  34.              store.removeAll();
  35.    
  36.             //criar ponto de partida
  37.             var startpoint = layer.features[0].geometry.clone();
  38.            
  39.        
  40.              
  41.              //criar ponto de destino
  42.              var finalpoint = layer.features[1].geometry.clone();
  43.            
  44.            
  45.            
  46.              // carregar a rota
  47.              store.load({
  48.                  params: {
  49.                      startpoint: startpoint.x + " " + startpoint.y,
  50.                      finalpoint: finalpoint.x + " " + finalpoint.y,
  51.                      method: method}  });
  52.  
  53.  
  54.          }}
  55.    
  56.    
  57.    
  58.    
  59.     //extend do mapa
  60.    
  61.     var extend = new OpenLayers.Bounds (-788843.31, 4977768.00,-785094.75, 4980008.00);
  62.    
  63.    
  64.  
  65.            
  66.            
  67.            
  68.     //opções do mapa     
  69.     var opcoes = {maxExtent: extend,restrictExtent: extend, units: 'm',projection: epsg_900913,};
  70.    
  71.    
  72.    
  73.      Ext.onReady(function() {
  74.        
  75.        
  76.         // criar o mapa
  77.        
  78.         var map = new OpenLayers.Map("map-id",opcoes);
  79.        
  80.        
  81.        
  82.        //criar mappanel
  83.         var mapPanel = new GeoExt.MapPanel({
  84.         renderTo: 'map-id',
  85.         height: 560,
  86.         width: 840,
  87.         map: map
  88.        
  89.         });
  90.        
  91.        
  92.      
  93.  
  94.      
  95.          
  96.        //criar e adicionar camadas base
  97.        
  98.         var aerial = new OpenLayers.Layer.Bing({
  99.         key: "AqTGBsziZHIJYYxgivLBf0hVdrAk9mWO5cQcb8Yux8sW5M8c8opEC2lZqKR1ZZXf",
  100.         type: "Aerial"
  101.         });
  102.         map.addLayer(aerial);
  103.        
  104.         var bing = new OpenLayers.Layer.Bing({
  105.         key: "AqTGBsziZHIJYYxgivLBf0hVdrAk9mWO5cQcb8Yux8sW5M8c8opEC2lZqKR1ZZXf",
  106.         type: "Road",
  107.         });
  108.         map.addLayer(bing);
  109.  
  110.         var osm = new OpenLayers.Layer.OSM();
  111.         map.addLayer(osm);
  112.        
  113.        
  114.        
  115.        
  116.        
  117.         // var tree = new Ext.tree.TreePanel({
  118.         // renderTo: "coluna",
  119.             // root: new GeoExt.tree.LayerContainer({
  120.             // text: 'Níveis de informação',
  121.             // leaf: false,
  122.             // expanded: true
  123.             // }),
  124.             // enableDD: true,
  125.             // width: 230,
  126.             // height: 560,
  127.             // floating: true,
  128.             // x: 841,
  129.             // y: 0
  130.             // });
  131.        
  132.        
  133.        
  134.        
  135.        //criar e adicionar arcos       
  136.     var arcos = new OpenLayers.Layer.WMS(
  137.         'Arcos',
  138.        'http://localhost:8080/geoserver/base/wms',
  139.         {layers: 'base:arcos',
  140.         styles: 'line',
  141.        srs: 'EPSG:900913',
  142.        format: 'image/png',
  143.        transparent: true},
  144.     {isBaseLayer: false});
  145.         map.addLayer(arcos);
  146.          
  147.          
  148.          
  149.        
  150.        
  151.         //criar e adicionar equipamentos
  152.         //var equipamentos = new OpenLayers.Layer.WMS(
  153.         //'Equipamentos',
  154.         //'http://localhost:8080/geoserver/base/wms',
  155.         //{layers: 'base:equipamentos',
  156.         //styles: 'polygon',
  157.         //srs: 'EPSG:900913',
  158.         //format: 'image/png',
  159.         //transparent: true
  160.         //},{isBaseLayer: false});
  161.            
  162.         //map.addLayer(equipamentos);
  163.        
  164.        
  165.            
  166.        //criar layer que vai receber a rota
  167.     var route_layer = new OpenLayers.Layer.Vector("rota", {
  168.         projection: epsg_900913,
  169.     styleMap: new OpenLayers.StyleMap(new OpenLayers.Style({
  170.         strokeColor: "#ff9933",
  171.         strokeWidth: 3
  172.          
  173.         }))})
  174.        
  175.  
  176.        
  177.         //layer que vai receber os rebaixamentos da rota
  178.        
  179.         var points_rota = new OpenLayers.Layer.Vector("rebaixamentos", {
  180.         projection: epsg_900913,
  181.     styleMap: new OpenLayers.StyleMap(new OpenLayers.Style({
  182.         strokeColor: "#ff9933",
  183.         strokeWidth: 3
  184.          
  185.         }))})
  186.        
  187.        
  188.        
  189.        
  190.        
  191.        
  192.        
  193.        
  194.  
  195.         // criar os pontos onde vão ser desenhados o início e fim do percurso
  196.         var points_layer = new OpenLayers.Layer.Vector("points");
  197.  
  198.        
  199.        
  200.        
  201.        
  202.         // quando um ponto é adicionado chamar a função pgrouting
  203.         points_layer.events.on({
  204.             featureadded: function() {
  205.                 pgrouting(store, points_layer, method.getValue());
  206.             }   });
  207.            
  208.            
  209.  
  210.         // adicionar os pontos e o percurso
  211.         map.addLayers([points_layer, route_layer, points_rota]);
  212.        
  213.        
  214.  
  215.         // criar os controlos para desenhar os pontos de início e fim(DrawPoints.js)
  216.         var draw_points = new DrawPoints(points_layer);
  217.        
  218.        
  219.            
  220.         // criar o controlo para mover os pontos
  221.         var drag_points = new OpenLayers.Control.DragFeature(points_layer, {
  222.             autoActivate: true
  223.         });
  224.  
  225.        
  226.        
  227.         //criar controlo para mudar as camadas
  228.        
  229.         var mudar_camadas = new OpenLayers.Control.LayerSwitcher();
  230.        
  231.         //displayInLayerSwitcher: false;
  232.        
  233.        
  234.         // Chamar a função pgrouting quando os pontos são movidos
  235.         drag_points.onComplete = function() {
  236.               pgrouting(store, points_layer, method.getValue());
  237.         };
  238.  
  239.        
  240.        
  241.         // adicionar os controlos ao mapa
  242.         map.addControls([draw_points, drag_points, mudar_camadas]);
  243.        
  244.        
  245.        
  246.        
  247.        
  248.         // create the store to query the web service
  249.         var store = new GeoExt.data.FeatureStore({layer: route_layer, fields: [{name: "id"}],
  250.             proxy: new GeoExt.data.ProtocolProxy({
  251.             protocol: new OpenLayers.Protocol.HTTP({
  252.             url: "./php/phpfile.php",
  253.             format: new OpenLayers.Format.GeoJSON({
  254.             internalProjection: epsg_900913,
  255.             externalProjection: epsg_900913
  256.                  
  257.  
  258.                 })})})});
  259.                
  260.                
  261.                
  262.                
  263.              // create the store to query the web service - rebaixamentos
  264.         var store2 = new GeoExt.data.FeatureStore({layer: points_rota, fields: [{name: "id"}],
  265.             proxy: new GeoExt.data.ProtocolProxy({
  266.             protocol: new OpenLayers.Protocol.HTTP({
  267.             url: "./php/phpfile.php",
  268.             format: new OpenLayers.Format.GeoJSON({
  269.             internalProjection: epsg_900913,
  270.             externalProjection: epsg_900913
  271.                  
  272.  
  273.                 })})})});      
  274.                
  275.                
  276.                
  277.                
  278.  
  279.    
  280.        
  281.        
  282.  
  283.         // zoom à bounding box
  284.         map.zoomToExtent(extend);
  285.    
  286.    
  287.    
  288.         //definir a área máxima visível
  289.         map.events.register('zoomend', map, function(){
  290.         var mapProj = map.getProjection();
  291.         var mapZoom = map.getZoom();
  292.         var mapRes = map.getResolutionForZoom(mapZoom);
  293.         if (mapProj == 'EPSG:900913' && mapRes > 4.777314267158508){
  294.         map.zoomToExtent(extend);
  295.         }
  296.         });
  297.    
  298.    
  299.    
  300.     // create the method combo box
  301.         var method = new Ext.form.ComboBox({
  302.            renderTo: "method",
  303.            triggerAction: "all",
  304.            editable: false,
  305.            forceSelection: true,
  306.            store: [
  307.                ["SP1", "Rod"],
  308.             ["SP2", "Sén"],
  309.         ["SP3", "Ad"]
  310.                
  311.          ],
  312.          listeners: {
  313.           select: function() {
  314.            pgrouting(store, points_layer, method.getValue());
  315.           }
  316.          }
  317.         });
  318.    
  319.    
  320.    
  321.    
  322.    
  323.        
  324.    
  325.    
  326.    
  327.    
  328.         // método predefinido
  329.         method.setValue("SP1");
  330.    
  331.    
  332.    
  333.    
  334.     });
  335.    
  336.    
  337.             </script>
  338.            
  339.             <div id="method"></div>    
  340.     </body>
  341. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement