<commit_before>/*jslint browser: true*/
/*global Tangram, gui */

(function () {
    'use strict';

    function appendProtocol(url) {
        return window.location.protocol + url;
    }

    // default source, can be overriden by URL
    var default_tile_source = 'mapzen',
        rS;

    var tile_sources = {
        'mapzen': {
            source: {
                type: 'GeoJSONTileSource',
                url:  appendProtocol('//vector.mapzen.com/osm/all/{z}/{x}/{y}.json')
            },
            layers: 'demos/layers.yaml',
            styles: 'demos/styles.yaml'
        },
        'mapzen-dev': {
            source: {
                type: 'GeoJSONTileSource',
                url: appendProtocol('//vector.dev.mapzen.com/osm/all/{z}/{x}/{y}.json')
            },
            layers: 'demos/layers.yaml',
            styles: 'demos/styles.yaml'
        },
        'mapzen-local': {
            source: {
                type: 'GeoJSONTileSource',
                url: 'http://localhost:8080/all/{z}/{x}/{y}.json'
            },
            layers: 'demos/layers.yaml',
            styles: 'demos/styles.yaml'
        },
        'mapzen-mvt': {
            source: {
                type: 'MapboxFormatTileSource',
                url: appendProtocol('//vector.mapzen.com/osm/all/{z}/{x}/{y}.mapbox')
            },
            layers: 'demos/layers.yaml',
            styles: 'demos/styles.yaml'
        },
        'mapzen-topojson': {
            source: {
                type: 'TopoJSONTileSource',
                url: appendProtocol('//vector.mapzen.com/osm/all/{z}/{x}/{y}.topojson')
            },
            layers: 'demos/layers.yaml',
            styles: 'demos/styles.yaml'
        },
        'osm': {
            source: {
                type: 'GeoJSONTileSource',
                url: 'http://tile.openstreetmap.us/vectiles-all/{z}/{x}/{y}.json'
            },
            layers: 'demos/layers.yaml',
            styles: 'demos/styles.yaml'
        },
        'mapbox': {
            source: {
                type: 'MapboxFormatTileSource',
                url: 'http://{s:[a,b,c,d]}.tiles.mapbox.com/v4/mapbox.mapbox-streets-v6-dev/{z}/{x}/{y}.vector.pbf?access_token=<KEY>',
                max_zoom: 15
            },
            layers: 'demos/layers_mvt.yaml',
            styles: 'demos/styles.yaml'
        }
    };

    var locations = {
        'London': [51.508, -0.105, 15],
        'New York': [40.70531887544228, -74.00976419448853, 16],
        'Seattle': [47.609722, -122.333056, 15]
    };
    var osm_debug = false;

    /***** GUI/debug controls *****/

    // GUI options for #define-based effects
    var gl_define_options = {
        lighting: {
            lighting: 'LIGHTING_POINT',
            options: {
                'None': '',
                'Diffuse': 'LIGHTING_POINT',
                'Specular': 'LIGHTING_POINT_SPECULAR',
                'Flat': 'LIGHTING_DIRECTION',
                'Night': 'LIGHTING_NIGHT'
            }
        }
    };

    /*** URL parsing ***/

    // URL hash pattern is one of:
    // #[source]
    // #[lat],[lng],[zoom]
    // #[source],[lat],[lng],[zoom]
    // #[source],[location name]
    var url_hash = window.location.hash.slice(1, window.location.hash.length).split(',');

    // Get tile source from URL
    if (url_hash.length >= 1 && tile_sources[url_hash[0]] != null) {
        default_tile_source = url_hash[0];
    }

    // Get location from URL
    var map_start_location = locations['New York'];

    if (url_hash.length == 3) {
        map_start_location = url_hash.slice(0, 3);
    }
    if (url_hash.length > 3) {
        map_start_location = url_hash.slice(1, 4);
    }
    else if (url_hash.length == 2) {
        map_start_location = locations[url_hash[1]];
    }

    if (url_hash.length > 4) {
        var url_ui = url_hash.slice(4);

        // Mode on URL?
        var url_mode;
        if (url_ui) {
            var re = new RegExp(/mode=(\w+)/);
            url_ui.forEach(function(u) {
                var match = u.match(re);
                url_mode = (match && match.length > 1 && match[1]);
            });
        }
    }

    function setGLProgramDefinesForOptionSet(current_value, options) {
        Object.keys(options).forEach(function (key) {
            var value = options[key];
            Tangram.GLProgram.defines[value] = ((value === current_value) && value !== '');
        });
    }


    function setGLProgramDefines() {
        Object.keys(gl_define_options).forEach(function (key) {
            setGLProgramDefinesForOptionSet(gl_define_options[key][key], gl_define_options[key].options);
        });
        layer.scene.requestRedraw();
    }

    // Put current state on URL
    function updateURL() {
        var map_latlng = map.getCenter(),
            url_options = [default_tile_source, map_latlng.lat, map_latlng.lng, map.getZoom()];

        if (rS) {
            url_options.push('rstats');
        }

        if (gl_mode_options && gl_mode_options.effect != '') {
            url_options.push('mode=' + gl_mode_options.effect);
        }

        window.location.hash = url_options.join(',');
    }

    /*** Map ***/

    var map = L.map('map', {
        maxZoom: 20,
        inertia: false,
        keyboard: false
    });

    var layer = Tangram.leafletLayer({
        vectorTileSource: tile_sources[default_tile_source].source,
        vectorLayers: tile_sources[default_tile_source].layers,
        vectorStyles: tile_sources[default_tile_source].styles,
        numWorkers: 2,
        // debug: true,
        attribution: 'Map data &copy; OpenStreetMap contributors | <a href="https://github.com/tangrams/tangram">Source Code</a>',
        unloadInvisibleTiles: false,
        updateWhenIdle: false
    });

    var scene = layer.scene;
    window.scene = scene;

    // Update URL hash on move
    map.attributionControl.setPrefix('');
    map.setView(map_start_location.slice(0, 2), map_start_location[2]);
    map.on('moveend', updateURL);

    // Resize map to window
    function resizeMap() {
        document.getElementById('map').style.width = window.innerWidth + 'px';
        document.getElementById('map').style.height = window.innerHeight + 'px';
        map.invalidateSize(false);
    }

    window.addEventListener('resize', resizeMap);
    resizeMap();<commit_msg>expose layer in demo for debugging<commit_after>/*jslint browser: true*/
/*global Tangram, gui */

(function () {
    'use strict';

    function appendProtocol(url) {
        return window.location.protocol + url;
    }

    // default source, can be overriden by URL
    var default_tile_source = 'mapzen',
        rS;

    var tile_sources = {
        'mapzen': {
            source: {
                type: 'GeoJSONTileSource',
                url:  appendProtocol('//vector.mapzen.com/osm/all/{z}/{x}/{y}.json')
            },
            layers: 'demos/layers.yaml',
            styles: 'demos/styles.yaml'
        },
        'mapzen-dev': {
            source: {
                type: 'GeoJSONTileSource',
                url: appendProtocol('//vector.dev.mapzen.com/osm/all/{z}/{x}/{y}.json')
            },
            layers: 'demos/layers.yaml',
            styles: 'demos/styles.yaml'
        },
        'mapzen-local': {
            source: {
                type: 'GeoJSONTileSource',
                url: 'http://localhost:8080/all/{z}/{x}/{y}.json'
            },
            layers: 'demos/layers.yaml',
            styles: 'demos/styles.yaml'
        },
        'mapzen-mvt': {
            source: {
                type: 'MapboxFormatTileSource',
                url: appendProtocol('//vector.mapzen.com/osm/all/{z}/{x}/{y}.mapbox')
            },
            layers: 'demos/layers.yaml',
            styles: 'demos/styles.yaml'
        },
        'mapzen-topojson': {
            source: {
                type: 'TopoJSONTileSource',
                url: appendProtocol('//vector.mapzen.com/osm/all/{z}/{x}/{y}.topojson')
            },
            layers: 'demos/layers.yaml',
            styles: 'demos/styles.yaml'
        },
        'osm': {
            source: {
                type: 'GeoJSONTileSource',
                url: 'http://tile.openstreetmap.us/vectiles-all/{z}/{x}/{y}.json'
            },
            layers: 'demos/layers.yaml',
            styles: 'demos/styles.yaml'
        },
        'mapbox': {
            source: {
                type: 'MapboxFormatTileSource',
                url: 'http://{s:[a,b,c,d]}.tiles.mapbox.com/v4/mapbox.mapbox-streets-v6-dev/{z}/{x}/{y}.vector.pbf?access_token=<KEY>',
                max_zoom: 15
            },
            layers: 'demos/layers_mvt.yaml',
            styles: 'demos/styles.yaml'
        }
    };

    var locations = {
        'London': [51.508, -0.105, 15],
        'New York': [40.70531887544228, -74.00976419448853, 16],
        'Seattle': [47.609722, -122.333056, 15]
    };
    var osm_debug = false;

    /***** GUI/debug controls *****/

    // GUI options for #define-based effects
    var gl_define_options = {
        lighting: {
            lighting: 'LIGHTING_POINT',
            options: {
                'None': '',
                'Diffuse': 'LIGHTING_POINT',
                'Specular': 'LIGHTING_POINT_SPECULAR',
                'Flat': 'LIGHTING_DIRECTION',
                'Night': 'LIGHTING_NIGHT'
            }
        }
    };

    /*** URL parsing ***/

    // URL hash pattern is one of:
    // #[source]
    // #[lat],[lng],[zoom]
    // #[source],[lat],[lng],[zoom]
    // #[source],[location name]
    var url_hash = window.location.hash.slice(1, window.location.hash.length).split(',');

    // Get tile source from URL
    if (url_hash.length >= 1 && tile_sources[url_hash[0]] != null) {
        default_tile_source = url_hash[0];
    }

    // Get location from URL
    var map_start_location = locations['New York'];

    if (url_hash.length == 3) {
        map_start_location = url_hash.slice(0, 3);
    }
    if (url_hash.length > 3) {
        map_start_location = url_hash.slice(1, 4);
    }
    else if (url_hash.length == 2) {
        map_start_location = locations[url_hash[1]];
    }

    if (url_hash.length > 4) {
        var url_ui = url_hash.slice(4);

        // Mode on URL?
        var url_mode;
        if (url_ui) {
            var re = new RegExp(/mode=(\w+)/);
            url_ui.forEach(function(u) {
                var match = u.match(re);
                url_mode = (match && match.length > 1 && match[1]);
            });
        }
    }

    function setGLProgramDefinesForOptionSet(current_value, options) {
        Object.keys(options).forEach(function (key) {
            var value = options[key];
            Tangram.GLProgram.defines[value] = ((value === current_value) && value !== '');
        });
    }


    function setGLProgramDefines() {
        Object.keys(gl_define_options).forEach(function (key) {
            setGLProgramDefinesForOptionSet(gl_define_options[key][key], gl_define_options[key].options);
        });
        layer.scene.requestRedraw();
    }

    // Put current state on URL
    function updateURL() {
        var map_latlng = map.getCenter(),
            url_options = [default_tile_source, map_latlng.lat, map_latlng.lng, map.getZoom()];

        if (rS) {
            url_options.push('rstats');
        }

        if (gl_mode_options && gl_mode_options.effect != '') {
            url_options.push('mode=' + gl_mode_options.effect);
        }

        window.location.hash = url_options.join(',');
    }

    /*** Map ***/

    var map = L.map('map', {
        maxZoom: 20,
        inertia: false,
        keyboard: false
    });

    var layer = Tangram.leafletLayer({
        vectorTileSource: tile_sources[default_tile_source].source,
        vectorLayers: tile_sources[default_tile_source].layers,
        vectorStyles: tile_sources[default_tile_source].styles,
        numWorkers: 2,
        // debug: true,
        attribution: 'Map data &copy; OpenStreetMap contributors | <a href="https://github.com/tangrams/tangram">Source Code</a>',
        unloadInvisibleTiles: false,
        updateWhenIdle: false
    });
    window.layer = layer;

    var scene = layer.scene;
    window.scene = scene;

    // Update URL hash on move
    map.attributionControl.setPrefix('');
    map.setView(map_start_location.slice(0, 2), map_start_location[2]);
    map.on('moveend', updateURL);

    // Resize map to window
    function resizeMap() {
        document.getElementById('map').style.width = window.innerWidth + 'px';
        document.getElementById('map').style.height = window.innerHeight + 'px';
        map.invalidateSize(false);
    }

    window.addEventListener('resize', resizeMap);
    resizeMap();
{'fraction_non_alphanumeric': 0.15014520053371008, 'fraction_numerical': 0.014755513695942234, 'mean_word_length': 1.8467381590705987, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '2301429', 'n_tokens_mistral': 4214, 'n_tokens_neox': 3968, 'n_words': 670}