Merge pull request #8731 from fredj/GeolocationError

Dispatch a GeolocationError in Geolocation
This commit is contained in:
Frédéric Junod
2018-09-27 16:56:42 +02:00
committed by GitHub

View File

@@ -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));
}
/**