[Commits] r2532 - in sandbox/cmoullet/ux/Profile: examples lib/GeoExt.ux

commits at geoext.org commits at geoext.org
Fri Dec 24 13:12:32 CET 2010


Author: cmoullet
Date: 2010-12-24 13:12:32 +0100 (Fri, 24 Dec 2010)
New Revision: 2532

Added:
   sandbox/cmoullet/ux/Profile/lib/GeoExt.ux/ProfilePanel.js
Modified:
   sandbox/cmoullet/ux/Profile/examples/profile.html
   sandbox/cmoullet/ux/Profile/lib/GeoExt.ux/ProfileAction.js
Log:
Create a profile Window. And now, which graphic library ??

Modified: sandbox/cmoullet/ux/Profile/examples/profile.html
===================================================================
--- sandbox/cmoullet/ux/Profile/examples/profile.html	2010-12-24 12:11:55 UTC (rev 2531)
+++ sandbox/cmoullet/ux/Profile/examples/profile.html	2010-12-24 12:12:32 UTC (rev 2532)
@@ -13,8 +13,10 @@
     <script type="text/javascript" src="http://svn.osgeo.org/metacrs/proj4js/trunk/lib/defs/EPSG21781.js"></script>
 
     <!-- script resources for this ux -->
+    <script type="text/javascript" src="../../../trunk/ext/src/ext-core/examples/jsonp/jsonp.js"></script>
     <script type="text/javascript" src="../lib/GeoExt.ux/ProfileControl.js"></script>
     <script type="text/javascript" src="../lib/GeoExt.ux/ProfileAction.js"></script>
+    <script type="text/javascript" src="../lib/GeoExt.ux/ProfilePanel.js"></script>
 
     <script type="text/javascript" src="profile.js"></script>
 </head>

Modified: sandbox/cmoullet/ux/Profile/lib/GeoExt.ux/ProfileAction.js
===================================================================
--- sandbox/cmoullet/ux/Profile/lib/GeoExt.ux/ProfileAction.js	2010-12-24 12:11:55 UTC (rev 2531)
+++ sandbox/cmoullet/ux/Profile/lib/GeoExt.ux/ProfileAction.js	2010-12-24 12:12:32 UTC (rev 2532)
@@ -29,32 +29,55 @@
      *  ``String`` Name of the profile service. Optional.
      */
 
+    /* profile information
+     * Multidimensional array with x columns of "samples" lines
+     * column 0: distance from start
+     * column 1: easting
+     * column 2: northing
+     * column 3 to n: elevation information of the cooresponding elevation models
+     */
+    profileData: null,
+
+    _profileWindow: null,
+
+    _drawControl: null,
+
     /** private: method[constructor]
      */
     constructor: function(config) {
-        var drawControl = new OpenLayers.Control.ProfileControl(
+
+        this._drawControl = new OpenLayers.Control.ProfileControl(
                 config.vector, OpenLayers.Handler.Path
                 );
 
-        drawControl.events.register('featureadded', this, function(event) {
+        this._drawControl.events.register('featureadded', this, function(event) {
             this.createProfile(event);
         });
 
+
         this.profileService = config.profileService;
+        this.profileModels = config.profileModels;
+
         this.map = config.map;
 
-        config.map.addControl(drawControl);
+        this.samples = config.samples || 200;
 
+        config.map.addControl(this._drawControl);
+
         config = Ext.apply({
             allowDepress: false,
             text: OpenLayers.i18n('Profile'),
             handler: function() {
-                if (!drawControl.active) {
-                    drawControl.activate();
+                if (this._profileWindow) {
+                    this._profileWindow.close();
+                }
+                if (!this._drawControl.active) {
+                    this._drawControl.activate();
                 } else {
-                    drawControl.cleanFeature();
+                    this._drawControl.cleanFeature();
                 }
-            }
+            },
+            scope: this
         }, config);
 
         GeoExt.ux.Profile.superclass.constructor.call(this, config);
@@ -65,6 +88,52 @@
             var formatter = new OpenLayers.Format.GeoJSON({internalProjection: this.map.getProjectionObject(),
                 externalProjection: new OpenLayers.Projection("EPSG:21781")});
             var geometryGeoJSON = formatter.write(event.feature.geometry);
+            if (!this.profileModels) {
+                this.profileModels = 'DTM25';
+            }
+            Ext.ux.JSONP.request("http://api.geo.admin.ch/profile.json", {
+                callbackKey: "cb",
+                params: {
+                    nb_points: this.samples,
+                    geom: geometryGeoJSON,
+                    elevation_models: this.profileModels
+                },
+                scope: this,
+                callback: function(response) {
+                    // Define the size of the array
+                    var models = this.profileModels.split(',');
+                    var arraySize = parseInt(3 + models.length, 10);
+                    this.profileData = [arraySize];
+                    for (var k = 0; k < arraySize; k++) {
+                        this.profileData[k] = [this.samples];
+                    }
+                    for (var i = 0; i < response.profile.length; i++) {
+                        this.profileData[0][i] = response.profile[i].dist;
+                        this.profileData[1][i] = response.profile[i].easting;
+                        this.profileData[2][i] = response.profile[i].northing;
+                        for (j = 0; j < models.length; j++) {
+                            this.profileData[j + 3][i] = response.profile[i].alts[models[j]];
+                        }
+                    }
+                    this.showProfileWindow();
+                }
+            });
         }
+    },
+
+    showProfileWindow: function() {
+        this._profileWindow = new Ext.Window({
+            width:800,
+            height:600,
+            items: new GeoExt.ux.ProfilePanel({
+                map: this.map,
+                profileData: this.profileData,
+                feature: this._drawControl.digitizedFeature
+            })
+        });
+        this._profileWindow.on('close', function() {
+            this._drawControl.cleanFeature();
+        }, this);
+        this._profileWindow.show();
     }
 });

Added: sandbox/cmoullet/ux/Profile/lib/GeoExt.ux/ProfilePanel.js
===================================================================
--- sandbox/cmoullet/ux/Profile/lib/GeoExt.ux/ProfilePanel.js	                        (rev 0)
+++ sandbox/cmoullet/ux/Profile/lib/GeoExt.ux/ProfilePanel.js	2010-12-24 12:12:32 UTC (rev 2532)
@@ -0,0 +1,33 @@
+/** api: (define)
+ *  module = GeoExt.ux
+ *  class = ProfilePanel
+ *  base_link = `Ext.Panel <http://extjs.com/deploy/dev/docs/?class=Ext.Panel>`_
+ */
+Ext.namespace('GeoExt.ux');
+
+GeoExt.ux.ProfilePanel = Ext.extend(Ext.Panel, {
+    /** api: config[map]
+     *  ``OpenLayers.Map``  A configured map
+     */
+    /** private: property[map]
+     *  ``OpenLayers.Map``  The map object.
+     */
+    map: null,
+
+    feature: null,
+
+    profileData: null,
+
+    /** private: method[initComponent]
+     *  Private initComponent override.
+     */
+    initComponent: function() {
+        var defConfig = {
+            border: true
+        };
+        Ext.applyIf(this, defConfig);
+
+        GeoExt.ux.ProfilePanel.superclass.initComponent.call(this);
+    }
+
+});
\ No newline at end of file



More information about the Commits mailing list