公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
Map.addLayer
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
将指定的 EE 对象作为图层添加到地图中。
返回新的地图图层。
用法 | 返回 |
---|
Map.addLayer(eeObject, visParams, name, shown, opacity) | ui.Map.Layer |
参数 | 类型 | 详细信息 |
---|
eeObject | 合集|功能|图片|RawMapId | 要添加到地图中的对象。 |
visParams | FeatureVisualizationParameters|ImageVisualizationParameters,可选 | 可视化图表参数。对于 Image 和 ImageCollection,请参阅 ee.data.getMapId 以了解有效参数。对于 Feature 和 FeatureCollection,唯一支持的键是“color”,其值可以是 CSS 3.0 颜色字符串,也可以是“RRGGBB”格式的十六进制字符串。如果 eeObject 是地图 ID,则忽略此参数。 |
name | 字符串,可选 | 图层的名称。默认值为“Layer N”。 |
shown | 布尔值,可选 | 一个标志,用于指示图层是否应默认处于开启状态。 |
opacity | 数字,可选 | 图层的不透明度,以介于 0 到 1 之间的数字表示。默认为 1。 |
示例
代码编辑器 (JavaScript)
// A Sentinel-2 surface reflectance image.
var image = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');
Map.setCenter(-121.87, 37.44, 9);
// Set multi-band RGB image visualization parameters. If the "bands" parameter
// is not defined, the first three bands are used.
var rgbVis = {
bands: ['B11', 'B8', 'B3'],
min: 0,
max: 3000
};
Map.addLayer(image, rgbVis, 'Multi-band RGB image');
// Set band-specific "min" and "max" properties.
var rgbVisBandSpec = {
bands: ['B11', 'B8', 'B3'],
min: [0, 75, 150],
max: [3500, 3000, 2500]
};
Map.addLayer(image, rgbVisBandSpec, 'Band-specific min/max');
// If you don't specify "min" and "max" properties, they will be determined
// from the data type range, often resulting in an ineffective color stretch.
Map.addLayer(image.select('B8'), null, 'Default visParams');
// If an image layer has already been styled, set "visParams" as null.
var imageRgb = image.visualize(rgbVis);
Map.addLayer(imageRgb, null, 'Pre-styled image');
// Use the "palette" parameter with single-band image inputs to define the
// linear color gradient to stretch between the "min" and "max" values.
var singleBandVis = {
min: 0,
max: 3000,
palette: ['blue', 'yellow', 'green']
};
Map.addLayer(image.select('B8'), singleBandVis, 'Single-band palette');
// Images within ImageCollections are automatically mosaicked according to mask
// status and image order. The last image in the collection takes priority,
// invalid pixels are filled by valid pixels in preceding images.
var imageCol = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate('2021-03-01', '2021-04-01');
Map.addLayer(imageCol, rgbVis, 'ImageCollection mosaic');
// FeatureCollection, Feature, and Geometry objects can be styled using the
// "color" parameter.
var featureCol = ee.FeatureCollection('WCMC/WDPA/current/polygons');
Map.addLayer(featureCol, {color: 'purple'}, 'FeatureCollection');
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eMap.addLayer()\u003c/code\u003e overlays Earth Engine objects like images and features onto the map as a new layer.\u003c/p\u003e\n"],["\u003cp\u003eVisualization parameters can be customized using the \u003ccode\u003evisParams\u003c/code\u003e argument to control how the layer is displayed.\u003c/p\u003e\n"],["\u003cp\u003eThis function accepts Earth Engine objects (like Image, FeatureCollection, Geometry), visualization parameters, layer name, visibility, and opacity as arguments.\u003c/p\u003e\n"],["\u003cp\u003eThe function returns the added map layer as a \u003ccode\u003eui.Map.Layer\u003c/code\u003e object, which can be further manipulated.\u003c/p\u003e\n"],["\u003cp\u003ePre-styled images or those with inherent visualization can be added by setting \u003ccode\u003evisParams\u003c/code\u003e to null.\u003c/p\u003e\n"]]],["The `Map.addLayer` function adds an Earth Engine object to a map as a layer, returning the new `ui.Map.Layer`. It accepts an `eeObject` (Collection, Feature, Image, or RawMapId), optional `visParams` for visualization, `name` for the layer's label, `shown` (boolean) to set default visibility, and `opacity` (0-1). Visualization parameters vary by object type; `color` is the only supported parameter for Features, while Images support `bands`, `min`, `max`, and `palette`. ImageCollections are mosaicked, and the last images take precedence.\n"],null,["# Map.addLayer\n\n\u003cbr /\u003e\n\nAdds a given EE object to the map as a layer.\n\n\u003cbr /\u003e\n\nReturns the new map layer.\n\n| Usage | Returns |\n|------------------------------------------------------------------------------|--------------|\n| `Map.addLayer(eeObject, `*visParams* `, `*name* `, `*shown* `, `*opacity*`)` | ui.Map.Layer |\n\n| Argument | Type | Details |\n|-------------|------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `eeObject` | Collection\\|Feature\\|Image\\|RawMapId | The object to add to the map. |\n| `visParams` | FeatureVisualizationParameters\\|ImageVisualizationParameters, optional | The visualization parameters. For Images and ImageCollection, see ee.data.getMapId for valid parameters. For Features and FeatureCollections, the only supported key is \"color\", as a CSS 3.0 color string or a hex string in \"RRGGBB\" format. Ignored when eeObject is a map ID. |\n| `name` | String, optional | The name of the layer. Defaults to \"Layer N\". |\n| `shown` | Boolean, optional | A flag indicating whether the layer should be on by default. |\n| `opacity` | Number, optional | The layer's opacity represented as a number between 0 and 1. Defaults to 1. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// A Sentinel-2 surface reflectance image.\nvar image = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');\nMap.setCenter(-121.87, 37.44, 9);\n\n// Set multi-band RGB image visualization parameters. If the \"bands\" parameter\n// is not defined, the first three bands are used.\nvar rgbVis = {\n bands: ['B11', 'B8', 'B3'],\n min: 0,\n max: 3000\n};\nMap.addLayer(image, rgbVis, 'Multi-band RGB image');\n\n// Set band-specific \"min\" and \"max\" properties.\nvar rgbVisBandSpec = {\n bands: ['B11', 'B8', 'B3'],\n min: [0, 75, 150],\n max: [3500, 3000, 2500]\n};\nMap.addLayer(image, rgbVisBandSpec, 'Band-specific min/max');\n\n// If you don't specify \"min\" and \"max\" properties, they will be determined\n// from the data type range, often resulting in an ineffective color stretch.\nMap.addLayer(image.select('B8'), null, 'Default visParams');\n\n// If an image layer has already been styled, set \"visParams\" as null.\nvar imageRgb = image.visualize(rgbVis);\nMap.addLayer(imageRgb, null, 'Pre-styled image');\n\n// Use the \"palette\" parameter with single-band image inputs to define the\n// linear color gradient to stretch between the \"min\" and \"max\" values.\nvar singleBandVis = {\n min: 0,\n max: 3000,\n palette: ['blue', 'yellow', 'green']\n};\nMap.addLayer(image.select('B8'), singleBandVis, 'Single-band palette');\n\n// Images within ImageCollections are automatically mosaicked according to mask\n// status and image order. The last image in the collection takes priority,\n// invalid pixels are filled by valid pixels in preceding images.\nvar imageCol = ee.ImageCollection('COPERNICUS/S2_SR')\n .filterDate('2021-03-01', '2021-04-01');\nMap.addLayer(imageCol, rgbVis, 'ImageCollection mosaic');\n\n// FeatureCollection, Feature, and Geometry objects can be styled using the\n// \"color\" parameter.\nvar featureCol = ee.FeatureCollection('WCMC/WDPA/current/polygons');\nMap.addLayer(featureCol, {color: 'purple'}, 'FeatureCollection');\n```"]]