<commit_before>
// STRINGS
var _rebuildHexLegend__p_str = gettext('Proportion of surveys with response(s): ');
var getBootstrapFields__str = gettext("ERROR: constants not found; please include main/static/js/formManagers.js");
var JSONSurveyToHTML__q_str = gettext("Question");
var JSONSurveyToHTML__r_str = gettext("Response");


var centerLatLng = new L.LatLng(!center.lat?0.0:center.lat, !center.lng?0.0:center.lng);
var defaultZoom = 8;
var mapId = 'map_canvas';
var map;
var layersControl;
// array of mapbox maps to use as base layers - the first one will be the default map
var mapboxMaps = [
    {'label': gettext('Mapbox Streets'), 'url': 'http://a.tiles.mapbox.com/v3/modilabs.map-iuetkf9u.jsonp'},
    {'label': gettext('MapBox Streets Light'), 'url': 'http://a.tiles.mapbox.com/v3/modilabs.map-p543gvbh.jsonp'},
    {'label': gettext('MapBox Streets Zenburn'), 'url': 'http://a.tiles.mapbox.com/v3/modilabs.map-bjhr55gf.jsonp'},
    {'label': gettext('Natural Earth II'), 'url': 'http://a.tiles.mapbox.com/v3/modilabs.map-1c1r9n5g.jsonp'}
];
var sslUrlPerfix = 'https://dnv9my2eseobd.cloudfront.net/'; // add trailing slash since its expected function that uses this
var allowResetZoomLevel = true; // used to allow zooming when first loaded
var popupOffset = new L.Point(0, -10);
var notSpecifiedCaption = gettext("Not Specified");
var colorPalette = ['#8DD3C7', '#FB8072', '#FFFFB3', '#BEBADA', '#80B1D3', '#FDB462', '#B3DE69', '#FCCDE5', '#D9D9D9',
    '#BC80BD', '#CCEBC5', '#FFED6F'];
var circleStyle = {
    color: '#fff',
    border: 8,
    fillColor: '#ff3300',
    fillOpacity: 0.9,
    radius: 8
};
// TODO: can we get the entire URL from mongo API
var amazonUrlPrefix = "https://formhub.s3.amazonaws.com/";
var markerLayerGroup = new L.LayerGroup();
var markerLayerGroupActive = false;
var hexbinLayerGroupActive = false;
var hexbinLayerGroup = new L.LayerGroup();
var hexbinData = null;
var markerLayerLabel = gettext("Marker Layer");
var hexbinLayerLabel = "Hexbin Layer";
// TODO: generate new api key for formhub at https://www.bingmapsportal.com/application/index/1121012?status=NoStatus
var bingAPIKey = '<KEY>';
var bingMapTypeLabels = {'AerialWithLabels': gettext('Bing Satellite Map'), 'Road': gettext('Bing Road Map')}; //Road, Aerial or AerialWithLabels
var mapBoxAdditAttribution = gettext("Map data (c) OpenStreetMap contributors, CC-BY-SA");

// map filter vars
var navContainerSelector = ".nav.pull-right";
var leafletControlSelector = ".leaflet-control-container";
var legendContainerId = "legend";
var formJSONMngr = new FormJSONManager(formJSONUrl, loadFormJSONCallback);
var formResponseMngr = new FormResponseManager(mongoAPIUrl, loadResponseDataCallback);
var currentLanguageIdx = -1;
var customMapBoxTileLayer;
var legendsContainer;

var mapview = function() {

    return {
        isHttps: function(){
            return location.protocol == 'https:';
        }
    }
}();

/**
 *  for a url http://a.tiles.mapbox.com/v3/modilabs.map-iuetkf9u/{z}/{x}/{y}.png
 *  return v3/modilabs.map-iuetkf9u/{z}/{x}/{y}.png,
 *  is a regex that strips gets everything after the domain name
 */
mapview.getMapboxMapname = function(mapUrl) {
    var matches = mapUrl.match(/(^.+?\..+?\/)(.+)/);
    if(matches.length > 0)
    {
        return matches[2];
    }
    return null;
}

