From 82d2fa373a90dcc0ea0752bf92ca397a92bd39bb Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Mon, 27 May 2013 12:08:03 +0200 Subject: [PATCH] Dispatch an error on Geolocation failure --- examples/geolocation.html | 5 +++-- examples/geolocation.js | 6 ++++++ src/ol/geolocation.js | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/examples/geolocation.html b/examples/geolocation.html index 65e32a4e7b..3a532be712 100644 --- a/examples/geolocation.html +++ b/examples/geolocation.html @@ -53,8 +53,9 @@
geolocation, openstreetmap
- - +
+ +
diff --git a/examples/geolocation.js b/examples/geolocation.js index 8b58c72807..8d855ab0a2 100644 --- a/examples/geolocation.js +++ b/examples/geolocation.js @@ -36,6 +36,12 @@ geolocation.addEventListener('accuracy_changed', function() { title: this.getAccuracy() + 'm from this point' }); }); +geolocation.on('error', function(error) { + var info = document.getElementById('info'); + info.innerHTML = error.message; + info.style.display = ''; +}); + $('#locate').click(function() { geolocation.setTracking(true); diff --git a/src/ol/geolocation.js b/src/ol/geolocation.js index 1e12155e17..e9d12f32f8 100644 --- a/src/ol/geolocation.js +++ b/src/ol/geolocation.js @@ -1,10 +1,10 @@ // FIXME handle geolocation not supported -// FIXME handle geolocation errors goog.provide('ol.Geolocation'); goog.provide('ol.GeolocationProperty'); goog.require('goog.events'); +goog.require('goog.events.EventType'); goog.require('goog.math'); goog.require('ol.Coordinate'); goog.require('ol.Object'); @@ -163,6 +163,8 @@ ol.Geolocation.prototype.positionChange_ = function(position) { * @param {GeolocationPositionError} error error object. */ ol.Geolocation.prototype.positionError_ = function(error) { + error.type = goog.events.EventType.ERROR; + this.dispatchEvent(error); };