[OpenLayers-Commits] r12117 - trunk/openlayers/examples

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Tue Jun 21 08:47:58 EDT 2011


Author: pgiraud
Date: 2011-06-21 05:47:57 -0700 (Tue, 21 Jun 2011)
New Revision: 12117

Modified:
   trunk/openlayers/examples/geolocation.js
Log:
geolocation example : don't zoom to and pulsate circle more than once when watching position (ie. listening for locationupdated event), no functional change

Modified: trunk/openlayers/examples/geolocation.js
===================================================================
--- trunk/openlayers/examples/geolocation.js	2011-06-21 10:28:27 UTC (rev 12116)
+++ trunk/openlayers/examples/geolocation.js	2011-06-21 12:47:57 UTC (rev 12117)
@@ -47,6 +47,7 @@
 };
 
 var geolocate = new OpenLayers.Control.Geolocate({
+    bind: false,
     geolocationOptions: {
         enableHighAccuracy: false,
         maximumAge: 0,
@@ -54,7 +55,8 @@
     }
 });
 map.addControl(geolocate);
-geolocate.events.register("locationupdated",this,function(e) {
+var firstGeolocation = true;
+geolocate.events.register("locationupdated",geolocate,function(e) {
     vector.removeAllFeatures();
     var circle = new OpenLayers.Feature.Vector(
         OpenLayers.Geometry.Polygon.createRegularPolygon(
@@ -80,8 +82,12 @@
         ),
         circle
     ]);
-    map.zoomToExtent(vector.getDataExtent());
-    pulsate(circle);
+    if (firstGeolocation) {
+        map.zoomToExtent(vector.getDataExtent());
+        pulsate(circle);
+        firstGeolocation = false;
+        this.bind = true;
+    }
 });
 geolocate.events.register("locationfailed",this,function() {
     OpenLayers.Console.log('Location detection failed');
@@ -92,6 +98,7 @@
     geolocate.deactivate();
     $('track').checked = false;
     geolocate.watch = false;
+    firstGeolocation = true;
     geolocate.activate();
 };
 $('track').onclick = function() {
@@ -99,6 +106,7 @@
     geolocate.deactivate();
     if (this.checked) {
         geolocate.watch = true;
+        firstGeolocation = true;
         geolocate.activate();
     }
 };



More information about the Commits mailing list