Advertisement
Guest User

Untitled

a guest
Jul 10th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.15 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title>title</title>
  5.         <script src="Ext-3.2.1/adapter/ext/ext-base.js" type="text/javascript"></script>
  6.         <script src="Ext-3.2.1/ext-all.js"  type="text/javascript"></script>
  7.         <link rel="stylesheet" type="text/css" href="Ext-3.2.1/resources/css/ext-all.css" />
  8.        
  9.        
  10.         <script src="http://openlayers.org/api/OpenLayers.js" type="text/javascript"></script>
  11.         <script src="GeoExt/lib/GeoExt.js" type="text/javascript"></script>
  12.         <link rel="stylesheet" type="text/css" href="GeoExt/resources/css/geoext-all-debug.css"/>
  13.         <script src="DrawPoints.js" type="text/javascript"></script>
  14.         <script src="proj4js-1.0.1/lib/proj4js.js" type="text/javascript"></script>
  15.         <script type="text/javascript">
  16.  
  17.  
  18.     </script>
  19. </head>
  20.     <body>
  21.         <div id="map-id"></div>
  22.         <script type="text/javascript">
  23.  
  24.  
  25.  
  26.      // global projection objects (uses the proj4js lib)
  27.      var epsg_900913 = new OpenLayers.Projection("EPSG:900913");
  28.      var epsg_27492 = new OpenLayers.Projection("EPSG:27492");
  29.    
  30.    
  31.      function pgrouting(store, layer, method) {
  32.          if (layer.features.length == 2) {
  33.              // erase the previous route
  34.              store.removeAll();
  35.  
  36.            
  37.             var startpoint = layer.features[0].geometry.clone();
  38.              startpoint.transform(epsg_900913, epsg_27492);
  39.              
  40.              
  41.              
  42.              var finalpoint = layer.features[1].geometry.clone();
  43.              finalpoint.transform(epsg_900913, epsg_27492);
  44.            
  45.            
  46.  
  47.              // load to route
  48.              store.load({
  49.                  params: {
  50.                      startpoint: startpoint.x + " " + startpoint.y,
  51.                      finalpoint: finalpoint.x + " " + finalpoint.y,
  52.                      method: method
  53.                  }
  54.              });
  55.          }
  56.     }
  57.    
  58.    
  59.    
  60.    
  61.     //extend
  62.     var mercator = new OpenLayers.Projection("EPSG:900913");
  63.     var extend = new OpenLayers.Bounds(-789032.43216791,4977612.1650746,-784140.46235833,4980058.1499794);
  64.            
  65.            
  66.            
  67.     //opcoes do mapa       
  68.     var opcoes = {maxExtent: extend,restrictExtent: extend, units: 'm',projection: mercator,};
  69.    
  70.    
  71.    
  72.     Ext.onReady(function() {
  73.        
  74.        
  75.         // create the map panel
  76.        
  77.         var map = new OpenLayers.Map("map-id",opcoes);
  78.        
  79.         var osm = new OpenLayers.Layer.OSM();
  80.         map.addLayer(osm);
  81.        
  82.        
  83.        
  84.        
  85.         var mapPanel = new GeoExt.MapPanel({
  86.         renderTo: 'map-id',
  87.         height: 800,
  88.         width: 1200,
  89.         map: map,
  90.         title: 'title2'
  91.         });
  92.        
  93.        
  94.    
  95.        
  96.        
  97.        
  98.        
  99.         // create the layer where the route will be drawn
  100.         var route_layer = new OpenLayers.Layer.Vector("route", {
  101.             styleMap: new OpenLayers.StyleMap(new OpenLayers.Style({
  102.                 strokeColor: "#ff9933",
  103.                 strokeWidth: 3
  104.             }))
  105.         });
  106.  
  107.         // create the layer where the start and final points will be drawn
  108.         var points_layer = new OpenLayers.Layer.Vector("points");
  109.  
  110.         // when a new point is added to the layer, call the pgrouting function
  111.         points_layer.events.on({
  112.             featureadded: function() {
  113.                 pgrouting(store, points_layer, method.getValue());
  114.             }
  115.         });
  116.  
  117.         // add the layers to the map
  118.         map.addLayers([points_layer, route_layer]);
  119.  
  120.         // create the control to draw the points (see the DrawPoints.js file)
  121.         var draw_points = new DrawPoints(points_layer);
  122.  
  123.         // create the control to move the points
  124.         var drag_points = new OpenLayers.Control.DragFeature(points_layer, {
  125.             autoActivate: true
  126.         });
  127.  
  128.         // when a point is moved, call the pgrouting function
  129.         drag_points.onComplete = function() {
  130.               pgrouting(store, points_layer, method.getValue());
  131.         };
  132.  
  133.         // add the controls to the map
  134.         map.addControls([draw_points, drag_points]);
  135.  
  136.         // create the store to query the web service
  137.         var store = new GeoExt.data.FeatureStore({
  138.             layer: route_layer,
  139.             fields: [
  140.                 {name: "length"}
  141.             ],
  142.             proxy: new GeoExt.data.ProtocolProxy({
  143.                 protocol: new OpenLayers.Protocol.HTTP({
  144.                     url: "./php/pgrouting.php",
  145.                     format: new OpenLayers.Format.GeoJSON({
  146.                         internalProjection: epsg_900913,
  147.                         externalProjection: epsg_27492
  148.                     })
  149.                 })
  150.             })
  151.         });
  152.  
  153.    
  154.    
  155.         map.zoomToExtent(extend);
  156.    
  157.    
  158.    
  159.    
  160.    
  161.    
  162.     // create the method combo box
  163.         var method = new Ext.form.ComboBox({
  164.             renderTo: "method",
  165.             triggerAction: "all",
  166.             editable: false,
  167.             forceSelection: true,
  168.             store: [
  169.                 ["SP", "Shortest Path"]
  170.                
  171.             ],
  172.             listeners: {
  173.                 select: function() {
  174.                     pgrouting(store, points_layer, method.getValue());
  175.                 }
  176.             }
  177.         });
  178.    
  179.    
  180.    
  181.    
  182.         // default method is Shortest Path Dijkstra
  183.         method.setValue("SP");
  184.     });
  185.    
  186.    
  187.             </script>
  188.            
  189.             <div id="method"></div>
  190.     </body>
  191. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement