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:
+11
-3
@@ -47,6 +47,7 @@ var pulsate = function(feature) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var geolocate = new OpenLayers.Control.Geolocate({
|
var geolocate = new OpenLayers.Control.Geolocate({
|
||||||
|
bind: false,
|
||||||
geolocationOptions: {
|
geolocationOptions: {
|
||||||
enableHighAccuracy: false,
|
enableHighAccuracy: false,
|
||||||
maximumAge: 0,
|
maximumAge: 0,
|
||||||
@@ -54,7 +55,8 @@ var geolocate = new OpenLayers.Control.Geolocate({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
map.addControl(geolocate);
|
map.addControl(geolocate);
|
||||||
geolocate.events.register("locationupdated",this,function(e) {
|
var firstGeolocation = true;
|
||||||
|
geolocate.events.register("locationupdated",geolocate,function(e) {
|
||||||
vector.removeAllFeatures();
|
vector.removeAllFeatures();
|
||||||
var circle = new OpenLayers.Feature.Vector(
|
var circle = new OpenLayers.Feature.Vector(
|
||||||
OpenLayers.Geometry.Polygon.createRegularPolygon(
|
OpenLayers.Geometry.Polygon.createRegularPolygon(
|
||||||
@@ -80,8 +82,12 @@ geolocate.events.register("locationupdated",this,function(e) {
|
|||||||
),
|
),
|
||||||
circle
|
circle
|
||||||
]);
|
]);
|
||||||
map.zoomToExtent(vector.getDataExtent());
|
if (firstGeolocation) {
|
||||||
pulsate(circle);
|
map.zoomToExtent(vector.getDataExtent());
|
||||||
|
pulsate(circle);
|
||||||
|
firstGeolocation = false;
|
||||||
|
this.bind = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
geolocate.events.register("locationfailed",this,function() {
|
geolocate.events.register("locationfailed",this,function() {
|
||||||
OpenLayers.Console.log('Location detection failed');
|
OpenLayers.Console.log('Location detection failed');
|
||||||
@@ -92,6 +98,7 @@ $('locate').onclick = function() {
|
|||||||
geolocate.deactivate();
|
geolocate.deactivate();
|
||||||
$('track').checked = false;
|
$('track').checked = false;
|
||||||
geolocate.watch = false;
|
geolocate.watch = false;
|
||||||
|
firstGeolocation = true;
|
||||||
geolocate.activate();
|
geolocate.activate();
|
||||||
};
|
};
|
||||||
$('track').onclick = function() {
|
$('track').onclick = function() {
|
||||||
@@ -99,6 +106,7 @@ $('track').onclick = function() {
|
|||||||
geolocate.deactivate();
|
geolocate.deactivate();
|
||||||
if (this.checked) {
|
if (this.checked) {
|
||||||
geolocate.watch = true;
|
geolocate.watch = true;
|
||||||
|
firstGeolocation = true;
|
||||||
geolocate.activate();
|
geolocate.activate();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user