1

I am trying to recreate this ui.Select function with data from an imported FeatureCollection.

In the original example the ui.Select function uses a dictionary that looks like this:

var places = {
  MTV: [-122.0849, 37.3887],
  PEK: [116.4056, 39.9097],
  ZRH: [8.536, 47.376]
};

So I would like to recreate with my own FeatureCollection. My attempt at code for creating the dictionary.

function get_coords(f){return f.centroid()}

var urban_areas = ee.Dictionary.fromLists(boroughs.aggregate_array('lad17nm'), 
                                          ee.List(boroughs.map(get_coords)));
print (urban_areas)

My code is here.

2
  • It would be helpful, if you'd isolate your problem into a separate File, with the Feature Collection to transform. I can't find boroughs in ur Code Commented Mar 27, 2019 at 14:03
  • @AlexanderVocaet I have made the Feature Collection public, hopefully that works.
    – kungphil
    Commented Mar 27, 2019 at 14:12

1 Answer 1

1

I made a 'toy' example to illustrate a possible solution.

var selector = ui.Select({placeholder:'fetching data..'})

var test_dict = ee.Dictionary.fromLists(['one', 'two'], [[0, 0], [1, 1]])

// Async fetch
test_dict.evaluate(function(dict){
  selector.items().reset(Object.keys(dict))
  selector.onChange(function(key){
    // make your process with value
    var value = dict[key]
    print(value)
  })
  selector.setPlaceholder('Select item..')
})

Map.add(selector)

link: https://code.earthengine.google.com/b183e792df540d4b4c9fbcc8b9a57b2b

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.