公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ui.Map.add
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
向地图添加项。也可用于添加 widget(如 ui.Label)以及一些非 widget 对象(如 ui.Map.Layer)。
返回地图。
参数 | 类型 | 详细信息 |
---|
此:ui.map | ui.Map | ui.Map 实例。 |
item | 对象 | 要添加的商品。 |
示例
代码编辑器 (JavaScript)
// The default map in the Code Editor is a built-in ui.Map object called "Map".
// Let's refer to it as "defaultMap" for clarity.
var defaultMap = Map;
// ui.Map objects can be constructed. Here, a new map is declared.
var newMap = ui.Map({
center: {lat: 0, lon: 0, zoom: 1},
style: {position: 'bottom-right', width: '400px'}
});
// Add the newMap to the defaultMap;
defaultMap.add(newMap);
// Other UI widgets can be added to ui.Map objects, for example labels:
defaultMap.add(ui.Label('Default Map', {position: 'bottom-left'}));
newMap.add(ui.Label('New Map', {position: 'bottom-left'}));
// ...selectors:
defaultMap.add(ui.Select(['This', 'That', 'Other']));
// ...or buttons:
defaultMap.add(ui.Button('Click me'));
// You can also add ui.Map.Layer objects. Here, an ee.Geometry object
// is converted to a map layer and added to the default map.
var geom = ee.Geometry.Point(-122.0841, 37.4223);
var geomLayer = ui.Map.Layer(geom, {color: 'orange'}, 'Googleplex');
defaultMap.add(geomLayer);
defaultMap.centerObject(geom, 18);
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003e\u003ccode\u003eui.Map.add()\u003c/code\u003e inserts items like UI widgets (labels, buttons, selectors) and map layers onto a map.\u003c/p\u003e\n"],["\u003cp\u003eThis method accepts the map and the item to be added as arguments, and subsequently returns the map itself.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can utilize this function to enhance map visualization by incorporating interactive elements and data layers directly within their maps.\u003c/p\u003e\n"],["\u003cp\u003eThe provided examples illustrate adding a new map, labels, selectors, buttons, and geometry-based layers to the default or a newly created map.\u003c/p\u003e\n"]]],["The `Map.add(item)` function adds an object to a `ui.Map` instance, returning the modified map. The `item` can be a `ui.Map` itself, UI widgets like `ui.Label`, `ui.Select`, or `ui.Button`, or objects like `ui.Map.Layer`. Examples demonstrate adding a new map, labels, selectors, buttons, and a geometry layer to an existing map. These are done using default and newly created maps. The new elements are added to the map using `defaultMap.add()`.\n"],null,["# ui.Map.add\n\n\u003cbr /\u003e\n\nAdds an item to the map. Can also be used to add widgets like ui.Label as well as some non-widget objects like ui.Map.Layer.\n\n\u003cbr /\u003e\n\nReturns the map.\n\n| Usage | Returns |\n|-----------------|---------|\n| Map.add`(item)` | ui.Map |\n\n| Argument | Type | Details |\n|----------------|--------|----------------------|\n| this: `ui.map` | ui.Map | The ui.Map instance. |\n| `item` | Object | The item to add. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// The default map in the Code Editor is a built-in ui.Map object called \"Map\".\n// Let's refer to it as \"defaultMap\" for clarity.\nvar defaultMap = Map;\n\n// ui.Map objects can be constructed. Here, a new map is declared.\nvar newMap = ui.Map({\n center: {lat: 0, lon: 0, zoom: 1},\n style: {position: 'bottom-right', width: '400px'}\n});\n\n// Add the newMap to the defaultMap;\ndefaultMap.add(newMap);\n\n// Other UI widgets can be added to ui.Map objects, for example labels:\ndefaultMap.add(ui.Label('Default Map', {position: 'bottom-left'}));\nnewMap.add(ui.Label('New Map', {position: 'bottom-left'}));\n\n// ...selectors:\ndefaultMap.add(ui.Select(['This', 'That', 'Other']));\n\n// ...or buttons:\ndefaultMap.add(ui.Button('Click me'));\n\n// You can also add ui.Map.Layer objects. Here, an ee.Geometry object\n// is converted to a map layer and added to the default map.\nvar geom = ee.Geometry.Point(-122.0841, 37.4223);\nvar geomLayer = ui.Map.Layer(geom, {color: 'orange'}, 'Googleplex');\ndefaultMap.add(geomLayer);\ndefaultMap.centerObject(geom, 18);\n```"]]