src/directives/glBearing.js
angular.module('mapboxgl-directive').directive('glBearing', [function () {
function mapboxGlBearingDirectiveLink (scope, element, attrs, controller) {
if (!controller) {
throw new Error('Invalid angular-mapboxgl-directive controller');
}
var mapboxglScope = controller.getMapboxGlScope();
controller.getMap().then(function (map) {
mapboxglScope.$watch('glBearing', function (bearingObject) {
if (angular.isDefined(bearingObject)) {
if (angular.isNumber(bearingObject.value)) {
map.setBearing(bearingObject.value, bearingObject.eventData);
} else {
throw new Error('Invalid bearing');
}
}
}, true);
});
}
var directive = {
restrict: 'A',
scope: false,
replace: false,
require: '?^mapboxgl',
link: mapboxGlBearingDirectiveLink
};
return directive;
}]);