3

I am working within Google Earth Engine and am trying to create a no-color/completely transparent color (no boarder and no fill). Below is a line of code where the first color should be the transparent "color". Basically I want my min value to not show up in the map at all.

    Map.addLayer(image, {min: 0, max: 3, palette: [transparent, '#0571b0', '#FFDF00', '#ca0020']},'image');

I have tried creating a variable to set a color as completely transparent (change the opacity to 0), but the palette command cannot take variables. Only strings. I've also read SVG fill color transparency, but do not understand how to change the opacity of that specific color without creating a variable (which again, palette doesn't allow). Lastly, I tried adding 00 to the end of another color, but that did not work either.

Any suggestions?

Update: I was never able to find a solution to this and ended up just going with a white back ground. It was purely for a nicer aesthetic look to allow a basemap to be seen. If I ever come across a solution, I'll be sure to post it.

Binx
  • 382
  • 7
  • 22
  • I don't have a dev environment to try but if they are CSS colors - can you try rgba()? i.e., rgba(0,0,0,0) – MrRobboto Oct 23 '19 at 19:45
  • so would `rgba(0,0,0,0)` replace the transparent text? – Binx Oct 23 '19 at 19:52
  • Yeah, that's what I would try - just because that syntax has been around a lot longer than the hex with alpha you tried (#0000 - shorthand). So I'd try: `Map.addLayer(image, {min: 0, max: 3, palette: ['rgba(0,0,0,0)', '#0571b0', '#FFDF00', '#ca0020']},'image');` Just one last note - rgba() function notation is supported by all browsers whereas hex with alpha doesn't work in Edge or IE if you happen to be using those... Ref to css colors: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#rgba() – MrRobboto Oct 23 '19 at 20:13

1 Answers1

2

I had the same question. I found the solution in the developer group.

See the answers: https://groups.google.com/g/google-earth-engine-developers/c/WcxtEIzudxw/m/GscOlsQhDgAJ

The Solution:

// create your previous mask

image = image.eq(1)

// mask and set the opacity

image = image.mask(image.mask().where(image.eq(0),0.0))