<commit_before>angular
  .module('app')
  .controller('locatorToolController', [
    '$rootScope',
    '$scope',
    '$location',
    '$routeParams',
    'vendorService',
    'googleMapsService',
    '$timeout',
    function($rootScope, $scope, $location, $routeParams, Vendor, googleMaps, $timeout) {
       

       
        //google.maps.visualRefresh = true;
       
        // markers will be vendors that match out serarch! 
        $scope.markers = [];
        
        // this will be set to true any time there is a specific location
        // we can show distance from, ie: use has geolocated, or searched by text.
        $scope.hasLocation = false;
        
        $scope.map = {};
        
        $scope.map.clickedMarker = {
            latitude: null,
            longitude: null
        };
            
        $scope.map.infoWindow = {
            coords: {
                latitude: 30,
                longitude: -89
            },
            show: false
        };
        
        $scope.map.templatedInfoWindow = {
            coords: {
                latitude: 60,
                longitude: -95
            },
            show: true,
            templateUrl: 'templates/info.html',
            templateParameter: {
                message: 'passed in from the opener'
            }
        };
        
        // current setting: USA center
        $scope.map.center = {
            latitude: 40.4230,
            longitude: -98.7372
        };
        
        // default map zoom level
        $scope.map.zoom = 4;
        
        // get all vendors from API
        Vendor.getAll().then(function(response) {
            $scope.vendors = response;
        });
        
        // check for geo location support
        $scope.geolocationAvailable = navigator.geolocation ? true : false;
        
        // button to set map center based on geolocation
        // @todo we should add a marker here
        $scope.findMe = function () {
            
            if (!$scope.geolocationAvailable) return false;
                
            navigator.geolocation.getCurrentPosition(function (position) {
                $scope.map.center = {
                    latitude: position.coords.latitude,
                    longitude: position.coords.longitude
                };
                
                //setCenter(position.coords.latitude, position.coords.longitude);
                
                // create latLng object, which we need for distanc comparisons
                
                $scope.hasLocation = true;
                
                $scope.$apply();
                
                filterMarkers(); // refilter the markers based on new location
            });  
            
        };
       
        // search by text
        $scope.searchText = '';
        
        $scope.searchByText = function() {
            filterMarkers();      
        };
        $scope.clearText = function() {
            $scope.searchText = '';
            filterMarkers();      
        };
        
        
        // distances in miles
        $scope.distanceOptions = [100,500,1000,2000,'Any'];
        
        // input to set distance from user for results
        $scope.distanceFrom = 2000;
        
        // trigger the search
        $scope.setDistanceFrom = function(newDistance) {
            $scope.distanceFrom = newDistance;
            $scope.distanceFromInMeters = newDistance * 1000;
            filterMarkers(); // refilter the markers based on new location
        };
        
        // input to serach by Industry
        $scope.locationSearch = null;
        
        // function that will geo locate, and then
        $scope.findMyLocation = function() {
            console.log('User is searching by location:' + $scope.locationSearch);  
            googleMaps.geo($scope.locationSearch, 'locationSearch');
        };
        
        // callback from the geo lookup
        var listener1 = $rootScope.$on('event:geo-location-success', function(event, data, type) {
            // update center based on search 
            if(type && type === 'locationSearch') {
                //console.log(data);
                $scope.map.center = {
                    latitude: data.lat,
                    longitude: data.lng
                };
                
                console.log(data);
                
                //setCenter(position.coords.latitude, position.coords.longitude);
                
                $scope.hasLocation = true;
                
                //console.log($scope.map.center);
                filterMarkers();
                
                $scope.$apply();
            }
        });
        
        $rootScope.$on('$routeChangeSuccess', function() {
            //console.log('removing google callback ');
            listener1();
        });
        
        // watch for center change
        // watch for tags to change
        // loop and filter based on above, save filteredSet of markers
        function filterMarkers() {
        
            closeAllWindows();
            
            if(!$scope.vendors) {
                console.log('$scope.vendors is undefined, aborting!');
                return;
            }
            
        
            $timeout(function() {
                $scope.markers = [];
            
                console.log('Filtering markers...');
                
                _.each($scope.vendors, function(item) {
                    
                    // check if vendor has geo data!
                    if(!item.geo) return;
                    
                    
                    // first check for text based search
                    // if this doesn't match, we dont care how close the vendor is! 
                    if($scope.searchText.toLowerCase() && item.name.toLowerCase().indexOf($scope.searchText.toLowerCase()) === -1) return;
                    
                    
                    // check if distance is withing range
                    // @note that users can set "unlimited" distance
                    item.geo.distance = isMarkerWithinDistanceFromCenter($scope.map.center, item.geo, $scope.distanceFrom);
                    
                    //console.log(distance);
                    if ($scope.distanceFrom !== 'Any' && item.geo.distance === false) return;
                                    
                    // we need to create the marker from the vendor
                    var newMarker = {
                        latitude: item.geo.latitude,
                        longitude: item.geo.longitude,
                        label: item.name,
                        website: item.website,
                        distance: item.geo.distance, // gets miles
                        logo: item.logo.original,
                        businessAddress: item.businessAddress,
                        infoWindow: '<img class="img-medium" src="'+item.logo.original+'" />',
                        name: item.name,
                        destAddress: 'http://maps.google.com/maps?q=' + genereateSingleLineAddress(item.businessAddress)
                    };
                    
                    $scope.markers.push(newMarker);
                                
                });
                
                _.each($scope.markers,function(marker){
                        
                    closeAllWindows();
                    
                    marker.closeClick = function(){  
                        closeAllWindows();
                        console.log('CLOSING WINDOW....');                      
                        this.showWindow = false;
                        $scope.$apply();
                    };
                    <commit_msg>Assign markers to temp markers, to fix issues with $watch repeating too many times<commit_after>angular
  .module('app')
  .controller('locatorToolController', [
    '$rootScope',
    '$scope',
    '$location',
    '$routeParams',
    'vendorService',
    'googleMapsService',
    '$timeout',
    function($rootScope, $scope, $location, $routeParams, Vendor, googleMaps, $timeout) {
       

       
        //google.maps.visualRefresh = true;
       
        // markers will be vendors that match out serarch! 
        $scope.markers = [];
        
        // this will be set to true any time there is a specific location
        // we can show distance from, ie: use has geolocated, or searched by text.
        $scope.hasLocation = false;
        
        $scope.map = {};
        
        $scope.map.clickedMarker = {
            latitude: null,
            longitude: null
        };
            
        $scope.map.infoWindow = {
            coords: {
                latitude: 30,
                longitude: -89
            },
            show: false
        };
        
        $scope.map.templatedInfoWindow = {
            coords: {
                latitude: 60,
                longitude: -95
            },
            show: true,
            templateUrl: 'templates/info.html',
            templateParameter: {
                message: 'passed in from the opener'
            }
        };
        
        // current setting: USA center
        $scope.map.center = {
            latitude: 40.4230,
            longitude: -98.7372
        };
        
        // default map zoom level
        $scope.map.zoom = 4;
        
        // get all vendors from API
        Vendor.getAll().then(function(response) {
            $scope.vendors = response;
        });
        
        // check for geo location support
        $scope.geolocationAvailable = navigator.geolocation ? true : false;
        
        // button to set map center based on geolocation
        // @todo we should add a marker here
        $scope.findMe = function () {
            
            if (!$scope.geolocationAvailable) return false;
                
            navigator.geolocation.getCurrentPosition(function (position) {
                $scope.map.center = {
                    latitude: position.coords.latitude,
                    longitude: position.coords.longitude
                };
                
                //setCenter(position.coords.latitude, position.coords.longitude);
                
                // create latLng object, which we need for distanc comparisons
                
                $scope.hasLocation = true;
                
                $scope.$apply();
                
                filterMarkers(); // refilter the markers based on new location
            });  
            
        };
       
        // search by text
        $scope.searchText = '';
        
        $scope.searchByText = function() {
            filterMarkers();      
        };
        $scope.clearText = function() {
            $scope.searchText = '';
            filterMarkers();      
        };
        
        
        // distances in miles
        $scope.distanceOptions = [100,500,1000,2000,'Any'];
        
        // input to set distance from user for results
        $scope.distanceFrom = 2000;
        
        // trigger the search
        $scope.setDistanceFrom = function(newDistance) {
            $scope.distanceFrom = newDistance;
            $scope.distanceFromInMeters = newDistance * 1000;
            filterMarkers(); // refilter the markers based on new location
        };
        
        // input to serach by Industry
        $scope.locationSearch = null;
        
        // function that will geo locate, and then
        $scope.findMyLocation = function() {
            console.log('User is searching by location:' + $scope.locationSearch);  
            googleMaps.geo($scope.locationSearch, 'locationSearch');
        };
        
        // callback from the geo lookup
        var listener1 = $rootScope.$on('event:geo-location-success', function(event, data, type) {
            // update center based on search 
            if(type && type === 'locationSearch') {
                //console.log(data);
                $scope.map.center = {
                    latitude: data.lat,
                    longitude: data.lng
                };
                
                console.log(data);
                
                //setCenter(position.coords.latitude, position.coords.longitude);
                
                $scope.hasLocation = true;
                
                //console.log($scope.map.center);
                filterMarkers();
                
                $scope.$apply();
            }
        });
        
        $rootScope.$on('$routeChangeSuccess', function() {
            //console.log('removing google callback ');
            listener1();
        });
        
        // watch for center change
        // watch for tags to change
        // loop and filter based on above, save filteredSet of markers
        function filterMarkers() {
        
            closeAllWindows();
            
            if(!$scope.vendors) {
                console.log('$scope.vendors is undefined, aborting!');
                return;
            }
            
        
            $timeout(function() {
                $scope.markers = [];
                $scope.tempMarkers = [];
            
                console.log('Filtering markers...');
                console.log('Filtering markers..., there are ' + $scope.vendors.length + ' vendors');
                
                _.each($scope.vendors, function(item) {
                    
                    // check if vendor has geo data!
                    if(!item.geo) return;
                    
                    
                    // first check for text based search
                    // if this doesn't match, we dont care how close the vendor is! 
                    if($scope.searchText.toLowerCase() && item.name.toLowerCase().indexOf($scope.searchText.toLowerCase()) === -1) return;
                    
                    
                    // check if distance is withing range
                    // @note that users can set "unlimited" distance
                    item.geo.distance = isMarkerWithinDistanceFromCenter($scope.map.center, item.geo, $scope.distanceFrom);
                    
                    //console.log(distance);
                    if ($scope.distanceFrom !== 'Any' && item.geo.distance === false) return;
                                    
                    // we need to create the marker from the vendor
                    var newMarker = {
                        latitude: item.geo.latitude,
                        longitude: item.geo.longitude,
                        label: item.name,
                        website: item.website,
                        distance: item.geo.distance, // gets miles
                        logo: item.logo.original,
                        businessAddress: item.businessAddress,
                        infoWindow: '<img class="img-medium" src="'+item.logo.original+'" />',
                        name: item.name,
                        destAddress: 'http://maps.google.com/maps?q=' + genereateSingleLineAddress(item.businessAddress)
                    };
                    
                    $scope.tempMarkers.push(newMarker);
                                
                });
                
                console.log('THERE are now ' + $scope.tempMarkers.length + ' markers');
                $scope.markers = $scope.tempMarkers;
                _.each($scope.markers,function(marker){
                        
                    closeAllWindows();
                    
                    marker.closeClick = function(){  
                        closeAllWindows();
                        console.log('CLOSING WINDOW....');                      
                        this.showWindow = false;
                        $scope.$apply();
                    };
                    
{'fraction_non_alphanumeric': 0.09765305480400176, 'fraction_numerical': 0.005788712011577424, 'mean_word_length': 1.1217460953143772, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4556235', 'n_tokens_mistral': 3881, 'n_tokens_neox': 3633, 'n_words': 849}