2

I would like to make items/list for ui.Select out of Feature Collection. I have developed a code, but I am receiving an error: enter image description here.

var subset = borders.filter(ee.Filter.eq('GID_0', 'UZB'));    
var filtered = ee.List(subset.aggregate_array('NAME_1'));
print(filtered);    

  var provincename_select = ui.Select({
  items: filtered,

  onChange: function(value) {
    var provincename = value;
  },
  style: {width: '200px'}
  });

print(provincename_select);   

https://code.earthengine.google.com/f6005af7e1bd5bfe8e8a598fbb749fdd

1 Answer 1

2

Ui-elements need client side inputs:

// UI-elements need client side inputs:

// option 1: getInfo()
var filtClient = filtered.getInfo();
      var countryName_select = ui.Select({
      items: filtClient,

      onChange: function(value) {
        var provincename = value;
      },
      style: {width: '200px'}
      });

print(countryName_select);   


// option 2: use evaluate
filtered.evaluate(function(evaluatedList){
      var countryName_select = ui.Select({
      items: evaluatedList,

      onChange: function(value) {
        var provincename = value;
      },
      style: {width: '200px'}
      });

print(countryName_select);   
})

link code with a sample featureCollection as yours was not shared

2
  • Thanks your suggestion! Is it possible two filter/remove the duplicates from the list? Commented Mar 25, 2020 at 16:59
  • Use distinct() on a list link
    – Kuik
    Commented Mar 26, 2020 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.