osm-directive.js 1.16 KB
angular.module('focaAdminSeguimiento').directive('osm', function() {
    return {
        restrict: 'E',
        link: function(scope, el, attrs) {
            var contenedor = document.createElement('div');
            el.append(contenedor);
            scope.map = L.map(contenedor).setView([attrs.latitud, attrs.longitud], attrs.zoom);
            L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(scope.map);
        },
        controller: function($scope) {
            $scope.$watch('marcadores', function(valorNuevo) {
                marcadores = $scope.marcadores;
                mapa = $scope.map;
                angular.forEach($scope.marcadores, function(marcador) {
                    L.marker([marcador.latitud, marcador.longitud]).addTo($scope.map)
                        .bindPopup(
                            "Actividad: " + marcador.actividad + '<br/>' +
                            'Fecha: ' + marcador.fecha
                        ).openPopup();
                });
            });
        },
        scope: {
            latitud: '=',
            longitud: '=',
            zoom: '=',
            marcadores: '='
        }
    };
});