[Commits] r1637 - in sandbox/cmoullet/ux/RoutingPanel: examples tests/ux/widgets ux/widgets

commits at geoext.org commits at geoext.org
Thu Dec 31 06:46:32 CET 2009


Author: cmoullet
Date: 2009-12-31 06:46:32 +0100 (Thu, 31 Dec 2009)
New Revision: 1637

Modified:
   sandbox/cmoullet/ux/RoutingPanel/examples/RoutingPanelExample.html
   sandbox/cmoullet/ux/RoutingPanel/examples/RoutingPanelExample.js
   sandbox/cmoullet/ux/RoutingPanel/tests/ux/widgets/RoutingPanel.html
   sandbox/cmoullet/ux/RoutingPanel/ux/widgets/RoutingPanel.js
Log:
Add events, doc and unit tests

Modified: sandbox/cmoullet/ux/RoutingPanel/examples/RoutingPanelExample.html
===================================================================
--- sandbox/cmoullet/ux/RoutingPanel/examples/RoutingPanelExample.html	2009-12-30 06:54:55 UTC (rev 1636)
+++ sandbox/cmoullet/ux/RoutingPanel/examples/RoutingPanelExample.html	2009-12-31 05:46:32 UTC (rev 1637)
@@ -6,7 +6,8 @@
     <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/examples/shared/examples.css"/>
     <script type="text/javascript" src="http://openlayers.org/api/2.8/OpenLayers.js"></script>
     <script type="text/javascript" src="../../../trunk/geoext/lib/GeoExt.js"></script>
-    <script type="text/javascript" src="http://svn.geoext.org/ux/GeoNamesSearchCombo/ux/widgets/form/GeoNamesSearchCombo.js"></script>
+    <script type="text/javascript"
+            src="http://svn.geoext.org/ux/GeoNamesSearchCombo/ux/widgets/form/GeoNamesSearchCombo.js"></script>
     <script type="text/javascript" src="../ux/widgets/RoutingPanel.js"></script>
     <script type="text/javascript" src="RoutingPanelExample.js"></script>
 </head>

Modified: sandbox/cmoullet/ux/RoutingPanel/examples/RoutingPanelExample.js
===================================================================
--- sandbox/cmoullet/ux/RoutingPanel/examples/RoutingPanelExample.js	2009-12-30 06:54:55 UTC (rev 1636)
+++ sandbox/cmoullet/ux/RoutingPanel/examples/RoutingPanelExample.js	2009-12-31 05:46:32 UTC (rev 1637)
@@ -86,7 +86,15 @@
         // Key for dev.geoext.org: 187a9f341f70406a8064d07a30e5695c
         // Key for localhost: BC9A493B41014CAABB98F0471D759707
         cloudmadeKey: '187a9f341f70406a8064d07a30e5695c',
-        geocodingType: 'geonames'
+        geocodingType: 'geonames',
+        listeners:{
+            routingcomputed: function() {
+                //alert('Computation done');
+            },
+            beforeroutingcomputed: function() {
+                //alert('Before computation');
+            }
+        }
     };
     treePanel = Ext.getCmp("treepanel");
     treePanel.add(treePanelItem);

