0

Below I have shared the link. The issue - ui.Select remebers previous selections - even after being reset. Consequentially, if the user picks the same value twice - onChange is not activated. I am working in code editor with JavaScript

https://code.earthengine.google.com/4341dde5f526ef48f2eae20be42eb2b0

2 Answers 2

1

ui.Select does not change its value when a placeholder text is changed. Therefore, within Reset button while resetting the items (according to me unnecessary) and changing the placeholder text to "Choose a location2..." of the select button, you are not changing the value of select, but merely changing the text that is displayed on the select button. This is why a change is not registered when you click on the same location again. You can verify this by printing select.getValue() after you click on Reset.

I think you want to set the location value to default (0,0) when you click on reset. Then, if you again click on the original location, a change will be registered. To achieve that, you can change your reset function as follows:

var Reset=ui.Button({
  label: "Reset Dropdown",
  onClick: function () {
    select.setValue("Choose a location...")
    // select.items().reset();
    // select.items().reset(Object.keys(places));
    // select.setPlaceholder('Choose a location2...');
    }
    
});

And explicitly set the default location within the select button.

Link to complete code.

1

I found an answer by Noel Gorelick from developers forum, just add a line to onclick function, select.setValue(null, false) //JUST ADD THIS LINE :

//Try the following sequence:
//Select MTV (will print Registerd a change); then click reset dropdown (select will reset to placeholder); then select MTV again
//And nothing will happen; whereas if u select PEK or ZRH, it will print (registered a change)


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

var select = ui.Select({
  items: Object.keys(places),
  placeholder: 'Choose a location...',
  onChange: function(key) {
   Map.setCenter(places[key][0], places[key][1]);
   print('Registered a change');
  }
});

print(select);

var Reset=ui.Button({
 label: "Reset Dropdown",
 onClick: function () {
    select.setValue(null, false) //JUST ADD THIS LINE
 }
});

print(Reset);

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.