公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ui.Map.addLayer
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
将指定的 EE 对象作为图层添加到地图中。
返回新的地图图层。
用法 | 返回 |
---|
Map.addLayer(eeObject, visParams, name, shown, opacity) | ui.Map.Layer |
参数 | 类型 | 详细信息 |
---|
此:ui.map | ui.Map | ui.Map 实例。 |
eeObject | Collection|Feature|Image|MapId | 要添加到地图中的对象。 |
visParams | FeatureVisualizationParameters|ImageVisualizationParameters,可选 | 可视化图表参数。对于 Image 和 ImageCollection,请参阅 ee.data.getMapId 以了解有效参数。对于 Feature 和 FeatureCollection,唯一支持的键是“color”,以 RRGGBB 格式的 6 字符十六进制字符串表示。 |
name | 字符串,可选 | 图层的名称。默认值为“Layer N”。 |
shown | 布尔值,可选 | 一个标志,用于指示图层是否应默认处于开启状态。 |
opacity | 数字,可选 | 图层的不透明度,以介于 0 到 1 之间的数字表示。默认为 1。 |
示例
代码编辑器 (JavaScript)
// Define a ui.Map widget and add it to the cleared ui.root.
var map = ui.Map();
ui.root.clear();
ui.root.add(map);
map.setCenter(-121.87, 37.44, 9);
// A Sentinel-2 surface reflectance image.
var image = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');
// 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 for images and features, controlling aspects like color, opacity, and stretch.\u003c/p\u003e\n"],["\u003cp\u003eThis function accepts Earth Engine objects (Image, Feature, Geometry, Collections) and styling options to control their visual representation.\u003c/p\u003e\n"],["\u003cp\u003eLayers can be named and controlled for initial visibility.\u003c/p\u003e\n"],["\u003cp\u003eThe function returns the added layer as a \u003ccode\u003eui.Map.Layer\u003c/code\u003e object for further manipulation.\u003c/p\u003e\n"]]],[],null,["# ui.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| this: `ui.map` | ui.Map | The ui.Map instance. |\n| `eeObject` | Collection\\|Feature\\|Image\\|MapId | 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 6-character hex string in the RRGGBB format. |\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// Define a ui.Map widget and add it to the cleared ui.root.\nvar map = ui.Map();\nui.root.clear();\nui.root.add(map);\nmap.setCenter(-121.87, 37.44, 9);\n\n// A Sentinel-2 surface reflectance image.\nvar image = ee.Image('COPERNICUS/S2_SR/20210109T185751_20210109T185931_T10SEG');\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```"]]