From 0bfb6f53bf6076636564a7ec1a483680430b3a46 Mon Sep 17 00:00:00 2001 From: pgiraud Date: Tue, 21 Jun 2011 12:47:57 +0000 Subject: [PATCH] geolocation example : don't zoom to and pulsate circle more than once when watching position (ie. listening for locationupdated event), no functional change git-svn-id: http://svn.openlayers.org/trunk/openlayers@12117 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/geolocation.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/examples/geolocation.js b/examples/geolocation.js index e1c3320bad..1afc12d997 100644 --- a/examples/geolocation.js +++ b/examples/geolocation.js @@ -47,6 +47,7 @@ var pulsate = function(feature) { }; var geolocate = new OpenLayers.Control.Geolocate({ + bind: false, geolocationOptions: { enableHighAccuracy: false, maximumAge: 0, @@ -54,7 +55,8 @@ var geolocate = new OpenLayers.Control.Geolocate({ } }); 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 @@ geolocate.events.register("locationupdated",this,function(e) { ), 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 @@ $('locate').onclick = function() { geolocate.deactivate(); $('track').checked = false; geolocate.watch = false; + firstGeolocation = true; geolocate.activate(); }; $('track').onclick = function() { @@ -99,6 +106,7 @@ $('track').onclick = function() { geolocate.deactivate(); if (this.checked) { geolocate.watch = true; + firstGeolocation = true; geolocate.activate(); } };