I want to add layer in the map canvas in GEE with visual parameters coming from variables. for some reason it doesn't see my variables as numbers. Here is part of my code:

var min = image.reduceRegion({
  reducer: ee.Reducer.min(),
  geometry: fc,
  scale: 30,
  maxPixels: 1e9
var max = image.reduceRegion({
  reducer: ee.Reducer.max(),
  geometry: fc,
  scale: 30,
  maxPixels: 1e9
var maxXT = max.get('B10_1');
var minXT = min.get('B10_1');

//Thermal Visual parameters
var palette_1 = ['Black', 'Blue', 'White']
var Thermal_vis = {
   min: minXT,
   max: maxXT,
   palette: palette_1,
   bands: ['B10_1']
Map.addLayer(image.clip(fc), Thermal_vis, 'Thermal');

if i print my Thermal_vis variable I get:

Object (4 properties)
  bands: ["B10_1"]
    0: B10_1
  max: 54.652863769531294
  min: 47.71834838867191
  palette: ["Black","Blue","White"]
    0: Black
    1: Blue
    2: White

but I still get an error for adding the layer which says:

Thermal: Layer error: Image.visualize: Expected a number or list of numbers 
for field 'min'.

If I input the numbers manually within my visual parameters, the layer adds with no problem though. What is the problem?

2 Answers 2


If you use get(), GEE does not know which kind of object is returned. You could better make your variables server-side objects by casting them to ee.Dictionaries and ee.Numbers, so your browser does not stop responding (which it will do using getInfo() in longer scripts).

// cast to numbers
var maxXT = ee.Number(max.get('B10_1'));
var minXT = ee.Number(min.get('B10_1'));

//Thermal Visual parameters, cast to server-side objects
var palette_1 = ee.List(['Black', 'Blue', 'White']);
var Thermal_vis = ee.Dictionary({
   min: minXT,
   max: maxXT,
   palette: palette_1,
   bands: ['B10_1']

Then use getInfo() or evaluate() to get the dictionary on the client-side, necessary for input into Map.addLayer()

  • I just tried that and the output was all black actually. have you done this on your end?
    – B-C B.
    Jan 18, 2019 at 23:03
  • Make sure the values are non-null by printing the dictionary, and get the dictionary to the client-side.
    – Kuik
    Jul 1, 2020 at 8:32

I found the answer after trying a few different things. I have get the info from the object that is a number, by adding .getInfo() at the end of my variables.

var maxXT = max.get('B10_1').getInfo();
var minXT = min.get('B10_1').getInfo();

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.