mobileMeasureAreaComponent.$inject = ['gmfMobileMeasureAreaTemplateUrl'];
// The MIT License (MIT)
//
// Copyright (c) 2018-2024 Camptocamp SA
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import angular from 'angular';
import ngeoMiscFilters from 'ngeo/misc/filters';
import ngeoInteractionMeasureAreaMobile from 'ngeo/interaction/MeasureAreaMobile';
import { MeasueMobileBaseController } from 'gmf/mobile/measure/baseComponent';
import { buildStyle } from 'ngeo/options';
import htmlTemplate from './baseComponent.html';
/**
 * @type {angular.IModule}
 * @hidden
 */
const myModule = angular.module('gmfMobileMeasureArea', [ngeoMiscFilters.name]);
myModule.value('gmfMobileMeasureAreaTemplateUrl', 
/**
 * @param {JQuery} element Element.
 * @param {angular.IAttributes} attrs Attributes.
 * @returns {string} The template url.
 */
(element, attrs) => {
    const templateUrl = attrs.gmfMobileMeasureAreaTemplateurl;
    return templateUrl !== undefined ? templateUrl : 'gmf/measure/areaComponent';
});
myModule.run(
/**
 * @param {angular.ITemplateCacheService} $templateCache
 */
[
    '$templateCache',
    ($templateCache) => {
        // @ts-ignore: webpack
        $templateCache.put('gmf/measure/areaComponent', htmlTemplate);
    },
]);
/**
 * Provide a directive to do a area measure on the mobile devices.
 *
 * Example:
 *
 *      <div gmf-mobile-measurearea
 *        gmf-mobile-measurearea-active="ctrl.measureAreaActive"
 *        gmf-mobile-measurearea-map="::ctrl.map">
 *      </div>
 *
 * @htmlAttribute {boolean} gmf-mobile-measurearea-active Used to active
 * or deactivate the component.
 * @htmlAttribute {import('ol/Map').default} gmf-mobile-measurearea-map The map.
 * @param {string|function(JQuery=, angular.IAttributes=):string} gmfMobileMeasureAreaTemplateUrl
 *     Template URL for the directive.
 * @returns {angular.IDirective} The Directive Definition Object.
 * @ngdoc directive
 * @ngname gmfMobileMeasureArea
 */
function mobileMeasureAreaComponent(gmfMobileMeasureAreaTemplateUrl) {
    return {
        restrict: 'A',
        scope: {
            'active': '=gmfMobileMeasureareaActive',
            'map': '=gmfMobileMeasureareaMap',
        },
        controller: 'GmfMobileMeasureAreaController as ctrl',
        bindToController: true,
        templateUrl: gmfMobileMeasureAreaTemplateUrl,
        /**
         * @param {angular.IScope} scope Scope.
         * @param {JQuery} element Element.
         * @param {angular.IAttributes} attrs Attributes.
         * @param {angular.IController} [controller] Controller.
         */
        link: (scope, element, attrs, controller) => {
            if (!controller) {
                throw new Error('Missing controller');
            }
            controller.init();
        },
    };
}
myModule.directive('gmfMobileMeasurearea', mobileMeasureAreaComponent);
/**
 * @hidden
 */
export class Controller extends MeasueMobileBaseController {
    /**
     * @param {angular.IScope} $scope Angular scope.
     * @param {angular.IFilterService} $filter Angular filter
     * @param {angular.gettext.gettextCatalog} gettextCatalog Gettext catalog.
     * @param {import('gmf/options').gmfMobileMeasureAreaOptions} gmfMobileMeasureAreaOptions The options.
     */
    constructor($scope, $filter, gettextCatalog, gmfMobileMeasureAreaOptions) {
        super($scope, $filter, gettextCatalog);
        /**
         * @type {import('gmf/options').gmfMobileMeasureAreaOptions}
         */
        this.options = gmfMobileMeasureAreaOptions;
        /**
         * @type {?import('ngeo/interaction/MeasureAreaMobile').default}
         */
        this.measure = null;
    }
    /**
     * Initialize the controller.
     */
    init() {
        this.measure = new ngeoInteractionMeasureAreaMobile(this.filter('ngeoUnitPrefix'), this.gettextCatalog, {
            precision: this.options.precision || 2,
            sketchStyle: buildStyle(this.options.sketchStyle),
        });
        super.init();
    }
    /**
     * Add current sketch point to line measure
     */
    addPoint() {
        if (!this.drawInteraction) {
            throw new Error('Missing drawInteraction');
        }
        this.drawInteraction.addToDrawing();
    }
    /**
     * Clear the sketch feature
     */
    clear() {
        if (!this.drawInteraction) {
            throw new Error('Missing drawInteraction');
        }
        this.drawInteraction.clearDrawing();
    }
    /**
     * Finish line measure
     */
    finish() {
        if (!this.drawInteraction) {
            throw new Error('Missing drawInteraction');
        }
        this.drawInteraction.finishDrawing();
    }
    /**
     * Deactivate the directive.
     */
    deactivate() {
        this.active = false;
    }
}
Controller.$inject = ['$scope', '$filter', 'gettextCatalog', 'gmfMobileMeasureAreaOptions'];
myModule.controller('GmfMobileMeasureAreaController', Controller);
export default myModule;
//# sourceMappingURL=areaComponent.js.map