Merge pull request #1858 from elemoine/geolocation

Add change event to Geolocation
This commit is contained in:
Éric Lemoine
2014-03-17 09:32:08 +01:00
2 changed files with 5 additions and 4 deletions
+3 -2
View File
@@ -31,7 +31,8 @@ geolocation.bindTo('projection', view);
var track = new ol.dom.Input(document.getElementById('track')); var track = new ol.dom.Input(document.getElementById('track'));
track.bindTo('checked', geolocation, 'tracking'); track.bindTo('checked', geolocation, 'tracking');
geolocation.on('propertychange', function() { // update the HTML page when the position changes.
geolocation.on('change', function() {
$('#accuracy').text(geolocation.getAccuracy() + ' [m]'); $('#accuracy').text(geolocation.getAccuracy() + ' [m]');
$('#altitude').text(geolocation.getAltitude() + ' [m]'); $('#altitude').text(geolocation.getAltitude() + ' [m]');
$('#altitudeAccuracy').text(geolocation.getAltitudeAccuracy() + ' [m]'); $('#altitudeAccuracy').text(geolocation.getAltitudeAccuracy() + ' [m]');
@@ -39,13 +40,13 @@ geolocation.on('propertychange', function() {
$('#speed').text(geolocation.getSpeed() + ' [m/s]'); $('#speed').text(geolocation.getSpeed() + ' [m/s]');
}); });
// handle geolocation error.
geolocation.on('error', function(error) { geolocation.on('error', function(error) {
var info = document.getElementById('info'); var info = document.getElementById('info');
info.innerHTML = error.message; info.innerHTML = error.message;
info.style.display = ''; info.style.display = '';
}); });
var accuracyFeature = new ol.Feature(); var accuracyFeature = new ol.Feature();
accuracyFeature.bindTo('geometry', geolocation, 'accuracyGeometry'); accuracyFeature.bindTo('geometry', geolocation, 'accuracyGeometry');
+2 -2
View File
@@ -44,7 +44,7 @@ ol.GeolocationProperty = {
* // take the projection to use from the map's view * // take the projection to use from the map's view
* geolocation.bindTo('projection', map.getView()); * geolocation.bindTo('projection', map.getView());
* // listen to changes in position * // listen to changes in position
* geolocation.on('change:position', function(evt) { * geolocation.on('change', function(evt) {
* window.console.log(geolocation.getPosition()); * window.console.log(geolocation.getPosition());
* }); * });
* *
@@ -186,10 +186,10 @@ ol.Geolocation.prototype.positionChange_ = function(position) {
this.set(ol.GeolocationProperty.POSITION, projectedPosition); this.set(ol.GeolocationProperty.POSITION, projectedPosition);
this.set(ol.GeolocationProperty.SPEED, this.set(ol.GeolocationProperty.SPEED,
goog.isNull(coords.speed) ? undefined : coords.speed); goog.isNull(coords.speed) ? undefined : coords.speed);
var geometry = ol.sphere.WGS84.circle(this.position_, coords.accuracy); var geometry = ol.sphere.WGS84.circle(this.position_, coords.accuracy);
geometry.transform(this.transform_); geometry.transform(this.transform_);
this.set(ol.GeolocationProperty.ACCURACY_GEOMETRY, geometry); this.set(ol.GeolocationProperty.ACCURACY_GEOMETRY, geometry);
this.dispatchChangeEvent();
}; };