<commit_before>/**
 * Created with IntelliJ IDEA.
 * User: James
 * Date: 5/7/13
 * Time: 9:31 PM
 * To change this template use File | Settings | File Templates.
 */

var data = [
    {
        lat: 0,
        lng: 0,
        title:'Austin, TX',
        content: ''
    },
    {
        lat: 0,
        lng: 0,
        title:'McAllen, TX',
        content: ''
    },
    {
        lat: 0,
        lng: 0,
        title:'Dallas, TX',
        content: ''
    },
    {
        lat: 0,
        lng: 0,
        title:'San Antonio, TX',
        content: ''
    },
    {
        lat: 0,
        lng: 0,
        title:'Houston, TX',
        content: ''
    },
    {
        lat: 0,
        lng: 0,
        title:'El Paso, TX',
        content: ''
    },
    {
        lat: 0,
        lng: 0,
        title:'Laredo, TX',
        content: ''
    },
    {
        lat: 0,
        lng: 0,
        title:'Zilker Park, Austin, TX',
        content: ''
    }
];

var geocoder;

var getLatLngFromTitle = function(map, dataObject) {
    console.log('START getLatLngFromTitle()');
    geocoder.geocode({
            'address': dataObject.title
        },
        function(results, status) {
            if(status == google.maps.GeocoderStatus.OK) {
                dataObject.lat = results[0].geometry.location.lat();
                dataObject.lng = results[0].geometry.location.lng();

                console.log('Found result for ' + dataObject.title +
                    ', Lat:' + dataObject.lat +
                    ' Lng: ' + dataObject.lng);

                dataObject.content = '<h2>' + dataObject.title + '</h2>' +
                    '<p>Lat: ' + dataObject.lat +
                    ' Lng: ' + dataObject.lng + '</p>';

                console.log('Creating new marker for ' + dataObject.title +
                    ' at Lat: ' + dataObject.lat + ' Lng: ' + dataObject.lng);
                var x = new google.maps.Marker({
                    position: results[0].geometry.location,
                    map: map,
                    title: dataObject.title
                });

                var y = new google.maps.InfoWindow({
                    content: dataObject.content
                });

                google.maps.event.addListener(x, 'click', function() {
                    y.open(map, x);
                });
            }
            else {
                console.log('Could not find coordinates from title/address.');
            }
        });

    console.log('END getLatLngFromTitle()');
};

var init = function() {
    console.log('START init()');
    // Initialize the geocoding service, to convert addresses to coords.
    geocoder = new google.maps.Geocoder();

    // Initialize the map and roughly center it to the middle of the US.
    var o = {
        center: new google.maps.LatLng(40.924740, -98.339904),
        zoom: 4,
        mapTypeId: google.maps.MapTypeId.HYBRID
    };
    var m = new google.maps.Map(document.getElementById("map-canvas"), o);

    // For each data array element, create a geo-marker and info window.
    for(var i = 0; i < data.length; i++) {
        getLatLngFromTitle(m, data[i]);
    }

    console.log('END init()');
};

google.maps.event.addDomListener(window, 'load', init);<commit_msg>Added JSDoc comments and split the program into easy-to-understand functions.<commit_after>/**
 * @overview Contains the program's entire logic, divided into logical functions.
 * @copyright <NAME> 2013
 */

/**
 * The global array of objects containing coordinates and text data
 * describing various locations across the US.
 * @type {Array}
 */
var data = [
    {
        lat: 0,
        lng: 0,
        title:'Austin, TX',
        content: ''
    },
    {
        lat: 0,
        lng: 0,
        title:'McAllen, TX',
        content: ''
    },
    {
        lat: 0,
        lng: 0,
        title:'Dallas, TX',
        content: ''
    },
    {
        lat: 0,
        lng: 0,
        title:'San Antonio, TX',
        content: ''
    },
    {
        lat: 0,
        lng: 0,
        title:'Houston, TX',
        content: ''
    },
    {
        lat: 0,
        lng: 0,
        title:'El Paso, TX',
        content: ''
    },
    {
        lat: 0,
        lng: 0,
        title:'Laredo, TX',
        content: ''
    },
    {
        lat: 0,
        lng: 0,
        title:'<NAME>, Austin, TX',
        content: ''
    }
];

