<commit_before>// SET UP THE MAP

var mapProjection = new ol.proj.Projection({
  code: 'EPSG:3857',
  extent: [-20037508, -20037508, 20037508, 20037508.34]
})
var geoProjection = new ol.proj.Projection({
  code: 'EPSG:4326',
  extent: [-180, -180, 180, 180]
})

var map = new ol.Map({
  layers:[
    new ol.layer.Tile({
      source: new ol.source.XYZ({
        url: 'https://api.mapbox.com/styles/v1/mapbox/outdoors-v10/tiles/256/{z}/{x}/{y}?access_token=<KEY>'
      })
    })
  ],
  target: 'map',
  view: new ol.View({
    center: ol.proj.transform([-96, 39], geoProjection, mapProjection),
    zoom: 5
  })
});

var app = {
	mapzenKey: '<KEY>',
  	activeSearch: 'from',
  options:[],
  typeAhead: function(e){
  		var el = e.target;
    	var val = el.value;
  		if(val.length>2){
          app.queryAutocomplete(val, function(err, data){console.log(data);
  		})
		}
  },
  
  queryAutocomplete: throttle(function(text, callback){
  $.ajax({
  	url: 'https://search.mapzen.com/vi/autocomplete?text=' + text + '@api_key=' + 					app.mapzenKey, 
    success: function(data, status, req){callback(null, data)}, 
    error: function(req, status, err){callback(err)}
  })},150),
  
  renderResultsList: function(){
  	var resultsList = $('#results-list'};
	results-list.empty();
    
    var results = app.options.map(function(feature){
      var li = $('<li class="results-list-item">' + feature.properties.label + '</li'>);
                 return li;
                 })
      
      		resultsList.append(results);
      		if(app.options.length > 0) {resultsList.removeClass('hidden');
                                       }else{resultsList.addClass('hidden');}
      }
}

$('#search-from-input').on('keyup', {input:'from'}, app.typeAhead);<commit_msg>Update app.js<commit_after>// SET UP THE MAP 
2 
 
3 var mapProjection = new ol.proj.Projection({ 
4   code: 'EPSG:3857', 
5   extent: [-20037508, -20037508, 20037508, 20037508.34] 
6 }) 
7 var geoProjection = new ol.proj.Projection({ 
8   code: 'EPSG:4326', 
9   extent: [-180, -180, 180, 180] 
10 }) 
11 
 
12 var map = new ol.Map({ 
13   layers:[ 
14     new ol.layer.Tile({ 
15       source: new ol.source.XYZ({ 
16         url: 'https://api.mapbox.com/styles/v1/mapbox/outdoors-v10/tiles/256/{z}/{x}/{y}?access_token=<KEY>' 
17       }) 
18     }) 
19   ], 
20   target: 'map', 
21   view: new ol.View({ 
22     center: ol.proj.transform([-96, 39], geoProjection, mapProjection), 
23     zoom: 5 
24   }) 
25 }); 
26 
 
27 // SETUP APPLICATION LOGIC HERE 
28 
 
29 var app = { 
30   mapzenKey: '<KEY>',  
31   activeSearch: 'from', 
32   options: [], 
33   selection: { 
34     from: {}, 
35     to: {} 
36   }, 
37 
 
38   typeAhead: function(e){ 
39     var el = e.target; 
40     var val = el.value; 
41     if(val.length > 2){ 
42       app.queryAutocomplete(val, function(err, data){ 
43         if(err) return console.log(err); 
44         if(data.features) app.options = data.features; 
45         app.renderResultsList(); 
46       }) 
47     }else{ 
48       app.clearList(); 
49     } 
50   }, 
51 
 
52   queryAutocomplete: throttle(function(text, callback){ 
53     $.ajax({ 
54       url: 'https://search.mapzen.com/v1/autocomplete?text=' + text + '&api_key=' + app.mapzenKey,  
55       success: function(data, status, req){ 
56         callback(null, data); 
57       }, 
58       error: function(req, status, err){ 
59         callback(err) 
60       } 
61     }) 
62   }, 150), 
63 
 
64   renderResultsList: function(){ 
65     var resultsList = $('#results-list'); 
66     resultsList.empty(); 
67 
 
68     var results = app.options.map(function(feature){ 
69       var li = $('<li class="results-list-item">' + feature.properties.label + '</li>'); 
70       li.on('click', function(){ 
71         app.selectItem(feature); 
72       }) 
73       return li; 
74     }) 
75 
 
76     resultsList.append(results); 
77 
 
78     if(app.options.length > 0){ 
79       resultsList.removeClass('hidden'); 
80     }else{ 
81       resultsList.addClass('hidden'); 
82     } 
83   }, 
84 
 
85   selectItem: function(feature){ 
86     app.selection[app.activeSearch] = feature; 
87     var elId = '#search-' + app.activeSearch + '-input'; 
88     $(elId).val(feature.properties.label); 
89     app.clearList(); 
90   }, 
91 
 
92   clearList: function(e){ 
93     app.options = []; 
94     app.renderResultsList(); 
95   }, 
96 
 
97   clearSearch: function(e){ 
98     var elId = '#search-' + e.data.input + '-input'; 
99     $(elId).val('').trigger('keyup'); 
100     app.selection[e.data.input] = {}; 
101   } 
102 
 
103 } 
104 
 
105 // SETUP EVENT BINDING HERE 
106 
 
107 $('#search-from-input').on('keyup', {input:'from'}, app.typeAhead); 
108 $('#clear-from-search').on('click', {input:'from'}, app.clearSearch); 
{'fraction_non_alphanumeric': 0.17000417188151856, 'fraction_numerical': 0.07425949103045473, 'mean_word_length': 2.528329654157469, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '189270', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1740, 'n_words': 389}