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

commits at geoext.org commits at geoext.org
Wed Jan 13 21:42:48 CET 2010


Author: cmoullet
Date: 2010-01-13 21:42:48 +0100 (Wed, 13 Jan 2010)
New Revision: 1739

Modified:
   sandbox/cmoullet/ux/RoutingPanel/examples/RoutingPanelExample.js
   sandbox/cmoullet/ux/RoutingPanel/ux/widgets/RoutingPanel.js
Log:
initial permalink support. Not fully functional.

Modified: sandbox/cmoullet/ux/RoutingPanel/examples/RoutingPanelExample.js
===================================================================
--- sandbox/cmoullet/ux/RoutingPanel/examples/RoutingPanelExample.js	2010-01-13 11:18:51 UTC (rev 1738)
+++ sandbox/cmoullet/ux/RoutingPanel/examples/RoutingPanelExample.js	2010-01-13 20:42:48 UTC (rev 1739)
@@ -28,6 +28,33 @@
         layers: [layer]
     });
 
+    var toolbar = new Ext.Toolbar({
+        items: [
+            {
+                xtype: 'tbfill'
+            },
+            {
+                text: 'Clear route',
+                enableToggle: false,
+                handler: function() {
+                    var routingPanelItem = Ext.getCmp("routingPanelItem");
+                    if (routingPanelItem) {
+                        routingPanelItem.clearItinerary();
+                    }
+                }
+            },
+            {
+                text: 'Permalink',
+                enableToggle: false,
+                handler: function() {
+                    var routingPanelItem = Ext.getCmp("routingPanelItem");
+                    if (routingPanelItem) {
+                        window.open(routingPanelItem.getPermalink(true));
+                    }
+                }
+            }
+        ]});
+
     viewport = new Ext.Viewport({
         layout: "border",
         id: 'mainViewport',
@@ -41,7 +68,8 @@
                 layers: mapStore,
                 center: center,
                 zoom: 14,
-                split: true
+                split: true,
+                tbar: toolbar
             },
             {
                 layout:'accordion',

Modified: sandbox/cmoullet/ux/RoutingPanel/ux/widgets/RoutingPanel.js
===================================================================
--- sandbox/cmoullet/ux/RoutingPanel/ux/widgets/RoutingPanel.js	2010-01-13 11:18:51 UTC (rev 1738)
+++ sandbox/cmoullet/ux/RoutingPanel/ux/widgets/RoutingPanel.js	2010-01-13 20:42:48 UTC (rev 1739)
@@ -227,6 +227,14 @@
      */
     routingProjection: new OpenLayers.Projection("EPSG:4326"),
 
+    /** api: config[readPermalink]
+     *  ``Boolean``  Read the permalink in the url if presents
+     */
+    /** private: property[readPermalink]
+     *  ``Boolean``  Read the permalink in the url if presents
+     */
+    readPermalink: true,
+
     /** private: method[initComponent]
      *  Private initComponent override.
      *  Create two events:
@@ -508,7 +516,6 @@
      *  Private afterRender override.
      */
     afterRender : function() {
-
         // Create empty proxy
         this.proxy = new Ext.data.ScriptTagProxy({
             url: 'to_be_replaced',
@@ -564,8 +571,75 @@
         },
             scope: this
         });
+        // Use the permalink
+        if (this.readPermalink) {
+            var parameters = OpenLayers.Util.getParameters();
+            this.setPermalink(parameters);
+
+        }
     },
 
+    /** method[getPermalink]
+     *  Create the permalink
+     *
+     * :param complete ``Boolean`` Defines if the complete URL is generated or only the parameters KVP
+     */
+    getPermalink: function(complete) {
+        var permalink;
+        if (complete) {
+            permalink = window.location.href;
+            if (OpenLayers.String.contains(permalink, '?')) {
+                var end = permalink.indexOf('?');
+                permalink = permalink.substring(0, end);
+            }
+            permalink = permalink + "?";
+        } else {
+            permalink = '';
+        }
+
+        if (this.startLocationCombo.locationString && this.routingPathFeature) {
+            permalink = permalink + "routingStartLocationString=" + this.startLocationCombo.locationString;
+        }
+        if (this.endLocationCombo.locationString && this.routingPathFeature) {
+            permalink = permalink + "&routingEndLocationString=" + this.endLocationCombo.locationString;
+        }
+        if (this.map) {
+            permalink = permalink + "&routingeasting=" + this.map.getCenter().lon;
+            permalink = permalink + "&routingnorthing=" + this.map.getCenter().lat;
+            permalink = permalink + "&routingzoom=" + this.map.getZoom();
+        }
+        return permalink;
+    },
+
+    /** private: method[setPermalink]
+     *  Set the permalink according to the url parameters
+     *
+     * :param parameters URL paramaters
+     */
+    setPermalink: function(parameters) {
+        if (parameters.routingStartLocationString) {
+            this.startLocationCombo.locationString = parameters.routingStartLocationString[0] + "," + parameters.routingStartLocationString[1];
+        }
+        if (parameters.routingEndLocationString) {
+            this.endLocationCombo.locationString = parameters.routingEndLocationString[0] + "," + parameters.routingEndLocationString[1];
+        }
+        if (parameters.routingStartLocationString && parameters.routingEndLocationString) {
+            // TODO: supporte itinerary computation
+            //this.getItinerary();
+        }
+        if (parameters.routingeasting && parameters.routingnorthing) {
+            var position = new OpenLayers.LonLat(parseFloat(parameters.routingeasting), parseFloat(parameters.routingnorthing));
+            if (this.map) {
+                this.map.setCenter(position);
+            }
+        }
+        if (parameters.routingzoom) {
+            if (this.map) {
+                this.map.zoomTo(parseInt(parameters.routingzoom, 10));
+            }
+        }
+    },
+
     /** private: method[getItinerary]
      *  Compute the itinerary and assign the results
      */
@@ -617,6 +691,27 @@
         }
     },
 
+    /** private: method[clearItinerary]
+     *  Clear the itinerary the itinerary and assign the results
+     */
+    clearItinerary: function() {
+        if (this.routingPathFeature) {
+            this.routingLayer.removeFeatures([this.routingPathFeature]);
+        }
+        this.startLocationCombo.clearValue();
+        this.endLocationCombo.clearValue();
+        if (this.routingStartFeature) {
+            this.routingLayer.removeFeatures([this.routingStartFeature]);
+            this.routingStartFeature = null;
+        }
+        if (this.routingEndFeature) {
+            this.routingLayer.removeFeatures([this.routingEndFeature]);
+            this.routingEndFeature = null;
+        }
+        this.routingResultPanel.html = '';
+        this.routingResultPanel.body.update(this.routingResultPanel.html);
+    },
+
     /** private: method[drawRoute]
      *  Draw the route in the map
      */



More information about the Commits mailing list