Naimikan/angular-mapboxgl-directive

View on GitHub
src/directives/glMaxZoom.js

Summary

Maintainability
C
1 day
Test Coverage
angular.module('mapboxgl-directive').directive('glMaxZoom', [function () {
    function mapboxGlMaxZoomDirectiveLink (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('glMaxZoom', function (maxZoom) {
                if (angular.isNumber(maxZoom) && (maxZoom >= 0 || maxZoom <= 22)) {
                    map.setMaxZoom(maxZoom);
                } else {
                    throw new Error('Invalid max zoom');
                }
            }, true);
        });
    }

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

    return directive;
}]);