/**
 * Created by joannarosedelmar on 10/5/15.
 */
'use strict';

/* Services */
myApp.factory( 'Map', function( $rootScope, $log ){

    return {

        //clear all
        clear: function (){
            $rootScope.map = null;
            $rootScope.options = null;
            $rootScope.marker = null;
        },

        create: function( center ){

            $rootScope.map = { center: { latitude: center.lat, longitude: center.lng }, zoom: 12 };
            $rootScope.options = { scrollwheel: false };
            $rootScope.marker = {
                id: 0,
                coords: {
                    latitude: center.lat,
                    longitude: center.lng
                },
                options: { draggable: true },
                events: {
                    dragend: function (marker, eventName, args) {
                        $log.log('marker dragend');
                        var lat = marker.getPosition().lat();
                        var lon = marker.getPosition().lng();
                        $log.log(lat);
                        $log.log(lon);

                        marker.options = {
                            draggable: true,
                            //labelContent: "lat: " + $scope.marker.coords.latitude + ' ' + 'lon: ' + $scope.marker.coords.longitude,
                            labelAnchor: "100 0",
                            labelClass: "marker-labels"
                            };
                        }
                    }
                };

            $rootScope.$broadcast( 'Map.create' );
            }

    }


});