TransWikia.com

Incorporate location selection drop-down widget into split panel Earth Engine App

Geographic Information Systems Asked on August 28, 2021

I am relatively new to using the ui module for creating Earth Engine Apps. I used the split panel code from the Earth Engine example apps https://google.earthengine.app/view/split-panel to create my own version for viewing NAIP imagery over time.

I am interested in taking this a step further, where I can add in a drop down widget that will allow my end users to select different locations, and the app will subsequently zoom to their selection. I am using a FeatureCollection of locations from which I derive the list for selection.

I have found a snippet of code which is getting me closer to what I am looking for (https://code.earthengine.google.com/2217e2c7de9571f3177fd7acdbdfd516) and I have added it underneath the split panel code. The panel and widget look good, but I am unable to get the app to zoom in to the location of interest. I believe it has to do with the callback function for the location selection widget, but I am uncertain exactly how to get this part of the script working correclty.

Would anyone happen to have a solution?

One Answer

You were almost there. Inside the onChange function in ui.Select object, you were setting the center of a new ui.Map object whereas what is being displayed on screen are leftMap and rightMap objects.

So change the function to:

var select = ui.Select({
  items: names.getInfo(),
  placeholder: ('Choose Area of Interest'),
  style: {width: '290px'},
  onChange: function(key) {
    // Map.clear(); //clears previous calculations from map upon new selection
    var selection = ee.Feature(fc.filter(ee.Filter.eq('name', key)).first());
    // print(selection)
    leftMap.centerObject(selection); //centers map on Plantation selection
    // show Plantation
    var layer = ui.Map.Layer(selection, {color:'blue'}, 'Plantation');
    leftMap.layers().set(1, layer); //adds Plantation selection to the map
    // rightMap.layers().set(0, layer); //adds Plantation selection to the map
    var conversion = ee.FeatureCollection(selection); //converts the Plantation selection into a feature collection for future analyses
  }
});

And the drop-down location selector will work as intended.

Link to modified code.

Correct answer by kkrao on August 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP