[OpenLayers-Commits] r11328 - in sandbox/igorti/openlayers: . examples lib/OpenLayers lib/OpenLayers/Control tests/Control tests/Layer

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Feb 23 09:42:54 EST 2011


Author: igorti
Date: 2011-02-23 06:42:54 -0800 (Wed, 23 Feb 2011)
New Revision: 11328

Modified:
   sandbox/igorti/openlayers/
   sandbox/igorti/openlayers/examples/geolocation.html
   sandbox/igorti/openlayers/examples/geolocation.js
   sandbox/igorti/openlayers/examples/mobile-navigation.html
   sandbox/igorti/openlayers/lib/OpenLayers/Control/Geolocate.js
   sandbox/igorti/openlayers/lib/OpenLayers/Kinetic.js
   sandbox/igorti/openlayers/tests/Control/Geolocate.html
   sandbox/igorti/openlayers/tests/Layer/EventPane.html
Log:
merge with trunk


Property changes on: sandbox/igorti/openlayers
___________________________________________________________________
Modified: svn:mergeinfo
   - /sandbox/roberthl/openlayers:9745-9748
   + /sandbox/roberthl/openlayers:9745-9748
/trunk/openlayers:11298-11327

Modified: sandbox/igorti/openlayers/examples/geolocation.html
===================================================================
--- sandbox/igorti/openlayers/examples/geolocation.html	2011-02-23 14:31:55 UTC (rev 11327)
+++ sandbox/igorti/openlayers/examples/geolocation.html	2011-02-23 14:42:54 UTC (rev 11328)
@@ -13,7 +13,7 @@
             }
         </style>
     </head>
-    <body onload="init()">
+    <body>
         <h1 id="title">Geolocation Example</h1>
 
         <div id="tags">

Modified: sandbox/igorti/openlayers/examples/geolocation.js
===================================================================
--- sandbox/igorti/openlayers/examples/geolocation.js	2011-02-23 14:31:55 UTC (rev 11327)
+++ sandbox/igorti/openlayers/examples/geolocation.js	2011-02-23 14:42:54 UTC (rev 11328)
@@ -1,8 +1,7 @@
 var style = {
+    fillColor: '#000',
     fillOpacity: 0.1,
-    fillColor: '#000',
-    strokeColor: '#f00',
-    strokeOpacity: 0.6
+    strokeWidth: 0
 }
 
 var map = new OpenLayers.Map('map');
@@ -17,6 +16,34 @@
     ), 12
 );
 
