Take this code example, where mylabel
is a ui.Label
:
var mypt = ee.FeatureCollection(ee.Geometry.Point(Map.getCenter().coordinates()));
var states = ee.FeatureCollection('TIGER/2016/States');
var selectedstate = states.filterBounds(mypt);
var selstatename = selectedstate.first().get('NAME');
selstatename.evaluate(function(result) {
if (result) {
mylabel.setValue('State: ' + result.toString());
}
});
In the above simplified example, if the user has their map centered, say, over the ocean, then selectedstate will be a FeatureCollection with no Features in it. In that case, I can skip the following selstatename.first().get('NAME');
and selstatename.evaluate
I'm pretty sure there's got to be an easy way to check that, hopefully combined in the .filterBounds
step so I don't have to send requests to the server twice, if that makes sense?
THIS IS ANSWERED HERE: How to get several property values at once so there is only one call to .`evaluate`
No comments:
Post a Comment