[Commits] r1503 - in sandbox/cmoullet/ux/StreetViewPanel: examples tests/ux/widgets ux/control ux/widgets

commits at geoext.org commits at geoext.org
Thu Nov 26 23:41:22 CET 2009


Author: cmoullet
Date: 2009-11-26 23:41:22 +0100 (Thu, 26 Nov 2009)
New Revision: 1503

Added:
   sandbox/cmoullet/ux/StreetViewPanel/ux/control/StreetViewClick.js
Removed:
   sandbox/cmoullet/ux/StreetViewPanel/ux/control/Click.js
Modified:
   sandbox/cmoullet/ux/StreetViewPanel/examples/StreetViewPanelExample.html
   sandbox/cmoullet/ux/StreetViewPanel/tests/ux/widgets/StreetViewPanel.html
   sandbox/cmoullet/ux/StreetViewPanel/ux/widgets/StreetViewPanel.js
Log:
Train version, rearchitecturing of code


Modified: sandbox/cmoullet/ux/StreetViewPanel/examples/StreetViewPanelExample.html
===================================================================
--- sandbox/cmoullet/ux/StreetViewPanel/examples/StreetViewPanelExample.html	2009-11-26 10:52:20 UTC (rev 1502)
+++ sandbox/cmoullet/ux/StreetViewPanel/examples/StreetViewPanelExample.html	2009-11-26 22:41:22 UTC (rev 1503)
@@ -16,7 +16,7 @@
     <script type="text/javascript" src="../../../trunk/geoext/lib/GeoExt.js"></script>
 
     <script type="text/javascript" src="../ux/widgets/StreetViewPanel.js"></script>
-    <script type="text/javascript" src="../ux/control/Click.js"></script>
+    <script type="text/javascript" src="../ux/control/StreetViewClick.js"></script>
     <script type="text/javascript" src="StreetViewPanelExample.js"></script>
 
 </head>

Modified: sandbox/cmoullet/ux/StreetViewPanel/tests/ux/widgets/StreetViewPanel.html
===================================================================
--- sandbox/cmoullet/ux/StreetViewPanel/tests/ux/widgets/StreetViewPanel.html	2009-11-26 10:52:20 UTC (rev 1502)
+++ sandbox/cmoullet/ux/StreetViewPanel/tests/ux/widgets/StreetViewPanel.html	2009-11-26 22:41:22 UTC (rev 1503)
@@ -15,7 +15,7 @@
     <script type="text/javascript" src="../../../../../trunk/geoext/lib/GeoExt.js"></script>
 
     <script type="text/javascript" src="../../../ux/widgets/StreetViewPanel.js"></script>
