I started with GoogleEngine recently and I was wondering how I can display all images of my collection as layers. I guess there is a better way than manually copy past / typing:

 var img1 = ee.Image('COPERNICUS/.....);
 var img2 = ....;
 var imgx = ....

 Map.addLayer (img1);

This questions was already asked in 2017 but I was unable to retrace the link/shared google group...

  • Displaying a lot of layers simultaneously would take a lot of time. – Dmitri Chubarov May 30 '18 at 11:05
  • My images are clipped, and since I can manually display 15 images, I guess "the time it takes" is not the problem... I',m just looking for an auto-way – Andreas Eugster May 30 '18 at 15:49

If you are only displaying a reasonable amount of images you can use a client-side function to add each image as a layer to the map.

Here's an example using 15 images in a polygon you would draw and rename roi.

var s2 = ee.ImageCollection("COPERNICUS/S2")

function addImage(image) { // display each image in collection
  var id = image.id
  var image = ee.Image(image.id)

s2.evaluate(function(s2) {  // use map on client-side
| improve this answer | |
  • the above code gives the output but displays only one band as constant. how to go about it – rao Jan 22 at 12:05

In addition to the answer of Kersten, you could also add this piece of code to easily view all the images by moving a slider:

var slider = ui.Slider();
slider.onSlide(function(value) {
  var int_value = value * (Map.layers().length() - 1) >> 0;
  for (var i = int_value + 1; i < Map.layers().length(); i++) {

It does this by changing the opacity of each layer.

| improve this answer | |

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.