Skip to content

Commit e20e2d9

Browse files
committed
Update geolocation version
1 parent 16f0dc1 commit e20e2d9

3 files changed

Lines changed: 33 additions & 15 deletions

File tree

Samples/Device Sensors/Geolocation control options/Geolocation control options.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@
5252
//Add events to the control.
5353
map.events.add('geolocationerror', geolocationControl, displayEventInfo);
5454
map.events.add('geolocationsuccess', geolocationControl, displayEventInfo);
55-
map.events.add('compassheadingchanged', geolocationControl, (e) => {
56-
displayEventInfo(`Compass heading: ${e}`);
57-
});
55+
map.events.add('compassheadingchanged', geolocationControl, displayEventInfo);
5856

5957
//Add control and a style control to the map.
6058
map.controls.add([new atlas.control.StyleControl(), geolocationControl], {

Static/lib/azure-maps/azure-maps-geolocation-control.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
azure-maps-geolocation-control Version: 0.0.4
2+
azure-maps-geolocation-control Version: 1.0.0
33
44
MIT License
55
@@ -300,7 +300,14 @@ MIT License
300300
map.setCamera(opt);
301301
}
302302
}
303-
self._invokeEvent('geolocationsuccess', lastKnownPosition);
303+
var args = {
304+
type: 'geolocationsuccess',
305+
feature: lastKnownPosition,
306+
};
307+
if (!isNaN(self._lastCompassHeading)) {
308+
args.compassHeading = self._lastCompassHeading;
309+
}
310+
self._invokeEvent('geolocationsuccess', args);
304311
}
305312
};
306313
/**
@@ -309,7 +316,10 @@ MIT License
309316
*/
310317
_this._onGpsError = function (error) {
311318
//Don't do anything other than report the error. Often it will be that there was a timeout when getting the users location.
312-
_this._invokeEvent('geolocationerror', error);
319+
_this._invokeEvent('geolocationerror', {
320+
type: 'geolocationerror',
321+
error: error
322+
});
313323
};
314324
/**
315325
* An event handler for when the device orientation changes. This is used to update the compass heading.
@@ -347,7 +357,14 @@ MIT License
347357
self._compassEventUpdateScheduled = true;
348358
//Throttle.
349359
setTimeout(function () {
350-
self._invokeEvent('compassheadingchanged', h_1);
360+
var args = {
361+
type: 'compassheadingchanged',
362+
compassHeading: h_1
363+
};
364+
if (self._lastKnownPosition) {
365+
args.feature = self._lastKnownPosition;
366+
}
367+
self._invokeEvent('compassheadingchanged', args);
351368
self._compassEventUpdateScheduled = false;
352369
}, self._options.compassEventThrottleDelay);
353370
}
@@ -472,11 +489,14 @@ MIT License
472489
//Device doesn't support getting position.
473490
//@ts-ignore
474491
self._invokeEvent('geolocationerror', {
475-
code: 2,
476-
message: 'Geolocation API not supported by device.',
477-
PERMISSION_DENIED: 1,
478-
POSITION_UNAVAILABLE: 2,
479-
TIMEOUT: 3
492+
type: 'geolocationerror',
493+
error: {
494+
code: 2,
495+
message: 'Geolocation API not supported by device.',
496+
PERMISSION_DENIED: 1,
497+
POSITION_UNAVAILABLE: 2,
498+
TIMEOUT: 3
499+
}
480500
});
481501
}
482502
});

0 commit comments

Comments
 (0)