<commit_before>const images = require('./images');
const object = require('./object');
const updater = require('./updater');
const util = require('./util');
const makeFeatureEventHandler = require('./feature-event-handler');
const query = require('./query');

module.exports = map;

/* global mapboxgl */

function transition(prop) {
  const _m = this;
  _m[prop] = Object.assign(function (options) {
    if (options.zoom) {
      options.zoom = Math.floor(options.zoom);
    }
    _m[prop].superior.apply(this, arguments);
  }, {
    superior: _m[prop]
  });
}

function getAttribution(result, attr) {
  attr = attr.slice(6).match(/(?:http:|https:)?\/\/([^\/?]+)/);
  if (attr) {
    attr = attr[1].split('.');
    if (attr.length > 1) {
      attr = attr[attr.length - 2];
    }
    if (attr) {
      result.push(attr);
    }
  }
  return result;
}

function preprocessDataEvent(event) {
  if (!(event.dataType === 'source' &&
      event.tile &&
      event.tile.state === 'loaded')) {
    return true;
  }
  if (event.style &&
      event.style.sourceCaches &&
      event.sourceId) {
    // collect attributions
    let attribution = event.style.sourceCaches[event.sourceId].getSource().attribution;
    if (attribution) {
      attribution = attribution.match(/href="[^"]+/g);
      if (attribution) {
        event.attribution = attribution.reduce(getAttribution, []);
      }
    }
  }
  return true;
}

function map(node, options) {
  let self;
  let mapTypeId;
  let styles;

  function element() {
    return node;
  }

  function center(c) {
    if (!c) {
      return util.mll2ll(self._m.getCenter());
    }
    self._m.setCenter(c);
  }

  function zoom(z) {
    if (z === undefined) {
      return Math.round(self._m.getZoom() + 1);
    }
    self._m[self._m.isStyleLoaded() ? 'zoomTo' : 'setZoom'](z - 1);
  }
<commit_msg>add source hostname to event for collecting statistics<commit_after>const images = require('./images');
const object = require('./object');
const updater = require('./updater');
const util = require('./util');
const makeFeatureEventHandler = require('./feature-event-handler');
const query = require('./query');

module.exports = map;

/* global mapboxgl */

function transition(prop) {
  const _m = this;
  _m[prop] = Object.assign(function (options) {
    if (options.zoom) {
      options.zoom = Math.floor(options.zoom);
    }
    _m[prop].superior.apply(this, arguments);
  }, {
    superior: _m[prop]
  });
}

function getAttribution(result, attr) {
  attr = attr.slice(6).match(/(?:http:|https:)?\/\/([^\/?]+)/);
  if (attr) {
    attr = attr[1].split('.');
    if (attr.length > 1) {
      attr = attr[attr.length - 2];
    }
    if (attr) {
      result.push(attr);
    }
  }
  return result;
}

function preprocessDataEvent(event) {
  if (!(event.dataType === 'source' &&
      event.tile &&
      event.tile.state === 'loaded')) {
    return true;
  }
  if (event.style &&
      event.style.sourceCaches &&
      event.sourceId) {
    // collect attributions
    let attribution = event.style.sourceCaches[event.sourceId].getSource().attribution;
    if (attribution) {
      attribution = attribution.match(/href="[^"]+/g);
      if (attribution) {
        event.attribution = attribution.reduce(getAttribution, []);
      }
    }
  }
  if (event.source) {
    // track tile loading
    let source = event.source.url || (event.source.tiles && event.source.tiles[0]);
    if (source) {
      event.sourceHostname = new URL(source).hostname;
    }
  }
  return true;
}

function map(node, options) {
  let self;
  let mapTypeId;
  let styles;

  function element() {
    return node;
  }

  function center(c) {
    if (!c) {
      return util.mll2ll(self._m.getCenter());
    }
    self._m.setCenter(c);
  }

  function zoom(z) {
    if (z === undefined) {
      return Math.round(self._m.getZoom() + 1);
    }
    self._m[self._m.isStyleLoaded() ? 'zoomTo' : 'setZoom'](z - 1);
  }

{'fraction_non_alphanumeric': 0.17726347914547305, 'fraction_numerical': 0.0038148524923702952, 'mean_word_length': 2.837073170731707, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '207943', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1326, 'n_words': 260}