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...');
  subDistDD.setPlaceholder('Select a Place');

var btnShow=ui.Button('Go To Place');
  var placeName=subDistDD.getValue();
  var selectedSubdist=ee.Feature(table.filterMetadata('admin3Name','equals',placeName).first())
  .set({style: {fillColor: '00000000'}});
  Map.addLayer(selectedSubdist.style({styleProperty: "style"}));
var panel=ui.Panel({
  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.

1 Answer 1


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

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

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.