Naimikan/angular-mapboxgl-directive

View on GitHub
src/directives/glMaxBounds.js

Summary

Maintainability
A
0 mins
Test Coverage
angular.module('mapboxgl-directive').directive('glMaxBounds', [function () {
    function mapboxGlMaxBoundsDirectiveLink (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('glMaxBounds', function (maxBounds) {
                if (angular.isArray(maxBounds) && maxBounds.length === 2) {
                    map.setMaxBounds(maxBounds);
                } else {
                    throw new Error('Invalid max bounds');
                }
            }, true);
        });
    }

    var directive = {
        restrict: 'A',
        scope: false,
        replace: false,
        require: '?^mapboxgl',
        link: mapboxGlMaxBoundsDirectiveLink
    };

    return directive;
}]);