3

I am new to Google Earth Engine and JavaScript. I have created a dropdown box and a button. The dropdown contains sub-district names from a shapefile. After clicking the button, the selected place is shown in the map as a polygon.

var subDist= table.aggregate_array('admin3Name');
var subDistDD= ui.Select([],'Loading...');
subDist.evaluate(function(sD){
  subDistDD.items().reset(sD);
  subDistDD.setPlaceholder('Select a Place');

});
var btnShow=ui.Button('Go To Place');
btnShow.onClick(function(){
  var placeName=subDistDD.getValue();
  var selectedSubdist=ee.Feature(table.filterMetadata('admin3Name','equals',placeName).first())
  .set({style: {fillColor: '00000000'}});
  Map.addLayer(selectedSubdist.style({styleProperty: "style"}));
  Map.centerObject(selectedSubdist,12);
});
var panel=ui.Panel({
  widgets:[subDistDD,btnShow],
  style: {width:'210px', resize:'horizontal'}
});
ui.root.insert(0, panel);

The program runs without error. But when the place is selected and the button is clicked, an error shows up: selectedSubdist.style is not a function.

Can anyone help me in this matter?

3

selectedSubdist is a Feature, style() is a function on FeatureCollection. Wrap it in a FeatureCollection wrapper.

ee.FeatureCollection([selectedSubdist]).style({styleProperty: "style"})
1
  • Thank you very much. It worked. I had to assign the FeatureCollection to another variable. Then add it as a layer. May 14 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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