-    <script type="text/javascript" src="../../../ux/control/Click.js"></script>
+    <script type="text/javascript" src="../../../ux/control/StreetViewClick.js"></script>
     <script type="text/javascript">
         function test_ctor(t) {
             t.plan(2);

Deleted: sandbox/cmoullet/ux/StreetViewPanel/ux/control/Click.js
===================================================================
--- sandbox/cmoullet/ux/StreetViewPanel/ux/control/Click.js	2009-11-26 10:52:20 UTC (rev 1502)
+++ sandbox/cmoullet/ux/StreetViewPanel/ux/control/Click.js	2009-11-26 22:41:22 UTC (rev 1503)
@@ -1,63 +0,0 @@
-/**
- * Copyright (c) 2008-2009 The Open Source Geospatial Foundation
- *
- * Published under the BSD license.
- * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
- * of the license.
- */
-
-Ext.namespace('GeoExt.ux');
-
-GeoExt.ux.Click = OpenLayers.Class(OpenLayers.Control, {
-    defaultHandlerOptions: {
-        'single': true,
-        'double': false,
-        'pixelTolerance': 0,
-        'stopSingle': false,
-        'stopDouble': false
-    },
-
-    initialize: function(options) {
-        this.handlerOptions = OpenLayers.Util.extend({}, this.defaultHandlerOptions);
-        OpenLayers.Control.prototype.initialize.apply(this, arguments);
-        this.handler = new OpenLayers.Handler.Click(
-                this, {
-            'click': this.onClick,
-            'dblclick': this.onDblclick
-        },
-                this.handlerOptions
-                );
-    },
-
-
-    onClick: function(evt) {
-
-        var lonlat = this.map.getLonLatFromViewPortPx(evt.xy);
-        lonlat.transform(this.map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
-        var clickedPosition = new GLatLng(lonlat.lat, lonlat.lon);
-
-        var callback = function (data) {
-            if (data) {
-                if (data.code == 600) {
-                    alert(OpenLayers.i18n('Google Street View: No panorama found near this position. You have to click elsewhere ;-)'));
-                } else if (data.code == 500) {
-                    alert(OpenLayers.i18n('Google Street View: Server error'));
-                } else if (data.code == 200) {
-                    var POV = {yaw: this.yaw,  pitch: this.pitch, zoom: this.zoom};
-                    this.panorama.setLocationAndPOV(data.location.latlng, POV);
-                    // Add the navigation tool
-                    this.panorama.drawNavigationTool(this.panorama, this.panorama.navigationToolLayer, data.location.latlng, this.yaw, data.links)
-                } else {
-                    alert(OpenLayers.i18n('Google Street View: Unexpected problem'));
-                }
-            }
-        };
-        this.streetviewclient.getNearestPanorama(clickedPosition, callback.createDelegate(this));
-
-    },
-
-    onDblclick: function(evt) {
-        alert('doubleClick');
-    }
-
-});

Copied: sandbox/cmoullet/ux/StreetViewPanel/ux/control/StreetViewClick.js (from rev 1502, sandbox/cmoullet/ux/StreetViewPanel/ux/control/Click.js)
===================================================================
--- sandbox/cmoullet/ux/StreetViewPanel/ux/control/StreetViewClick.js	                        (rev 0)
+++ sandbox/cmoullet/ux/StreetViewPanel/ux/control/StreetViewClick.js	2009-11-26 22:41:22 UTC (rev 1503)
@@ -0,0 +1,62 @@
+/**
+ * Copyright (c) 2008-2009 The Open Source Geospatial Foundation
+ *
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+
+Ext.namespace('GeoExt.ux');
+
+GeoExt.ux.StreetViewClick = OpenLayers.Class(OpenLayers.Control, {
+    defaultHandlerOptions: {
+        'single': true,
+        'double': false,
+        'pixelTolerance': 0,
+        'stopSingle': false,
+        'stopDouble': false
+    },
+
+    initialize: function(options) {
+        this.handlerOptions = OpenLayers.Util.extend({}, this.defaultHandlerOptions);
+        OpenLayers.Control.prototype.initialize.apply(this, arguments);
+        this.handler = new OpenLayers.Handler.Click(this, {
+            'click': this.onClick,
+            'dblclick': this.onDblclick},
+                this.handlerOptions
+                );
+    },
+
+
+    onClick: function(evt) {
+        var lonlat = this.map.getLonLatFromViewPortPx(evt.xy);
+        lonlat.transform(this.map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
+        var clickedPosition = new GLatLng(lonlat.lat, lonlat.lon);
+
+        var callback = function (data) {
+            if (data) {
+                if (data.code == 600) {
+                    alert(OpenLayers.i18n('Google Street View: No panorama found near this position. You have to click elsewhere ;-)'));
+                } else if (data.code == 500) {
+                    alert(OpenLayers.i18n('Google Street View: Server error'));
+                } else if (data.code == 200) {
+                    var POV = {yaw: this.panorama.yaw,  pitch: this.panorama.pitch, zoom: this.panorama.zoom};
+                    this.panorama.setLocationAndPOV(data.location.latlng, POV);
+                    // Add the navigation tool
+                    if (this.panorama.showTool) {
+                        this.panorama.drawNavigationTool(this.panorama, data.location.latlng, data.links)
+                    }
+
+                } else {
+                    alert(OpenLayers.i18n('Google Street View: Unexpected problem'));
+                }
+            }
+        };
+        this.streetviewclient.getNearestPanorama(clickedPosition, callback.createDelegate(this));
+    },
+
+    onDblclick: function(evt) {
+        alert('doubleClick');
+    }
+
+});

Modified: sandbox/cmoullet/ux/StreetViewPanel/ux/widgets/StreetViewPanel.js
===================================================================
--- sandbox/cmoullet/ux/StreetViewPanel/ux/widgets/StreetViewPanel.js	2009-11-26 10:52:20 UTC (rev 1502)
+++ sandbox/cmoullet/ux/StreetViewPanel/ux/widgets/StreetViewPanel.js	2009-11-26 22:41:22 UTC (rev 1503)
@@ -10,8 +10,7 @@
 
 GeoExt.ux.StreetViewPanel = Ext.extend(Ext.Panel, {
     /** api: config[map]
-     *  ``OpenLayers.Map or Object``  A configured map or a configuration object
-     *  for the map constructor
+     *  ``OpenLayers.Map``  A configured map
      */
     /** private: property[map]
      *  ``OpenLayers.Map``  The map object.
@@ -53,7 +52,7 @@
     /** api: config[yaw]
      *  ``Number``  The camera yaw in degrees relative to true north. True north is 0 degrees, east is 90 degrees, south is 180 degrees, west is 270 degrees.
      */
-    /** private: property[180]
+    /** private: property[yaw]
      *  ``Number``  Camery yaw
      */
     yaw: 180,
@@ -61,7 +60,7 @@
     /** api: config[pitch]
      *  ``Number``  The camera pitch in degrees, relative to the street view vehicle. Ranges from 90 degrees (directly upwards) to -90 degrees (directly downwards).
      */
-    /** private: property[180]
+    /** private: property[pitch]
      *  ``Number``  Camery pitch
      */
     pitch: 0,
@@ -69,11 +68,19 @@
     /** api: config[zoom]
      *  ``Number``  The zoom level. Fully zoomed-out is level 0, zooming in increases the zoom level.
      */
-    /** private: property[180]
+    /** private: property[zoom]
      *  ``Number``  Panorama zoom level
      */
     zoom: 0,
 
+    /** api: config[panoramaLocation]
+     *  ``Number``  The panorama location
+     */
+    /** private: property[panoramaLocation]
+     *  ``Number``  Panorama location
+     */
+    panoramaLocation: null,
+
     initComponent : function() {
 
         var defConfig = {
@@ -93,50 +100,85 @@
         }
 
         GeoExt.ux.StreetViewPanel.superclass.afterRender.call(this);
+        // Create StreetViewClient
+        this.streetviewclient = new GStreetviewClient();
 
+        // Configure panorama and associate methods and parameters
         this.panorama = new GStreetviewPanorama(this.body.dom);
-
-        // Navigation tool associated to panorama
         this.panorama.map = this.map;
-        this.panorama.drawNavigationTool = function(panorama, layer, position, yaw, links) {
-            layer.destroyFeatures();
+        this.panorama.yaw = this.yaw;
+        this.panorama.pitch = this.pitch;
+        this.panorama.level = this.level;
+        this.panorama.showTool = this.showTool;
+        this.panorama.clickMode = this.clickMode;
+        // Define a panorama method for navigation tool drawing
+        this.panorama.drawNavigationTool = function(panorama, position, links) {
+            // Destroy the existing features
+            panorama.navigationToolLayer.destroyFeatures();
+            // Compute the new position
             var circlePosition = new OpenLayers.Geometry.Point(position.lng(), position.lat());
             circlePosition.transform(new OpenLayers.Projection("EPSG:4326"), panorama.map.getProjectionObject());
+            // Define a style
             panorama.navigationToolStyle = {
                 externalGraphic: "../resources/tool.png",
                 pointRadius: 30,
-                rotation: panorama.getPOV().yaw
+                rotation: panorama.yaw
             };
+            // Add a vector feature in navigation layer
             panorama.navigationTool = new OpenLayers.Feature.Vector(circlePosition, null, panorama.navigationToolStyle);
-            layer.addFeatures([panorama.navigationTool]);
+            panorama.navigationToolLayer.addFeatures([panorama.navigationTool]);
         };
-        
-        // Add event handler for panorama
+        // Add panorama events listeners
         GEvent.addListener(this.panorama, "yawchanged", function(yaw) {
-            this.navigationToolStyle.rotation = yaw;
-            this.navigationTool.layer.drawFeature(this.navigationTool);
+            // This is the panorama
+            if (this.showTool) {
+                this.navigationToolStyle.rotation = yaw;
+                this.navigationTool.layer.drawFeature(this.navigationTool);
+            }
+            this.yaw = yaw;
         });
+        // Set initial position of panorama
+        if (this.panoramaLocation) {
+            var POV = {yaw: this.panorama.yaw,  pitch: this.panorama.pitch, zoom: this.panorama.zoom};
+            var callback = function (data) {
+                if (data) {
+                    if (data.code == 600) {
+                        alert(OpenLayers.i18n('Google Street View: No panorama found near this position. You have to click elsewhere ;-)'));
+                    } else if (data.code == 500) {
+                        alert(OpenLayers.i18n('Google Street View: Server error'));
+                    } else if (data.code == 200) {
+                        var POV = {yaw: this.panorama.yaw,  pitch: this.panorama.pitch, zoom: this.panorama.zoom};
+                        this.panorama.setLocationAndPOV(data.location.latlng, POV);
+                        // Add the navigation tool
+                        if (this.panorama.showTool) {
+                            this.panorama.drawNavigationTool(this.panorama, data.location.latlng, data.links)
+                        }
 
-        this.streetviewclient = new GStreetviewClient();
+                    } else {
+                        alert(OpenLayers.i18n('Google Street View: Unexpected problem'));
+                    }
+                }
+            };
+            this.streetviewclient.getNearestPanorama(this.panoramaLocation, callback.createDelegate(this));
+        }
+
+        // Add features associated to map
         if (this.map) {
             if (this.clickMode) {
-                if (this.showTool) {
-                    this.panorama.navigationToolLayer = new OpenLayers.Layer.Vector("2DNavigationTool");
-                    this.map.addLayer(this.panorama.navigationToolLayer);
-                }
-                this.clickControl = new GeoExt.ux.Click({
+                this.clickControl = new GeoExt.ux.StreetViewClick({
                     handlerOptions: {
                         "single": true
                     },
                     panorama: this.panorama,
-                    streetviewclient: this.streetviewclient,
-                    yaw: this.yaw,
-                    pitch: this.pitch,
-                    level: this.level
+                    streetviewclient: this.streetviewclient
                 });
                 this.map.addControl(this.clickControl);
                 this.clickControl.activate();
             }
+            if (this.showTool) {
+                this.panorama.navigationToolLayer = new OpenLayers.Layer.Vector("2DNavigationTool");
+                this.map.addLayer(this.panorama.navigationToolLayer);
+            }
         }
     },
 
@@ -145,12 +187,12 @@
             if (this.map) {
                 this.clickControl.deactivate();
                 this.map.removeControl(this.clickControl);
-                if (this.showTool) {
-                    this.map.removeLayer(this.navigationToolLayer);
-                    this.navigationToolLayer.destroy();
-                }
             }
         }
+        if (this.showTool) {
+            this.map.removeLayer(this.panorama.navigationToolLayer);
+            this.panorama.navigationToolLayer.destroy();
+        }
         this.panorama.remove();
         delete this.panorama;
         GeoExt.ux.StreetViewPanel.superclass.beforeDestroy.apply(this, arguments);



More information about the Commits mailing list