+var pulsate = function(feature) {
+    var point = feature.geometry.getCentroid(),
+        bounds = feature.geometry.getBounds(),
+        radius = Math.abs((bounds.right - bounds.left)/2),
+        count = 0,
+        grow = 'up';
+
+    var resize = function(){
+        if (count>16) clearInterval(window.resizeInterval);
+        var interval = radius * 0.03;
+        var ratio = interval/radius;
+        switch(count) {
+            case 4:
+            case 12:
+                grow = 'down'; break;
+            case 8:
+                grow = 'up'; break;
+        }
+        if (grow!=='up') {
+            ratio = - Math.abs(ratio);
+        }
+        feature.geometry.resize(1+ratio, point);
+        vector.drawFeature(feature);
+        count++;
+    }
+    window.resizeInterval = window.setInterval(resize, 50, point, radius);
+};
+
 var geolocate = new OpenLayers.Control.Geolocate({
     geolocationOptions: {
         enableHighAccuracy: false,
@@ -27,6 +54,16 @@
 map.addControl(geolocate);
 geolocate.events.register("locationupdated",this,function(e) {
     vector.removeAllFeatures();
+    var circle = new OpenLayers.Feature.Vector(
+        OpenLayers.Geometry.Polygon.createRegularPolygon(
+            new OpenLayers.Geometry.Point(e.point.x, e.point.y),
+            e.position.coords.accuracy/2,
+            40,
+            0
+        ),
+        {},
+        style
+    );
     vector.addFeatures([
         new OpenLayers.Feature.Vector(
             e.point,
@@ -39,34 +76,28 @@
                 pointRadius: 10
             }
         ),
-        new OpenLayers.Feature.Vector(
-            OpenLayers.Geometry.Polygon.createRegularPolygon(
-                new OpenLayers.Geometry.Point(e.point.x, e.point.y),
-                e.position.coords.accuracy/2,
-                50,
-                0
-            ),
-            {},
-            style
-        )
+        circle
     ]);
     map.zoomToExtent(vector.getDataExtent());
+    pulsate(circle);
 });
 geolocate.events.register("locationfailed",this,function() {
     OpenLayers.Console.log('Location detection failed');
 });
 
 $('locate').onclick = function() {
+    vector.removeAllFeatures();
     geolocate.deactivate();
     $('track').checked = false;
     geolocate.watch = false;
     geolocate.activate();
 };
 $('track').onclick = function() {
+    vector.removeAllFeatures();
     geolocate.deactivate();
     if (this.checked) {
         geolocate.watch = true;
         geolocate.activate();
     }
 };
-$('track').checked = false;
\ No newline at end of file
+$('track').checked = false;

Modified: sandbox/igorti/openlayers/examples/mobile-navigation.html
===================================================================
--- sandbox/igorti/openlayers/examples/mobile-navigation.html	2011-02-23 14:31:55 UTC (rev 11327)
+++ sandbox/igorti/openlayers/examples/mobile-navigation.html	2011-02-23 14:42:54 UTC (rev 11328)
@@ -3,7 +3,7 @@
   <head>
     <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
     <meta name="apple-mobile-web-app-capable" content="yes" />
-    <title>OpenLayers TouchNavigation Control</title>
+    <title>Mobile Navigation Example</title>
     <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
     <link rel="stylesheet" href="style.mobile.css" type="text/css" />
     <link rel="stylesheet" href="style.css" type="text/css" />

Modified: sandbox/igorti/openlayers/lib/OpenLayers/Control/Geolocate.js
===================================================================
--- sandbox/igorti/openlayers/lib/OpenLayers/Control/Geolocate.js	2011-02-23 14:31:55 UTC (rev 11327)
+++ sandbox/igorti/openlayers/lib/OpenLayers/Control/Geolocate.js	2011-02-23 14:42:54 UTC (rev 11328)
@@ -85,7 +85,7 @@
             this.events.triggerEvent("locationuncapable");
             return false;
         }
-        if (!this.active) {
+        if (OpenLayers.Control.prototype.activate.apply(this, arguments)) {
             if (this.watch) {
                 this.watchId = this.geolocation.watchPosition(
                     OpenLayers.Function.bind(this.geolocate, this),
@@ -93,16 +93,11 @@
                     this.geolocationOptions
                 );
             } else {
-                this.geolocation.getCurrentPosition(
-                    OpenLayers.Function.bind(this.geolocate, this),
-                    OpenLayers.Function.bind(this.failure, this),
-                    this.geolocationOptions
-                );
+                this.getCurrentLocation();
             }
+            return true;
         }
-        return OpenLayers.Control.prototype.activate.apply(
-            this, arguments
-        );
+        return false;
     },
 
     /**
@@ -146,6 +141,25 @@
     },
 
     /**
+     * APIMethod: getCurrentLocation
+     *
+     * Returns:
+     * {Boolean} Returns true if a event will be fired (successfull
+     * registration)
+     */
+    getCurrentLocation: function() {
+        if (!this.active || this.watch) {
+            return false;
+        }
+        this.geolocation.getCurrentPosition(
+            OpenLayers.Function.bind(this.geolocate, this),
+            OpenLayers.Function.bind(this.failure, this),
+            this.geolocationOptions
+        );
+        return true;
+    },
+
+    /**
      * Method: failure
      * method called on browser's geolocation failure
      *

Modified: sandbox/igorti/openlayers/lib/OpenLayers/Kinetic.js
===================================================================
--- sandbox/igorti/openlayers/lib/OpenLayers/Kinetic.js	2011-02-23 14:31:55 UTC (rev 11327)
+++ sandbox/igorti/openlayers/lib/OpenLayers/Kinetic.js	2011-02-23 14:42:54 UTC (rev 11328)
@@ -63,7 +63,6 @@
 
     /**
      * Method: begin
-     *
      * Begins the dragging.
      */
     begin: function() {
@@ -74,8 +73,10 @@
 
     /**
      * Method: update
+     * Updates during the dragging.
      *
-     * Updates during the dragging.
+     * Parameters:
+     * xy - {<OpenLayers.Pixel>} The new position.
      */
     update: function(xy) {
         this.points.unshift({xy: xy, tick: new Date().getTime()});
@@ -86,8 +87,15 @@
 
     /**
      * Method: end
+     * Ends the dragging, start the kinetic.
      *
-     * Ends the dragging, start the kinetic.
+     * Parameters:
+     * xy - {<OpenLayers.Pixel>} The last position.
+     *
+     * Returns:
+     * {Object} An object with two properties: "speed", and "theta". The
+     *     "speed" and "theta" values are to be passed to the move 
+     *     function when starting the animation.
      */
     end: function(xy) {
         var last, now = new Date().getTime();
@@ -117,12 +125,13 @@
 
     /**
      * Method: move
-     *
      * Launch the kinetic move pan.
      *
      * Parameters:
-     * info - {Object}
-     * callback - arguments x, y (values to pan), end (is the last point)
+     * info - {Object} An object with two properties, "speed", and "theta".
+     *     These values are those returned from the "end" call.
+     * callback - {Function} Function called on every step of the animation,
+     *     receives x, y (values to pan), end (is the last point).
      */
     move: function(info, callback) {
         var v0 = info.speed;

Modified: sandbox/igorti/openlayers/tests/Control/Geolocate.html
===================================================================
--- sandbox/igorti/openlayers/tests/Control/Geolocate.html	2011-02-23 14:31:55 UTC (rev 11327)
+++ sandbox/igorti/openlayers/tests/Control/Geolocate.html	2011-02-23 14:42:54 UTC (rev 11328)
@@ -62,6 +62,31 @@
         map.removeControl(control);
         map.setCenter(centerLL);
     }
+    function test_getCurrentLocation(t) {
+        t.plan(5);
+        var control = new OpenLayers.Control.Geolocate({
+            geolocation: geolocation
+        });
+        map.addControl(control);
+        t.eq(control.getCurrentLocation(), false, 'getCurrentLocation return false if control hasnt been activated');
+        control.activate();
+        map.setCenter(centerLL);
+        t.eq(control.getCurrentLocation(), true, 'getCurrentLocation return true if control has been activated');
+        var center = map.getCenter();
+        t.eq(center.lon, 10, 'bound control sets the map lon when calling getCurrentLocation');
+        t.eq(center.lat, 10, 'bound control sets the map lat when calling getCurrentLocation');
+        control.deactivate();
+        map.removeControl(control);
+        map.setCenter(centerLL);
+        var control2 = new OpenLayers.Control.Geolocate({
+            geolocation: geolocation
+        });
+        map.addControl(control2);
+        t.eq(control2.getCurrentLocation(), false, 'getCurrentLocation return false if control is in watch mode');
+        control2.deactivate();
+        map.removeControl(control2);
+        map.setCenter(centerLL);
+    }
     function test_watch(t) {
         t.plan(2);
         var control = new OpenLayers.Control.Geolocate({

Modified: sandbox/igorti/openlayers/tests/Layer/EventPane.html
===================================================================
--- sandbox/igorti/openlayers/tests/Layer/EventPane.html	2011-02-23 14:31:55 UTC (rev 11327)
+++ sandbox/igorti/openlayers/tests/Layer/EventPane.html	2011-02-23 14:42:54 UTC (rev 11328)
@@ -58,11 +58,11 @@
 //         t.plan( 2 );    
 
         if (OpenLayers.BROWSER_NAME != "firefox" && OpenLayers.BROWSER_NAME != "mozilla") {
-          t.plan(4);
+            t.plan(4);
         } else {
-          t.plan(0);
-          t.debug_print("Firefox gives different results for different browsers on setMap on EventPane, so just don't run it for now.") 
-          return;
+            t.plan(0);
+            t.debug_print("Firefox gives different results for different browsers on setMap on EventPane, so just don't run it for now.") 
+            return;
         }
         var map = new OpenLayers.Map('map');
         
@@ -84,19 +84,23 @@
         layer2.getWarningHTML = function() { this.warning = true; return ""; }
 
         map.addLayer(layer2);
-        t.ok( !layer2.warning, "warning not registered on mapObject load" );
+        t.ok(!layer2.warning, "warning not registered on mapObject load");
 
-        map.events.register("mousemove", map, function () {
-            t.ok(true, "got mouse move");
+        var log = [];
+        map.events.register("mousemove", map, function(event) {
+            log.push(event);
         });
         
-        if( document.createEvent ) { // Mozilla
-          var evObj = document.createEvent('MouseEvents');
-          evObj.initEvent( 'mousemove', true, false );
-          layer.pane.dispatchEvent(evObj);
-        } else if( document.createEventObject ) { // IE
-          layer.pane.fireEvent('onmousemove');
+        if (document.createEvent) { // Mozilla
+            var evObj = document.createEvent('MouseEvents');
+            evObj.initEvent('mousemove', true, false);
+            layer.pane.dispatchEvent(evObj);
+        } else if(document.createEventObject) { // IE
+            layer.pane.fireEvent('onmousemove');
         }
+        
+        t.eq(log.length, 1, "got one event");
+        
     }
 
     function test_Layer_EventPane_setVisibility (t) {



More information about the Commits mailing list