// Let's add a dropdown with the location names using aggregate_array()
var items = India.aggregate_array('NAME_1');
items.evaluate(function(List) {
dropdown.items().reset(List),
dropdown.setPlaceholder('Select Location');
});
var dropdown =ui.Select({
placeholder: 'please wait...',
onChange : function(key){
var region = India.filter(ee.Filter.eq('NAME_1',key));
Map.clear();
Map.centerObject(region,7);
Map.addLayer(region,{},key);
}
});
//Main Panel
var panel = ui.Panel({
widgets: [dropdown],
style: {backgroundColor: 'white'},
layout: ui.Panel.Layout.flow('vertical')
});
//displaying the main panel
ui.root.insert(1,panel);
Here India
is the shapefile and NAME_1
is the column containing State names. I want to modify the code such that when the user selects a State, a new dropdown list with the Districts of that particular State is made available for selection. NAME_2
is the column name for Districts.
Best Answer
It's a matter of updating the second dropdown options when the first dropdown changes. Something like this:
https://code.earthengine.google.com/e474a44ca84553570e11cba1436664b8