Source: managers/PontoMovelManager.js

/**
 * @ngdoc managers
 * @name PontoMovelManager
 * @module s4c.managers.PontoMovelManager
 *
 * @description
 * `PontoMovelManager` Componente para comunicação entre uma página html qualquer e o controller da diretiva
 * 
 * 
 */
(function () {
    'use strict';

    function PontoMovelManager(MainState, $q, $mdDialog, MapaService) {
        var layersPontoMovel = new L.LayerGroup([]);
        var subItens = new L.LayerGroup([]);

        return {
            'ativo': false,
            'activeWindow': false,
            'top': 10,
            'right': 10,
            'data': {},
            'pontoMovelAtivo': null,
            'pontoMovelMarkerAtivo': null,
            'posicoesER': [],
            'historicoPosicoesER': [],
            'subItens': subItens,
            'layersPontoMovel': layersPontoMovel,
            'elementoRastreavel': {},

            /**
             * @method abrirPontoMovel
             * @param {*} id 
             * @param {*} ponto 
             */
            'abrirPontoMovel': function (id, ponto) {
                this.ativo = true;
                var pontoMovel = MainState.getDirective('pontoMovel');
                pontoMovel.buscarPontoMovel(id, ponto);
            },

            /**
             * @method carregarPontosMoveisPorTipo
             * @param {*} id 
             */
            'carregarPontosMoveisPorTipo': function (id) {
                var pontoMovel = MainState.getDirective('pontoMovel');
                pontoMovel.buscarPontosMoveisPorTipo(id);
            },

            /**
             * @method voarParaSubItem
             * @param {*} data 
             * @param {*} obj 
             */
            'voarParaSubItem': function (data, obj) {
                var coords;

                MainState.managers.HabilitarCamadasManager.habilitarCamadas(obj);

                if (typeof obj.geojson === 'string') {
                    coords = JSON.parse(obj.geojson);
                } else {
                    coords = obj.geojson;
                }
                //var coords2 = JSON.parse(data.poiGeometricoBuffer);
                //var centroid = turf.centroid(coords2);
                MapaService.destacarSubItem(coords);
            },

            /**
             * @method fechar
             * @param {*} force 
             */
            'fechar': function (force) {
                var self = this;

                if (!force) {
                    self.ativo = false;
                } else {
                    mapa.changeClass(false);
                    self.ativo = false;
                }

                var pontoMovel = MainState.getDirective('pontoMovel');
                pontoMovel.fechar();
                MapaService.removerPoiClicado();
                MapaService.removerLinhas();
                MapaService.removerLayers(subItens.getLayers());
                subItens.clearLayers();
            }
        };
    }

    PontoMovelManager.$inject = [
        'MainState',
        '$q',
        '$mdDialog',
        'MapaService'
    ];

    angular.module('s4c.managers')
        .service('PontoMovelManager', PontoMovelManager);
})();