<commit_before>"use strict";

var $ = require('jquery'),
    BU = require('treemap/baconUtils'),
    _ = require('lodash'),
    L = require('leaflet');

var boundaryUrlTemplate = _.template('<%= instanceUrl %>boundaries/<%= boundaryId %>/geojson/');
var currentLayer = null;

function clearLayer(map) {
    if (currentLayer) {
        map.removeLayer(currentLayer);
    }
}

function showBoundaryGeomOnMapLayerAndZoom(map, boundaryGeom) {
    clearLayer(map);

    currentLayer = boundaryGeom;

    map.addLayer(boundaryGeom);
    map.fitBounds(boundaryGeom.getBounds());
}

function instanceBoundaryIdToUrl(instanceUrl, id) {
    return boundaryUrlTemplate({
        instanceUrl: instanceUrl,
        boundaryId: id
    });
}

function parseGeoJson(style, geojson) {
    return L.geoJson(geojson, {
        style: function() { return style; }
    });
}

exports.init = function (options) {
    var map = options.map,
        idStream = options.idStream,
        boundaries = idStream
            .filter(BU.isDefined)
            .map(instanceBoundaryIdToUrl, options.config.instance.url)
            .flatMap(BU.getJsonFromUrl);

    // Make overlay layer be below tiles
    $(map.getPanes().overlayPane).css('z-index', -2);

    boundaries.map(parseGeoJson, options.style)
        .onValue(showBoundaryGeomOnMapLayerAndZoom, map);

    // If there is an error fetching or parsing the
    // boundary, we should clear any existing, stale
    // boundary highlight.
    boundaries.onError(clearLayer, map);
<commit_msg>Adjust z-index only when adding boundary polygon to map<commit_after>"use strict";

var $ = require('jquery'),
    BU = require('treemap/baconUtils'),
    _ = require('lodash'),
    L = require('leaflet');

var boundaryUrlTemplate = _.template('<%= instanceUrl %>boundaries/<%= boundaryId %>/geojson/');
var currentLayer = null;

function clearLayer(map) {
    if (currentLayer) {
        map.removeLayer(currentLayer);
    }
}

function showBoundaryGeomOnMapLayerAndZoom(map, boundaryGeom) {
    clearLayer(map);

    // We want to put the boundary polygon below the plot tiles
    // so that plots will display and select normally.
    // But in Leaflet < 0.8 all polygon layers go in the "overlay pane",
    // so our only choice is to set the z-index of the entire overlay pane.
    // That's not great since we might want other polygons on the map,
    // *above* the plot tiles.
    // TODO: When we switch to Leaflet 0.8, make a separate pane to contain
    // the boundary polygon, with a permanent z-index.
    map.getPanes().overlayPane.style.zIndex = -2;

    currentLayer = boundaryGeom;

    map.addLayer(boundaryGeom);
    map.fitBounds(boundaryGeom.getBounds());
}

function instanceBoundaryIdToUrl(instanceUrl, id) {
    return boundaryUrlTemplate({
        instanceUrl: instanceUrl,
        boundaryId: id
    });
}

function parseGeoJson(style, geojson) {
    return L.geoJson(geojson, {
        style: function() { return style; }
    });
}

exports.init = function (options) {
    var map = options.map,
        idStream = options.idStream,
        boundaries = idStream
            .filter(BU.isDefined)
            .map(instanceBoundaryIdToUrl, options.config.instance.url)
            .flatMap(BU.getJsonFromUrl);

    boundaries.map(parseGeoJson, options.style)
        .onValue(showBoundaryGeomOnMapLayerAndZoom, map);

    // If there is an error fetching or parsing the
    // boundary, we should clear any existing, stale
    // boundary highlight.
    boundaries.onError(clearLayer, map);

{'fraction_non_alphanumeric': 0.11390616167326173, 'fraction_numerical': 0.0016958733747880158, 'mean_word_length': 3.1343457943925235, 'pattern_counts': {'":': 0, '<': 8, '<?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': '5207157', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1043, 'n_words': 275}