<commit_before>MainController = ($scope, $http) ->
    isFirstIteration = true
    iterator = 0
    $scope.speed = 0
    $scope.limit = 0

    _notSupported = () ->
        window.alert 'You need to accept geolocation to use this app'

    _handleGeolocation = (position) ->
        if isFirstIteration
            _createMap(position.coords)
            isFirstIteration = false
        
        if iterator % 10 is 0
            _getSpeedLimit position.coords
        
        _updateUserInfo position.coords

    _createMap = (coords) ->
        options =
            center: new google.maps.LatLng(coords.latitude, coords.longitude)
            replace: true
            zoom: 17
            mapTypeId: google.maps.MapTypeId.ROADMAP

        map = new google.maps.Map(document.getElementById('map-canvas'), options)

    _getSpeedLimit = (coords) ->
        iterator++
        options =
            method: 'GET'
            url: '/api/speed-limit'
            params:
                latitude: coords.latitude
                longitude: coords.longitude

        $http(options)
            .success((result) ->
                $scope.limit = result.data.limit
            )
            .error (status, error) ->
                console.log 'error', status, error
        
    _updateUserInfo = (coords) ->
        $scope.$apply () ->
            $scope.coords = coords
            $scope.speed = Math.ceil(window.parseFloat(coords.speed) * 3.6) if coords.speed

    initialize = () ->
        window.navigator.geolocation.watchPosition _handleGeolocation, _notSupported, {enableHighAccuracy: true}
    
    initialize()

module.exports = MainController<commit_msg>start with shapes<commit_after>MainController = ($scope, $http) ->
    isFirstIteration = true
    $scope.speed = 0
    $scope.limit = 0
    mapsApi = google.maps

    _notSupported = () ->
        window.alert 'You need to accept geolocation to use this app'

    _handleGeolocation = (position) ->
        if isFirstIteration
            _createMap position.coords
            isFirstIteration = false
        
        # _getSpeedCameraAreas $scope.map.getBounds()
        # _IsInDangerZone position.coords
        # _getSpeedLimit position.coords
        _updateMap position
        _updateUserInfo position.coords

    _createMap = (coords) ->
        mapOptions =
            center: new mapsApi.LatLng(coords.latitude, coords.longitude)
            replace: true
            zoom: 15
            mapTypeId: google.maps.MapTypeId.ROADMAP
            # draggable: false

        $scope.map = new mapsApi.Map(document.getElementById('map-canvas'), mapOptions)

    _getSpeedLimit = (coords) ->
        options =
            method: 'GET'
            url: '/api/speed-limit'
            params:
                latitude: coords.latitude
                longitude: coords.longitude

        $http(options)
            .success((result) ->
                $scope.limit = result.data.limit
            )
            .error (status, error) ->
                console.log 'error', status, error

    _updateMap = (position) ->
        $scope.map.setCenter(new mapsApi.LatLng(position.coords.latitude, position.coords.longitude))
        $scope.map.setHeading position.coords.heading
        
    _getSpeedCameraAreas = (bounds) ->
        # options =
        #     method: 'GET'
        #     url: '/'
        # $http options

        # for each polygons,
        # if the polygon hasn't been drawn already
        # remove last point from polygon and add polygon object in array
        # do
        polygonOptions =
            map: $scope.map
            paths: [
                [
                    new mapsApi.LatLng(46.89227,-71.212867) #1
                    new mapsApi.LatLng(46.89727  ,  -71.205593) #3
                    new mapsApi.LatLng(46.891551 ,  -71.212116) #4
                    # remove last point from polygon, and for each point in polygon, create new LatLng
                ]
            ]
            fillColor: 'red'
            strokeOpacity: 0.5
            geodesic: true
        new mapsApi.Polygon(polygonOptions)

    _IsInDangerZone = (coords) ->
        # TODO: get the shit with $http

    _updateUserInfo = (coords) ->
        $scope.$apply () ->
            $scope.coords = coords
            $scope.speed = Math.ceil(window.parseFloat(coords.speed) * 3.6) if coords.speed

    initialize = () ->
        window.navigator.geolocation.watchPosition _handleGeolocation, _notSupported, {enableHighAccuracy: true}
    
    initialize()

module.exports = MainController
{'fraction_non_alphanumeric': 0.09518599562363239, 'fraction_numerical': 0.014660831509846827, 'mean_word_length': 1.7420515896820636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 1, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2950313', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1276, 'n_words': 282}