<commit_before>'use strict';

require('mapbox.js');
require('leaflet-osm');

var omnivore = require('leaflet-omnivore');
var wellknown = require('wellknown');

var React = require('react');
var Reflux = require('reflux');

var store = require('store');
var actions = require('../actions/actions');
var config = require('../config');
var qs = require('querystring');
var xhr = require('xhr');
var EditBar = require('./workspace/editbar');
var MapStore = require('../stores/map_store');
var BingLayer = require('../ext/bing.js');

L.mapbox.accessToken = config.accessToken;
var geocoder = L.mapbox.geocoder('mapbox.places');

module.exports = React.createClass({
  contextTypes: {
    router: React.PropTypes.func
  },

  mixins: [
    Reflux.connect(MapStore, 'map'),
    Reflux.listenTo(actions.taskEdit, 'taskEdit')
  ],

  statics: {
    fetchData: function(params) {
      actions.taskData(params.task);
    }
  },

  componentDidUpdate: function() {
    var taskLayer = this.taskLayer;
    var map = this.map;

    // Clear any previously set layers in taskLayer
    if (taskLayer && taskLayer.getLayers()) {
      taskLayer.getLayers().forEach(function(l) {
        taskLayer.removeLayer(l);
      });
    }

    var task = this.context.router.getCurrentParams().task;
    if (this.state.map.mapData.length) {
      this.state.map.mapData.forEach(function(xml) {
        var layer = new L.OSM.DataLayer(xml).addTo(taskLayer);
        map.fitBounds(layer.getBounds(), { reset: true });
        this.geolocate(map.getCenter());
      }.bind(this));
    } else if (task == 'tigerdelta') {
      var layer = omnivore.wkt.parse(this.state.map.value.st_astext).addTo(taskLayer);
      map.fitBounds(layer.getBounds(), { reset: true });
      this.geolocate(map.getCenter());
    } else if (task == 'disconnectednepal') {
      var layer = omnivore.wkt.parse(this.state.map.value.geometry).addTo(taskLayer);
      map.fitBounds(layer.getBounds(), { reset: true });
      this.geolocate(map.getCenter());
    } else if (task == 'rk') {
      var geom = wellknown.parse(this.state.map.value.geom);

      var circleOptions = {
        stroke: false,
        color: '#fff',
        opacity: 0.1,
        fillColor: '#03f',
        fillOpacity: 0.5,
        fill: true,
        weight: 0,
        radius: 5
      };

      if (geom.type == 'MultiPoint') {
        geom.coordinates.forEach(function(coords) {
          L.circleMarker([coords[1], coords[0]], circleOptions).addTo(taskLayer);
        });
      }

      if (geom.type == 'Point') {
        L.circleMarker([geom.coordinates[1], geom.coordinates[0]], circleOptions).addTo(taskLayer);
      }<commit_msg>contextual tilelayer for test task<commit_after>'use strict';

require('mapbox.js');
require('leaflet-osm');

var omnivore = require('leaflet-omnivore');
var wellknown = require('wellknown');

var React = require('react');
var Reflux = require('reflux');

var store = require('store');
var actions = require('../actions/actions');
var config = require('../config');
var qs = require('querystring');
var xhr = require('xhr');
var EditBar = require('./workspace/editbar');
var MapStore = require('../stores/map_store');
var BingLayer = require('../ext/bing.js');

L.mapbox.accessToken = config.accessToken;
var geocoder = L.mapbox.geocoder('mapbox.places');

module.exports = React.createClass({
  contextTypes: {
    router: React.PropTypes.func
  },

  mixins: [
    Reflux.connect(MapStore, 'map'),
    Reflux.listenTo(actions.taskEdit, 'taskEdit')
  ],

  statics: {
    fetchData: function(params) {
      actions.taskData(params.task);
    }
  },

  componentDidUpdate: function() {
    var taskLayer = this.taskLayer;
    var map = this.map;

    // Clear any previously set layers in taskLayer
    if (taskLayer && taskLayer.getLayers()) {
      taskLayer.getLayers().forEach(function(l) {
        taskLayer.removeLayer(l);
      });
    }

    var task = this.context.router.getCurrentParams().task;
    if (this.state.map.mapData.length) {
      this.state.map.mapData.forEach(function(xml) {
        var layer = new L.OSM.DataLayer(xml).addTo(taskLayer);
        map.fitBounds(layer.getBounds(), { reset: true });
        this.geolocate(map.getCenter());
      }.bind(this));
    } else if (task == 'tigerdelta') {
      var layer = omnivore.wkt.parse(this.state.map.value.st_astext).addTo(taskLayer);
      map.fitBounds(layer.getBounds(), { reset: true });
      this.geolocate(map.getCenter());
    } else if (task == 'disconnectednepal') {
      var layer = omnivore.wkt.parse(this.state.map.value.geometry).addTo(taskLayer);
      map.fitBounds(layer.getBounds(), { reset: true });
      this.geolocate(map.getCenter());
    } else if (task == 'rk') {
      // rk traces
      var rkTraces = L.mapbox.tileLayer('matt.8fafe5ff');
      rkTraces.addTo(map).bringToFront();

      var geom = wellknown.parse(this.state.map.value.geom);

      var circleOptions = {
        stroke: false,
        color: '#fff',
        opacity: 0.1,
        fillColor: '#03f',
        fillOpacity: 0.5,
        fill: true,
        weight: 0,
        radius: 5
      };

      if (geom.type == 'MultiPoint') {
        geom.coordinates.forEach(function(coords) {
          L.circleMarker([coords[1], coords[0]], circleOptions).addTo(taskLayer);
        });
      }

      if (geom.type == 'Point') {
        L.circleMarker([geom.coordinates[1], geom.coordinates[0]], circleOptions).addTo(taskLayer);
      }
{'fraction_non_alphanumeric': 0.16492578339747113, 'fraction_numerical': 0.004764522631482499, 'mean_word_length': 3.088389513108614, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3912433', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1775, 'n_words': 318}