[OpenLayers-Commits] r11315 - in trunk/openlayers:
lib/OpenLayers/Control tests/Control
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Wed Feb 23 08:33:14 EST 2011
Author: pgiraud
Date: 2011-02-23 05:33:14 -0800 (Wed, 23 Feb 2011)
New Revision: 11315
Modified:
trunk/openlayers/lib/OpenLayers/Control/Geolocate.js
trunk/openlayers/tests/Control/Geolocate.html
Log:
Adding getCurrentLocation API method so that application can get the location anytime, p=aabt, r=elemoine, (Closes #3090)
Modified: trunk/openlayers/lib/OpenLayers/Control/Geolocate.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Control/Geolocate.js 2011-02-23 13:24:27 UTC (rev 11314)
+++ trunk/openlayers/lib/OpenLayers/Control/Geolocate.js 2011-02-23 13:33:14 UTC (rev 11315)
@@ -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: trunk/openlayers/tests/Control/Geolocate.html
===================================================================
--- trunk/openlayers/tests/Control/Geolocate.html 2011-02-23 13:24:27 UTC (rev 11314)
+++ trunk/openlayers/tests/Control/Geolocate.html 2011-02-23 13:33:14 UTC (rev 11315)
@@ -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({
More information about the Commits
mailing list