<commit_before>/*
1. Assume a sample large (50K items) JSON data set (e.g USA users for a site with location information)
2. Render a Google map, with pins shown for each state (e.g X users from California)
3. On zoom in, show the pins for each city (e.g X users from Palo Alto)
4. On zoom in further, show the pins for each zip code.
5. On zoom out, show the appropriate pins per the zoom level
 */

/*! @license
 *  Project: Buttons
 *  Description: Google Map Interface which extends to multi market
 *  Author: <NAME>
 *  Date : 26/03/2015 (DD/MM/YYYY)
 *  License: Apache License v2.0
 */

// the semi-colon before function invocation is a safety net against concatenated
// scripts and/or other plugins which may not be closed properly.
;
(function($, window, document, undefined) {

    var MarkerUtil = {

            markers: [],
            bounds: new google.maps.LatLngBounds(),
            geocoder: new google.maps.Geocoder(),

            initMarkers: function(type) {
                this.processMarker(mappedJson[type], type);
            },

            processMarker: function(interator, type) {
                var keys = Object.keys(interator);
                $(keys).each(function(index, key) {
                    /*jshint unused:true*/
                    var LatLng = interator[key].LatLng;
                    LatLng ? this.addMarker(LatLng) : this.getLongLatInfo(key, type);
                }.bind(this));
            },

            getLongLatInfo: function(query, type) {
                var address = query;

                this.geocoder.geocode({
                    "address": address
                }, this.putMarker.bind(this, type, query));
            },
            putMarker: function(type, query, results, status) {

                var position;

                if (status === google.maps.GeocoderStatus.OK) {

                    position = results[0].geometry.location;
                    saveLongLatInfo(type, query, position);
                    this.addMarker(position);

                } else {
                    alert("Geocode was not successful for the following reason: " + status);
                }
            },

            addMarker: function(position) {
                var marker;

                marker = new google.maps.Marker({
                    map: map,
                    position: position
                });

                this.markers.push(marker);
                //this.addBounds(marker);

            },
            // Removes the markers from the map, but keeps them in the array.
            clearMarkers: function() {
                this.setAllMap(null);
                this.markers = [];
            },

            // Sets the map on all markers in the array.
            setAllMap: function(map) {
                for (var i = 0; i < this.markers.length; i++) {
                    this.markers[i].setMap(map);
                }
            },

            addBounds: function(marker) {
                this.bounds.extend(marker.position);
            },

            fitBound: function() {
                //map.fitBounds(this.bounds);
            }
        },

        map,
        mappedJson = {},
        DELIMITOR = ",",
        ZOOM_LEVEL_MAP = {
            "4": "state",
            "5": "city",
            "6": "zip"
        },
        ZOOM_LEVEL = 4;

    function initialize() {
        processJSON();
        var mapOptions = {
            zoom: ZOOM_LEVEL,
            center: new google.maps.LatLng(20.593684, 78.962880)
        };
        map = new google.maps.Map(document.getElementById("map-canvas"),
            mapOptions);

        initListerners();
        MarkerUtil.initMarkers(ZOOM_LEVEL_MAP[ZOOM_LEVEL]);
    }

    function initListerners() {
        google.maps.event.addListener(map, "zoom_changed", zoomChangedcallBack);
    }

    function zoomChangedcallBack() {
        var zoomLevel = map.getZoom(),
            typeOfZoom = ZOOM_LEVEL_MAP[zoomLevel];

        if (!typeOfZoom) {
            return;
        }

        MarkerUtil.clearMarkers();
        MarkerUtil.initMarkers(typeOfZoom);
        //map.setCenter(myLatLng);
        //infowindow.setContent('Zoom: ' + zoomLevel);
    }

    function getJSON() {
        var response = [{
            userId: 1,
            locationDetails: {
                state: {
                    value: "Karnataka",
                    longLat: [0.9876, 0.9988]
                },
                city: {
                    value: "Bangalore",
                    longLat: []
                },
                zipCode: {
                    value: 560103,
                    longLat: []
                }
            }

        }, {
            userId: 1,
            locationDetails: {<commit_msg>Adding Content window To Markers<commit_after>/*
1. Assume a sample large (50K items) JSON data set (e.g USA users for a site with location information)
2. Render a Google map, with pins shown for each state (e.g X users from California)
3. On zoom in, show the pins for each city (e.g X users from Palo Alto)
4. On zoom in further, show the pins for each zip code.
5. On zoom out, show the appropriate pins per the zoom level
 */

/*! @license
 *  Project: Buttons
 *  Description: Google Map Interface which extends to multi market
 *  Author: <NAME>
 *  Date : 26/03/2015 (DD/MM/YYYY)
 *  License: Apache License v2.0
 */

// the semi-colon before function invocation is a safety net against concatenated
// scripts and/or other plugins which may not be closed properly.
;
(function($, window, document, undefined) {

    var MarkerUtil = {

            markers: [],
            bounds: new google.maps.LatLngBounds(),
            geocoder: new google.maps.Geocoder(),
            infowindow: new google.maps.InfoWindow(),

            initMarkers: function(type) {
                this.processMarker(mappedJson[type], type);
            },

            processMarker: function(interator, type) {
                var keys = Object.keys(interator);
                $(keys).each(function(index, key) {
                    /*jshint unused:true*/
                    var LatLng = interator[key].LatLng;
                    if (LatLng) {
                        this.addMarker(type, key, LatLng);
                    } else {
                        this.getLongLatInfo(key, type);
                    }
                }.bind(this));
            },

            getLongLatInfo: function(query, type) {
                var address = query;

                this.geocoder.geocode({
                    "address": address
                }, this.putMarker.bind(this, type, query));
            },

            putMarker: function(type, query, results, status) {

                var position;

                if (status === google.maps.GeocoderStatus.OK) {

                    position = results[0].geometry.location;
                    saveLongLatInfo(type, query, position);
                    this.addMarker(type, query, position);

                } else {
                    alert("Geocode was not successful for the following reason: " + status);
                }
            },

            addMarker: function(type, query, position) {
                var marker;

                marker = new google.maps.Marker({
                    map: map,
                    position: position
                });

                this.markers.push(marker);
                google.maps.event.addListener(marker, "click", this.markerClickCallback.bind(this, type, query, marker));
                //this.addBounds(marker);
            },

            markerClickCallback: function(type, query, marker) {
                var count = getObjectBasedOnType(type)[query].count + 1,
                    message = ["<div class='markerInfoBox'>", [count, "Users in this location."].join(" "), "</div>"].join("");
                this.infowindow.setContent(message);
                this.infowindow.open(map, marker);
            },
            // Removes the markers from the map, but keeps them in the array.
            clearMarkers: function() {
                this.setAllMap(null);
                this.markers = [];
            },

            // Sets the map on all markers in the array.
            setAllMap: function(map) {
                for (var i = 0; i < this.markers.length; i++) {
                    this.markers[i].setMap(map);
                }
            },

            addBounds: function(marker) {
                this.bounds.extend(marker.position);
            },

            fitBound: function() {
                //map.fitBounds(this.bounds);
            }
        },

        map,
        mappedJson = {},
        DELIMITOR = ",",
        ZOOM_LEVEL_MAP = {
            "4": "state",
            "5": "city",
            "6": "zip"
        },
        ZOOM_LEVEL = 4;

    function initialize() {
        processJSON();
        var mapOptions = {
            zoom: ZOOM_LEVEL,
            center: new google.maps.LatLng(20.593684, 78.962880)
        };
        map = new google.maps.Map(document.getElementById("map-canvas"),
            mapOptions);

        initListerners();
        MarkerUtil.initMarkers(ZOOM_LEVEL_MAP[ZOOM_LEVEL]);
    }

    function initListerners() {
        google.maps.event.addListener(map, "zoom_changed", zoomChangedcallBack);
    }

    function zoomChangedcallBack() {
        var zoomLevel = map.getZoom(),
            typeOfZoom = ZOOM_LEVEL_MAP[zoomLevel];

        MarkerUtil.clearMarkers();
        if (!typeOfZoom) {
            return;
        }

        MarkerUtil.initMarkers(typeOfZoom);
        //map.setCenter(myLatLng);
        //infowindow.setContent('Zoom: ' + zoomLevel);
    }

    function getJSON() {
        var response = [{
            userId: 1,
            locationDetails: {
                state: {
                    value: "Karnataka",
                    longLat: [0.9876, 0.9988]
                },
                city: {
                    value: "Bangalore",
                    longLat: []
                },
                zipCode: {
                    value: 560103,
                    longLat: []
                }
            }

        }, {
            userId: 1,
            locationDetails: {
{'fraction_non_alphanumeric': 0.10729948348114218, 'fraction_numerical': 0.011207484650618849, 'mean_word_length': 1.4117508813160986, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 7, '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': '7092823', 'n_tokens_mistral': 2896, 'n_tokens_neox': 2654, 'n_words': 677}