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
This commit is contained in:
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user