function initialize() {
    // Make a new Leaflet map in your container div
    map = new L.Map(mapId).setView(centerLatLng, defaultZoom);

    map.on('layeradd', function(layerEvent){
        if(layerEvent.layer == hexbinLayerGroup)
        {
            hexbinLayerAdded(layerEvent.layer);
        }
        else if(layerEvent.layer == markerLayerGroup)
        {
            markerLayerAdded(layerEvent.layer);
        }
    });

    map.on('layerremove', function(layerEvent){
        if(layerEvent.layer == hexbinLayerGroup)
        {
            hexbinLayerRemoved(layerEvent.layer);
        }
        else if(layerEvent.layer == markerLayerGroup)
        {
            markerLayerRemoved(layerEvent.layer);
        }
    });

    var overlays = {};
    overlays[markerLayerLabel] = markerLayerGroup;
    overlays[hexbinLayerLabel] = hexbinLayerGroup;
    layersControl = new L.Control.Layers({}, overlays);
    map.addControl(layersControl);
    //show marker layer by default
    map.addLayer(markerLayerGroup);

    // add bing maps layer
    /** $.each(bingMapTypeLabels, function(type, label) {
        var bingLayer = new L.TileLayer.Bing(bingAPIKey, type); 
        layersControl.addBaseLayer(bingLayer, label);
    });*/

    // add google sat layer
    var ggl = new L.Google();
    layersControl.addBaseLayer(ggl, gettext("Google Satellite Map"));

    // Get metadata about the map from MapBox
    var tileJSONAddFn = function(mapData, addToMap) { 
        var innerFn = function(tilejson) {
            var tileLayer, mapName;

            tilejson.attribution += mapBoxAdditAttribution;
            // check if https and change tile array appropriately
            if(mapview.isHttps())
            {
                /// get map url
                mapName = mapview.getMapboxMapname(tilejson.tiles[0]);
                /// replace our tile url with this
                tilejson.tiles = [sslUrlPerfix + mapName];
            }<commit_msg>Pulling a google hybrid map as one way to fix #644<commit_after>
// STRINGS
var _rebuildHexLegend__p_str = gettext('Proportion of surveys with response(s): ');
var getBootstrapFields__str = gettext("ERROR: constants not found; please include main/static/js/formManagers.js");
var JSONSurveyToHTML__q_str = gettext("Question");
var JSONSurveyToHTML__r_str = gettext("Response");


var centerLatLng = new L.LatLng(!center.lat?0.0:center.lat, !center.lng?0.0:center.lng);
var defaultZoom = 8;
var mapId = 'map_canvas';
var map;
var layersControl;
// array of mapbox maps to use as base layers - the first one will be the default map
var mapboxMaps = [
    {'label': gettext('Mapbox Streets'), 'url': 'http://a.tiles.mapbox.com/v3/modilabs.map-iuetkf9u.jsonp'},
    {'label': gettext('MapBox Streets Light'), 'url': 'http://a.tiles.mapbox.com/v3/modilabs.map-p543gvbh.jsonp'},
    {'label': gettext('MapBox Streets Zenburn'), 'url': 'http://a.tiles.mapbox.com/v3/modilabs.map-bjhr55gf.jsonp'},
    {'label': gettext('Natural Earth II'), 'url': 'http://a.tiles.mapbox.com/v3/modilabs.map-1c1r9n5g.jsonp'}
];
var sslUrlPerfix = 'https://dnv9my2eseobd.cloudfront.net/'; // add trailing slash since its expected function that uses this
var allowResetZoomLevel = true; // used to allow zooming when first loaded
var popupOffset = new L.Point(0, -10);
var notSpecifiedCaption = gettext("Not Specified");
var colorPalette = ['#8DD3C7', '#FB8072', '#FFFFB3', '#BEBADA', '#80B1D3', '#FDB462', '#B3DE69', '#FCCDE5', '#D9D9D9',
    '#BC80BD', '#CCEBC5', '#FFED6F'];
var circleStyle = {
    color: '#fff',
    border: 8,
    fillColor: '#ff3300',
    fillOpacity: 0.9,
    radius: 8
};
// TODO: can we get the entire URL from mongo API
var amazonUrlPrefix = "https://formhub.s3.amazonaws.com/";
var markerLayerGroup = new L.LayerGroup();
var markerLayerGroupActive = false;
var hexbinLayerGroupActive = false;
var hexbinLayerGroup = new L.LayerGroup();
var hexbinData = null;
var markerLayerLabel = gettext("Marker Layer");
var hexbinLayerLabel = "Hexbin Layer";
// TODO: generate new api key for formhub at https://www.bingmapsportal.com/application/index/1121012?status=NoStatus
var bingAPIKey = '<KEY>';
var bingMapTypeLabels = {'AerialWithLabels': gettext('Bing Satellite Map'), 'Road': gettext('Bing Road Map')}; //Road, Aerial or AerialWithLabels
var mapBoxAdditAttribution = gettext("Map data (c) OpenStreetMap contributors, CC-BY-SA");

// map filter vars
var navContainerSelector = ".nav.pull-right";
var leafletControlSelector = ".leaflet-control-container";
var legendContainerId = "legend";
var formJSONMngr = new FormJSONManager(formJSONUrl, loadFormJSONCallback);
var formResponseMngr = new FormResponseManager(mongoAPIUrl, loadResponseDataCallback);
var currentLanguageIdx = -1;
var customMapBoxTileLayer;
var legendsContainer;

var mapview = function() {

    return {
        isHttps: function(){
            return location.protocol == 'https:';
        }
    }
}();

/**
 *  for a url http://a.tiles.mapbox.com/v3/modilabs.map-iuetkf9u/{z}/{x}/{y}.png
 *  return v3/modilabs.map-iuetkf9u/{z}/{x}/{y}.png,
 *  is a regex that strips gets everything after the domain name
 */
mapview.getMapboxMapname = function(mapUrl) {
    var matches = mapUrl.match(/(^.+?\..+?\/)(.+)/);
    if(matches.length > 0)
    {
        return matches[2];
    }
    return null;
}

function initialize() {
    // Make a new Leaflet map in your container div
    map = new L.Map(mapId).setView(centerLatLng, defaultZoom);

    map.on('layeradd', function(layerEvent){
        if(layerEvent.layer == hexbinLayerGroup)
        {
            hexbinLayerAdded(layerEvent.layer);
        }
        else if(layerEvent.layer == markerLayerGroup)
        {
            markerLayerAdded(layerEvent.layer);
        }
    });

    map.on('layerremove', function(layerEvent){
        if(layerEvent.layer == hexbinLayerGroup)
        {
            hexbinLayerRemoved(layerEvent.layer);
        }
        else if(layerEvent.layer == markerLayerGroup)
        {
            markerLayerRemoved(layerEvent.layer);
        }
    });

    var overlays = {};
    overlays[markerLayerLabel] = markerLayerGroup;
    overlays[hexbinLayerLabel] = hexbinLayerGroup;
    layersControl = new L.Control.Layers({}, overlays);
    map.addControl(layersControl);
    //show marker layer by default
    map.addLayer(markerLayerGroup);

    // add bing maps layer
    /** $.each(bingMapTypeLabels, function(type, label) {
        var bingLayer = new L.TileLayer.Bing(bingAPIKey, type); 
        layersControl.addBaseLayer(bingLayer, label);
    });*/

    // add google sat layer
    var ggl = new L.Google('HYBRID');
    layersControl.addBaseLayer(ggl, gettext("Google Satellite Map"));

    // Get metadata about the map from MapBox
    var tileJSONAddFn = function(mapData, addToMap) { 
        var innerFn = function(tilejson) {
            var tileLayer, mapName;

            tilejson.attribution += mapBoxAdditAttribution;
            // check if https and change tile array appropriately
            if(mapview.isHttps())
            {
                /// get map url
                mapName = mapview.getMapboxMapname(tilejson.tiles[0]);
                /// replace our tile url with this
                tilejson.tiles = [sslUrlPerfix + mapName];
            }
{'fraction_non_alphanumeric': 0.13478794748276188, 'fraction_numerical': 0.014262775101539624, 'mean_word_length': 3.4024948024948025, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, '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': '6695812', 'n_tokens_mistral': 3522, 'n_tokens_neox': 3399, 'n_words': 800}