var geocoder = null;

/**
 * Creates a marker and InfoWindow and registers them onto the Map.
 * @param {object} map - The handle for the Google Maps HTML canvas.
 * @param {object} dataObject - Contains the coordinates and text data of a location.
 */
var createMarkerAndInfoWindow = function(map, dataObject) {
    console.log('START createMarkerAndInfoWindow()');
    console.log('Creating new marker for ' + dataObject.title +
        ' at Lat: ' + dataObject.lat + ' Lng: ' + dataObject.lng);

    // Create the marker and InfoWindow.
    var x = new google.maps.Marker({
        position: new google.maps.LatLng(dataObject.lat, dataObject.lng),
        map: map,
        title: dataObject.title
    });

    var y = new google.maps.InfoWindow({
        content: dataObject.content
    });

    // Register an even handler to open the InfoWindow when the marker is clicked.
    google.maps.event.addListener(x, 'click', function() {
        y.open(map, x);
    });

    console.log('END createMarkerAndInfoWindow()');
};

/**
 * Callback function that retrieves the geocoder response and creates a marker and InfoWindow.
 * @param {object} results - The geocoder JSON response object containing results.
 * @param {object} status - The geocoder status code for the request.
 * @param {object} map - The handle for the Google Maps HTML canvas.
 * @param {object} dataObject - Contains the coordinates and text data of a location.
 */
var geocoderRequestCallback = function(results, status, map, dataObject) {
    if(status == google.maps.GeocoderStatus.OK) {
        dataObject.lat = results[0].geometry.location.lat();
        dataObject.lng = results[0].geometry.location.lng();

        console.log('Found result for ' + dataObject.title +
            ', Lat:' + dataObject.lat +
            ' Lng: ' + dataObject.lng);

        // Format the text content to be displayed within the InfoWindow.
        dataObject.content = '<h2>' + dataObject.title + '</h2>' +
            '<p>Lat: ' + dataObject.lat +
            ' Lng: ' + dataObject.lng + '</p>';

        // Create and register the marker and InfoWindow onto the map.
        createMarkerAndInfoWindow(map, dataObject);
    }
    else {
        console.log('Could not find coordinates from title/address.');
    }
};

/**
 * Creates a geocoder search request to retrieve coordinates based off dataObject.title.
 * @param {object} map - The handle for the Google Maps HTML canvas.
 * @param {object} dataObject - Contains the coordinates and text data of a location.
 */
var requestLatLngFromTitle = function(map, dataObject) {
    console.log('START requestLatLngFromTitle()');
    geocoder.geocode({
            'address': dataObject.title
        },
        function(results, status) {
            geocoderRequestCallback(results, status, map, dataObject);
        }
    );

    console.log('END requestLatLngFromTitle()');
};

/**
 * The main function that is executed upon the window loading.
 */
var init = function() {
    console.log('START init()');
    // Initialize the geocoding service, to convert addresses to coords.
    geocoder = new google.maps.Geocoder();

    // Initialize the map and roughly center it to the middle of the US.
    var o = {
        center: new google.maps.LatLng(40.924740, -98.339904),
        zoom: 4,
        mapTypeId: google.maps.MapTypeId.HYBRID
    };
    var m = new google.maps.Map(document.getElementById("map-canvas"), o);

    // For each data element look up its coordinates based of its title,
    // and create a matching marker and InfoWindow.
    for(var i = 0; i < data.length; i++)
        requestLatLngFromTitle(m, data[i]);

    console.log('END init()');
};

// Register an event handler to run the main function upon window loading.
google.maps.event.addDomListener(window, 'load', init);
{'fraction_non_alphanumeric': 0.12774792379091354, 'fraction_numerical': 0.01074743527112848, 'mean_word_length': 1.9627351664254704, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3126688', 'n_tokens_mistral': 2519, 'n_tokens_neox': 2398, 'n_words': 689}