From 39951a792dfb42fb62809859fe7ce770546549de Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 27 Sep 2018 16:36:14 +0200 Subject: [PATCH] Dispatch a GeolocationError in Geolocation See https://github.com/openlayers/openlayers/pull/8657#discussion_r219051918 --- src/ol/Geolocation.js | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/ol/Geolocation.js b/src/ol/Geolocation.js index 2cac07da18..1ccad7a123 100644 --- a/src/ol/Geolocation.js +++ b/src/ol/Geolocation.js @@ -4,6 +4,7 @@ import GeolocationProperty from './GeolocationProperty.js'; import BaseObject, {getChangeEventType} from './Object.js'; import {listen} from './events.js'; +import Event from './events/Event.js'; import EventType from './events/EventType.js'; import {circular as circularPolygon} from './geom/Polygon.js'; import {GEOLOCATION} from './has.js'; @@ -11,6 +12,30 @@ import {toRadians} from './math.js'; import {get as getProjection, getTransformFromProjections, identityTransform} from './proj.js'; +/** + * @classdesc + * Events emitted on Geolocation error. + */ +class GeolocationError extends Event { + /** + * @param {PositionError} error error object. + */ + constructor(error) { + super(EventType.ERROR); + + /** + * @type {number} + */ + this.code = error.code; + + /** + * @type {string} + */ + this.message = error.message; + } +} + + /** * @typedef {Object} Options * @property {boolean} [tracking=false] Start Tracking right after @@ -174,12 +199,8 @@ class Geolocation extends BaseObject { * @param {PositionError} error error object. */ positionError_(error) { - const event = { - type: EventType.ERROR, - target: undefined - }; this.setTracking(false); - this.dispatchEvent(event); + this.dispatchEvent(new GeolocationError(error)); } /**