Modified: sandbox/cmoullet/ux/RoutingPanel/tests/ux/widgets/RoutingPanel.html
===================================================================
--- sandbox/cmoullet/ux/RoutingPanel/tests/ux/widgets/RoutingPanel.html	2009-12-30 06:54:55 UTC (rev 1636)
+++ sandbox/cmoullet/ux/RoutingPanel/tests/ux/widgets/RoutingPanel.html	2009-12-31 05:46:32 UTC (rev 1637)
@@ -11,17 +11,18 @@
     <script type="text/javascript" src="../../../ux/widgets/RoutingPanel.js"></script>
     <script type="text/javascript">
         function test_ctor(t) {
-            t.plan(3);
+            t.plan(5);
 
             var layer = new OpenLayers.Layer.OSM("OSM");
 
-            var map = new OpenLayers.Map();
+            var map = new OpenLayers.Map('map');
 
             var center = new OpenLayers.LonLat(738481, 5863900);
             map.addLayer(layer);
             map.setCenter(center, 14);
 
             var routingPanel = new GeoExt.ux.RoutingPanel({
+                renderTo: 'routingPanel',
                 map: map,
                 // Key for dev.geoext.org: 187a9f341f70406a8064d07a30e5695c
                 // Key for localhost: BC9A493B41014CAABB98F0471D759707
@@ -35,12 +36,16 @@
                     "ctor creates an Ext.Panel object");
 
             t.eq(map.getCenter().toString(), "lon=738481,lat=5863900", "map center set correctly");
+            t.eq(routingPanel.routingRecenterMap, true, "recenter on map is true per default");
+            t.ok(routingPanel.routingPointDrawControl instanceof OpenLayers.Control.DrawFeature,
+                    "routingPanel.routingPointDrawControl is an OpenLayers.Control.DrawFeature object");
+            routingPanel.destroy();
         }
     </script>
 </head>
 <body>
 <div id="map"></div>
-<div id="StreetViewPanel"></div>
+<div id="routingPanel"></div>
 </body>
 </html>
 

Modified: sandbox/cmoullet/ux/RoutingPanel/ux/widgets/RoutingPanel.js
===================================================================
--- sandbox/cmoullet/ux/RoutingPanel/ux/widgets/RoutingPanel.js	2009-12-30 06:54:55 UTC (rev 1636)
+++ sandbox/cmoullet/ux/RoutingPanel/ux/widgets/RoutingPanel.js	2009-12-31 05:46:32 UTC (rev 1637)
@@ -6,50 +6,196 @@
  * of the license.
  */
 
+/** api: (define)
+ *  module = GeoExt.ux
+ *  class = RoutingPanel
+ *  base_link = `Ext.Panel <http://extjs.com/deploy/dev/docs/?class=Ext.Panel>`_
+ */
+
 Ext.namespace('GeoExt.ux');
 
 GeoExt.ux.RoutingPanel = Ext.extend(Ext.Panel, {
 
+    /** api: config[map]
+     *  ``OpenLayers.Map``  A configured map
+     */
+    /** private: property[map]
+     *  ``OpenLayers.Map``  The map object
+     */
+    map: null,
+
+    /** api: config[startLocationCombo]
+     *  ``Ext.form.ComboBox``  The combo box used for searching the start point
+     *  In order to work, the combo needs to have a propoerty locationString: lat,lon (WGS 84, example: locationString: '47.25976,9.58423') assigned depending of the searched position
+     *  See geocoding_type for the proposed combo.
+     */
+    /** private: property[startLocationCombo]
+     *  ``Ext.form.ComboBox``  The combo box used for searching the start point
+     */
     startLocationCombo: null,
 
+    /** api: config[endLocationCombo]
+     *  ``Ext.form.ComboBox``  The combo box used for searching the end point
+     *  In order to work, the combo needs to have a propoerty locationString: lat,lon (WGS 84, example: locationString: '47.25976,9.58423') assigned depending of the searched position
+     *  See geocoding_type for the proposed combo.
+     */
+    /** private: property[endLocationCombo]
+     *  ``Ext.form.ComboBox``  The combo box used for searching the end point
+     */
     endLocationCombo: null,
 
+    /** private: property[proxy]
+     *  ``Ext.data.ScriptTagProxy``  Proxy to make the cloudmade search request
+     */
     proxy: null,
 
+    /** private: property[proxy]
+     *  ``Ext.data.Store``  Store for toring the routing results
+     */
     routingStore: null,
 
+    /** api: config[lang]
+     *  Language (used for the routing)
+     */
+    /** private: property[lang]
+     *  Language (used for the routing)
+     */
     lang: 'en',
 
-    routingVersion: '0.0',
+    /** property[routingVersion]
+     *  Routing version of the routing service, available after an itinerary computation
+     *  See http://developers.cloudmade.com/wiki/routing-http-api/Response_structure
+     */
+    routingVersion: null,
+
+    /** property[routingStatus]
+     *  Routing status of the routing service, available after an itinerary computation
+     *  See http://developers.cloudmade.com/wiki/routing-http-api/Response_structure
+     */
     routingStatus: null,
+
+    /** property[routingStatusMessage]
+     *  Routing status message of the routing service, available after an itinerary computation
+     *  See http://developers.cloudmade.com/wiki/routing-http-api/Response_structure
+     */
     routingStatusMessage: null,
+
+    /** property[routingRouteSummary]
+     *  Routing route summary of the routing service, available after an itinerary computation
+     *  See http://developers.cloudmade.com/wiki/routing-http-api/Response_structure
+     */
     routingRouteSummary: null,
+
+    /** property[routingRouteGeometry]
+     *  Routing route geometry of the routing service, available after an itinerary computation
+     *  See http://developers.cloudmade.com/wiki/routing-http-api/Response_structure
+     */
     routingRouteGeometry: null,
+
+    /** property[routingRouteInstructions]
+     *  Routing route instruction of the routing service, available after an itinerary computation
+     *  See http://developers.cloudmade.com/wiki/routing-http-api/Response_structure
+     */
     routingRouteInstructions: null,
+
+    /** api: config[routingLayer]
+     *  ``OpenLayers.Layer.Vector``  Layer presenting the routing result geometry. Per default, a layer named "Routing" will be created.
+     */
+    /** private: property[routingLayer]
+     *  ``OpenLayers.Layer.Vector``  Layer presenting the routing result geometry. Per default, a layer named "Routing" will be created.
+     */
     routingLayer: null,
+
+    /** api: config[routingRecenterMap]
+     *  ``Boolean``  Defines if the map is recentered after routing computation. Per default, yes.
+     */
+    /** private: property[routingRecenterMap]
+     *  ``Boolean``  Defines if the map is recentered after routing computation. Per default, yes.
+     */
     routingRecenterMap: true,
+
+    /** property[routingPathFeature]
+     *  ``OpenLayers.Feature.Vector`` Line feature storing the routing path.
+     */
     routingPathFeature: null,
+
+    /** property[routingStartFeature]
+     *  ``OpenLayers.Feature.Vector`` Point feature storing the start point, if digitized by the user.
+     */
     routingStartFeature: null,
+
+    /** property[routingEndFeature]
+     *  ``OpenLayers.Feature.Vector`` Point feature storing the end point, if digitized by the user.
+     */
     routingEndFeature: null,
+
+    /** private: property[routingPointDrawControl]
+     *  ``OpenLayers.Control.DrawFeature`` Control to get start and end feature
+     */
     routingPointDrawControl: null,
+
+    /** property[routingResultPanel]
+     *  ``Ext.Panel`` Panel presenting the computation result
+     */
     routingResultPanel: null,
-    // Car, foot, bicycle
+
+    /** api: config[route_type]
+     *  Computation route type. Per default: car. Can be 'foot' or 'bicycle'.
+     */
+    /** private: property[route_type]
+     *  Computation route type. Per default: car.
+     */
     route_type: 'car',
+
+    /** api: config[cloudmadeKey]
+     *  Cloudmade key used for the routing and geocoding services
+     */
     cloudmadeKey: null,
 
-    statusLabel: null,
+    /** api: config[geocodingType]
+     *  Geocoding type. Per default: 'cloudmade'. Can be 'geonames'.
+     */
+    /** private: property[geocodingType]
+     *  Geocoding type. Per default: 'cloudmade'. Can be 'geonames'.
+     */
+    geocodingType: 'cloudmade',
 
-    // cloudmade or geonames
-    geocodingType: 'cloudmade',
+    /** private: property[geocodingQueryParam]
+     *  Geocoding query param used for cloudmade geocoding service. Per default: 'query'
+     */
     geocodingQueryParam: 'query',
+
+    /** api: config[geocodingMaxRows]
+     *  Maximum number of rows returned by the cloudmade geocoding service. Per default: 20
+     */
+    /** private: property[geocodingMaxRows]
+     *  Maximum number of rows returned by the cloudmade geocoding service. Per default: 20
+     */
     geocodingMaxRows: 20,
+
+    /** private: property[geocodingUrl]
+     *  Geocoding url of the cloudmade geocoding service.
+     */
     geocodingUrl: null,
 
+    /** api: config[routingStyle]
+     *  Vector style of the routing path
+     */
+    /** private: property[routingStyle]
+     *  Vector style of the routing path
+     */
     routingStyle: {
         strokeColor: "#0000FF",
         strokeOpacity: 0.5,
         strokeWidth: 5
     },
+
+    /** api: config[vectorStyle]
+     *  ``OpenLayers.StyleMap`` Vector style of routing layer
+     */
+    /** private: property[vectorStyle]
+     *  ``OpenLayers.StyleMap`` Vector style of routing layer
+     */
     vectorStyle: new OpenLayers.StyleMap({
         "default": new OpenLayers.Style({
             pointRadius: "8",
@@ -61,24 +207,31 @@
         })
     }),
 
-
+    /** private: property[routingProjection]
+     *  ``OpenLayers.Projection`` Projection of routing system.
+     */
     routingProjection: new OpenLayers.Projection("EPSG:4326"),
 
+    /** private: method[initComponent]
+     *  Private initComponent override.
+     *  Create two events: 
+     *  - routingcomputed
+     *  - beforeroutingcomputed
+     */
     initComponent : function() {
         var defConfig = {
             plain: true,
             border: false
         };
 
-
         Ext.applyIf(this, defConfig);
 
+        // Create cloudmade geocoding serach combo
         if (this.geocodingType == 'cloudmade') {
             this.geocodingUrl = 'http://geocoding.cloudmade.com/' + this.cloudmadeKey + '/geocoding/v2/find.js?results=' + this.geocodingMaxRows + '&return_geometry=false';
             this.startLocationCombo = new Ext.form.ComboBox({
                 fieldLabel: OpenLayers.i18n('A'),
                 name: 'startLocationCombo',
-                locationString: '47.25976,9.58423',
                 emptyText: OpenLayers.i18n('Search start...'),
                 minChars: 1,
                 queryDelay: 50,
@@ -121,7 +274,6 @@
             this.endLocationCombo = new Ext.form.ComboBox({
                 fieldLabel: OpenLayers.i18n('B'),
                 name: 'endLocationCombo',
-                locationString: '47.26117,9.59882',
                 emptyText: OpenLayers.i18n('Search end...'),
                 minChars: 1,
                 queryDelay: 50,
@@ -162,12 +314,7 @@
             });
         }
 
-        this.routingResultPanel = new Ext.Panel({
-            border: false,
-            html: '',
-            bodyStyle: 'padding:5px 5px 5px 5px;'
-        });
-
+        // Create geonames search combo
         if (this.geocodingType == 'geonames') {
             this.startLocationCombo = new GeoExt.ux.form.GeoNamesSearchCombo({
                 fieldLabel: OpenLayers.i18n('A'),
@@ -197,9 +344,22 @@
             }, this);
         }
 
-        this.startLocationCombo.locationString = '47.25976,9.58423';
-        this.endLocationCombo.locationString = '47.26117,9.59882';
+        // Create routing result panel
+        this.routingResultPanel = new Ext.Panel({
+            border: false,
+            html: '',
+            bodyStyle: 'padding:5px 5px 5px 5px;'
+        });
 
+        // Set default location string
+        if (!this.startLocationCombo.locationString) {
+            this.startLocationCombo.locationString = '47.25976,9.58423';
+        }
+        if (!this.endLocationCombo.locationString) {
+            this.endLocationCombo.locationString = '47.26117,9.59882';
+        }
+
+        // Create items of routing panel
         this.items = [
             {
                 layout: 'form',
@@ -309,10 +469,17 @@
 
         ];
 
+        this.addEvents('routingcomputed', 'beforeroutingcomputed');
+
         GeoExt.ux.RoutingPanel.superclass.initComponent.call(this);
     },
 
+    /** private: method[afterRender]
+     *  Private afterRender override.
+     */
     afterRender : function() {
+
+        // Create empty proxy
         this.proxy = new Ext.data.ScriptTagProxy({
             url: 'to_be_replaced',
             nocache: false
@@ -320,14 +487,21 @@
         //http://routes.cloudmade.com/BC9A493B41014CAABB98F0471D759707/api/0.3/47.25976,9.58423,47.26117,9.59882/car/shortest.js
         this.proxy.on(
                 'beforeload', function() {
+            this.fireEvent('beforeroutingcomputed', this);
             this.routingResultPanel.html = OpenLayers.i18n('Computation ongoing....');
             this.routingResultPanel.body.update(this.routingResultPanel.html);
             var newUrl = this.startLocationCombo.locationString + ',' + this.endLocationCombo.locationString;
-            newUrl = newUrl + "/"+this.route_type+".js?lang=" + this.lang;
+            newUrl = newUrl + "/" + this.route_type + ".js?lang=" + this.lang;
             this.proxy.url = "http://routes.cloudmade.com/" + this.cloudmadeKey + "/api/0.3/" + newUrl;
         }, this);
-        this.routingLayer = new OpenLayers.Layer.Vector("Routing", {styleMap: this.vectorStyle});
+
+        // Create routing layer
+        if (!this.routingLayer) {
+            this.routingLayer = new OpenLayers.Layer.Vector("Routing", {styleMap: this.vectorStyle});
+        }
         this.map.addLayer(this.routingLayer);
+
+        // Create point draw control
         this.routingPointDrawControl = new OpenLayers.Control.DrawFeature(this.routingLayer, OpenLayers.Handler.Point);
         this.map.addControl(this.routingPointDrawControl);
         this.routingPointDrawControl.events.on({ "featureadded": function(events) {
@@ -362,6 +536,9 @@
         });
     },
 
+    /** private: method[getItinerary]
+     *  Compute the itinerary and assign the results
+     */
     getItinerary: function() {
         this.routingStore = new Ext.data.Store({
             proxy: this.proxy,
@@ -400,15 +577,18 @@
                 this.routingResultPanel.html = this.routingStatusMessage;
                 this.routingResultPanel.body.update(this.routingResultPanel.html);
             }
+            this.fireEvent('routingcomputed', this);
         }, this
                 );
         this.routingStore.load();
     },
 
+    /** private: method[drawRoute]
+     *  Draw the route in the map
+     */
     drawRoute: function() {
         var pointList = [];
         var newPoint = null;
-        //console.log(this.routingRouteGeometry.length);
         for (var i = 0; i < this.routingRouteGeometry.length; i++) {
             newPoint = new OpenLayers.Geometry.Point(this.routingRouteGeometry[i][1],
                     this.routingRouteGeometry[i][0]);
@@ -428,7 +608,6 @@
             this.map.zoomToExtent(this.routingPathFeature.geometry.bounds);
         }
     }
-
 });
 
 Ext.reg('gxux_routingpanel', GeoExt.ux.RoutingPanel);
\ No newline at end of file



More information about the Commits mailing list