<commit_before>var map = L.map('map').setView([41.88, -87.63], 10);

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

var mapzen_key = "<KEY>";
var url = 'https://search.mapzen.com/v1/autocomplete';
var inputElement = document.getElementsByTagName('input')[0];
var dataListEl = document.getElementsByTagName('datalist')[0];
var API_RATE_LIMIT = 1000;

/* TO-DO:
- Build out error handling
- Figure out workaround for datalist HTML only matching exactly
*/

/*
var autocomplete = throttle(function() {
  if (inputElement.value.length > 0) {
    var params = {
      api_key: mapzen_key,
      text: inputElement.value
    };
    callPelias(url, params);
  }
}, API_RATE_LIMIT);
*/

function callPelias(search_url, search_params) {
  AJAX.request(search_url, search_params, function (err, results) {
    if (err) {
      console.log(err);
    }
    if (results && results.features) {
      while (dataListEl.firstChild) {
        dataListEl.removeChild(dataListEl.firstChild);
      };
      if (results.features.length >= 5) {
        for (var i = 0; i < 5; ++i) {
          var option = document.createElement('option');
          option.value = results.features[i].properties.label;
          option.text = results.features[i].properties.label;
          dataListEl.appendChild(option);
        };
      }
      else {
        for (var i = 0; i < results.features.length; ++i) {
          var option = document.createElement('option');
          option.value = results.features[i].properties.label;
          option.text = results.features[i].properties.label;
          dataListEl.appendChild(option);
        };
      }
    }
  });
};

inputElement.addEventListener('keyup', throttle(function() {
  if (inputElement.value.length > 0) {
    var params = {
      api_key: mapzen_key,
      "focus.point.lon": -87.63,
      "focus.point.lat": 41.88,
      text: inputElement.value
    };
    console.log(inputElement.value);
    callPelias(url, params);

  }
}, API_RATE_LIMIT));

var pt = {
  "type": "Feature",
  "properties": {
    "marker-color": "#0f0"
  },
  "geometry": {
    "type": "Point",
    "coordinates": [-87.663906, 41.968421]
  }
};

$.ajax({
  dataType: "json",
  url: "chi-neighborhoods.geojson",
  success: function(data) {
    var chi_neighborhoods = data;

    for (var i = 0; i < chi_neighborhoods.features.length; ++i) {
      if (turf.inside(pt, chi_neighborhoods.features[i])) {
        console.log(chi_neighborhoods.features[i].properties.name);
        break;
      }
    };

    //L.geoJson(chi_neighborhoods).addTo(map);
  }
}).error(function() {});

var AJAX = {
  serialize: function (params) {
    var data = '';

    for (var key in params) {
      if (params.hasOwnProperty(key)) {
        var param = params[key];
        var type = param.toString();
        var value;

        if (data.length) {
          data += '&';
        }

        switch (type) {
          case '[object Array]':
          value = (param[0].toString() === '[object Object]') ? JSON.stringify(param) : param.join(',');
          break;<commit_msg>added html5 geolocation back with check on neighborhoods<commit_after>var map = L.map('map').setView([41.88, -87.63], 10);

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

var mapzen_key = "<KEY>";
var url = 'https://search.mapzen.com/v1/autocomplete';
var inputElement = document.getElementsByTagName('input')[0];
var dataListEl = document.getElementsByTagName('datalist')[0];
var API_RATE_LIMIT = 1000;

/* TO-DO:
- Build out error handling
- Figure out workaround for datalist HTML only matching exactly
- fix scoping so not everything is global
*/

/*
var autocomplete = throttle(function() {
  if (inputElement.value.length > 0) {
    var params = {
      api_key: mapzen_key,
      text: inputElement.value
    };
    callPelias(url, params);
  }
}, API_RATE_LIMIT);
*/

function callPelias(search_url, search_params) {
  AJAX.request(search_url, search_params, function (err, results) {
    if (err) {
      console.log(err);
    }
    if (results && results.features) {
      while (dataListEl.firstChild) {
        dataListEl.removeChild(dataListEl.firstChild);
      };
      if (results.features.length >= 5) {
        for (var i = 0; i < 5; ++i) {
          var option = document.createElement('option');
          option.value = results.features[i].properties.label;
          option.text = results.features[i].properties.label;
          dataListEl.appendChild(option);
        };
      }
      else {
        for (var i = 0; i < results.features.length; ++i) {
          var option = document.createElement('option');
          option.value = results.features[i].properties.label;
          option.text = results.features[i].properties.label;
          dataListEl.appendChild(option);
        };
      }
    }
  });
};

inputElement.addEventListener('keyup', throttle(function() {
  if (inputElement.value.length > 0) {
    var params = {
      api_key: mapzen_key,
      "focus.point.lon": -87.63,
      "focus.point.lat": 41.88,
      text: inputElement.value
    };
    console.log(inputElement.value);
    callPelias(url, params);

  }
}, API_RATE_LIMIT));

var coords = [];

function searchNeighborhoods(position, neighborhoods) {
  var pt = {
    "type": "Feature",
    "properties": {
      "marker-color": "#0f0"
    },
    "geometry": {
      "type": "Point",
      "coordinates": []
    }
  };

  pt["geometry"]["coordinates"] = [position.coords.longitude, position.coords.latitude];
  console.log("coordinates are " + pt["geometry"]["coordinates"]);

  for (var i = 0; i < neighborhoods.features.length; ++i) {
    if (turf.inside(pt, neighborhoods.features[i])) {
      console.log(chi_neighborhoods.features[i].properties.name);
      break;
    }
    else if (i == neighborhoods.features.length - 1) {
      console.log("outside Chicago");
    }
  };
};

$.ajax({
  dataType: "json",
  url: "chi-neighborhoods.geojson",
  success: function(data) {
    var chi_neighborhoods = data;
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        searchNeighborhoods(position, chi_neighborhoods);
      });
    }
    else {
      console.log("geolocation not supported");
    }
    //L.geoJson(chi_neighborhoods).addTo(map);
  }
}).error(function() {});

var AJAX = {
  serialize: function (params) {
    var data = '';

    for (var key in params) {
      if (params.hasOwnProperty(key)) {
        var param = params[key];
        var type = param.toString();
        var value;

        if (data.length) {
          data += '&';
        }

        switch (type) {
          case '[object Array]':
          value = (param[0].toString() === '[object Object]') ? JSON.stringify(param) : param.join(',');
          break;
{'fraction_non_alphanumeric': 0.1609392898052692, 'fraction_numerical': 0.012600229095074456, 'mean_word_length': 2.785907859078591, 'pattern_counts': {'":': 16, '<': 15, '<?xml version=': 0, '>': 15, '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': '861337', 'n_tokens_mistral': 2370, 'n_tokens_neox': 2268, 'n_words': 438}