Feature and FeatureCollection Visualization

As with images, geometries and features, feature collections can be added to the map directly with Map.addLayer(). The default visualization will display the vectors with solid black lines and semi-opaque black fill. To render the vectors in color, specify the color parameter. The following displays the ‘RESOLVE’ ecoregions (Dinerstein et al. 2017) as the default visualization and in red:

// Load a FeatureCollection from a table dataset: 'RESOLVE' ecoregions.
var ecoregions = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017');

// Display as default and with a custom color.
Map.addLayer(ecoregions, {}, 'default display');
Map.addLayer(ecoregions, {color: 'FF0000'}, 'colored');

For additional display options, use featureCollection.draw(). Specifically, parameters pointRadius and strokeWidth control the size of points and lines, respectively, in the rendered FeatureCollection:

Map.addLayer(ecoregions.draw({color: '006600', strokeWidth: 5}), {}, 'drawn');

The output of draw() is an image with red, green and blue bands set according to the specified color parameter.

For more control over how a FeatureCollection is displayed, use image.paint() with the FeatureCollection as an argument. Unlike draw(), which outputs a three-band, 8-bit display image, image.paint() outputs an image with the specified numeric value ‘painted’ into it. Alternatively, you can supply the name of a property in the FeatureCollection which contains the numbers to paint. The width parameter behaves the same way: it can be a constant or the name of a property with a number for the line width. For example:

// Create an empty image into which to paint the features, cast to byte.
var empty = ee.Image().byte();

// Paint all the polygon edges with the same number and width, display.
var outline = empty.paint({
  featureCollection: ecoregions,
  color: 1,
  width: 3
Map.addLayer(outline, {palette: 'FF0000'}, 'edges');

Note that the empty image into which you paint the features needs to be cast prior to painting. This is because a constant image behaves as a constant: it is clamped to the initialization value. To color the feature edges with values set from a property of the features, set the color parameter to the name of the property with numeric values:

// Paint the edges with different colors, display.
var outlines = empty.paint({
  featureCollection: ecoregions,
  color: 'BIOME_NUM',
  width: 4
var palette = ['FF0000', '00FF00', '0000FF'];
Map.addLayer(outlines, {palette: palette, max: 14}, 'different color edges');

Both the color and width with which the boundaries are drawn can be set with properties. For example:

// Paint the edges with different colors and widths.
var outlines = empty.paint({
  featureCollection: ecoregions,
  color: 'BIOME_NUM',
  width: 'NNH'
Map.addLayer(outlines, {palette: palette, max: 14}, 'different color, width edges');

If the width parameter is not provided, the interior of the features is painted:

// Paint the interior of the polygons with different colors.
var fills = empty.paint({
  featureCollection: ecoregions,
  color: 'BIOME_NUM',
Map.addLayer(fills, {palette: palette, max: 14}, 'colored fills');

To render both the interior and edges of the features, paint the empty image twice:

// Paint both the fill and the edges.
var filledOutlines = empty.paint(ecoregions, 'BIOME_NUM').paint(ecoregions, 0, 2);
Map.addLayer(filledOutlines, {palette: ['000000'].concat(palette), max: 14}, 'edges and fills');

Send feedback about...

Google Earth Engine