公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ui.Map.getBounds
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
以 [west, south, east, north] 格式返回当前地图视图的边界(以度为单位)。
用法 | 返回 |
---|
Map.getBounds(asGeoJSON) | GeoJSONGeometry|List<Number>|String |
参数 | 类型 | 详细信息 |
---|
此:ui.map | ui.Map | ui.Map 实例。 |
asGeoJSON | 布尔值,可选 | 如果为 true,则以 GeoJSON 格式返回地图边界。 |
示例
代码编辑器 (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);
// You can set the viewport of a ui.Map to be centered on an object.
// Here, the defaultMap is centered on a point with a selected zoom level.
var geom = ee.Geometry.Point(-122.0841, 37.4223);
defaultMap.centerObject(geom, 18);
defaultMap.addLayer(geom, {color: 'orange'}, 'Googleplex');
// Map extent can be fetched using the ui.Map.getBounds method.
print('defaultMap bounds as a list',
defaultMap.getBounds());
print('defaultMap bounds as a dictionary',
ee.Dictionary.fromLists(['w', 's', 'e', 'n'], defaultMap.getBounds()));
print('defaultMap bounds as GeoJSON',
defaultMap.getBounds({asGeoJSON: true}));
// Map center point can be fetched using the ui.Map.getCenter method.
print('defaultMap center as a Point geometry', defaultMap.getCenter());
// Map zoom level can be fetched using the ui.Map.getZoom method.
print('defaultMap zoom level', defaultMap.getZoom());
// Map scale can be fetched using the ui.Map.getScale method.
print('defaultMap approximate pixel scale', defaultMap.getScale());
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003e\u003ccode\u003eMap.getBounds()\u003c/code\u003e returns the current map view's boundaries in degrees as a list: \u003ccode\u003e[west, south, east, north]\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIt can return the bounds as a GeoJSON object by setting the \u003ccode\u003easGeoJSON\u003c/code\u003e argument to \u003ccode\u003etrue\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egetBounds()\u003c/code\u003e method is called on a \u003ccode\u003eui.Map\u003c/code\u003e object, which represents the map in the Earth Engine Code Editor.\u003c/p\u003e\n"],["\u003cp\u003eThis function is useful for determining the geographic area currently displayed on the map.\u003c/p\u003e\n"]]],[],null,["# ui.Map.getBounds\n\n\u003cbr /\u003e\n\nReturns the bounds of the current map view, as a list in the format \\[west, south, east, north\\] in degrees.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|--------------------------------|-----------------------------------------|\n| Map.getBounds`(`*asGeoJSON*`)` | GeoJSONGeometry\\|List\\\u003cNumber\\\u003e\\|String |\n\n| Argument | Type | Details |\n|----------------|-------------------|-----------------------------------------|\n| this: `ui.map` | ui.Map | The ui.Map instance. |\n| `asGeoJSON` | Boolean, optional | If true, returns map bounds as GeoJSON. |\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// You can set the viewport of a ui.Map to be centered on an object.\n// Here, the defaultMap is centered on a point with a selected zoom level.\nvar geom = ee.Geometry.Point(-122.0841, 37.4223);\ndefaultMap.centerObject(geom, 18);\ndefaultMap.addLayer(geom, {color: 'orange'}, 'Googleplex');\n\n// Map extent can be fetched using the ui.Map.getBounds method.\nprint('defaultMap bounds as a list',\n defaultMap.getBounds());\nprint('defaultMap bounds as a dictionary',\n ee.Dictionary.fromLists(['w', 's', 'e', 'n'], defaultMap.getBounds()));\nprint('defaultMap bounds as GeoJSON',\n defaultMap.getBounds({asGeoJSON: true}));\n\n// Map center point can be fetched using the ui.Map.getCenter method.\nprint('defaultMap center as a Point geometry', defaultMap.getCenter());\n\n// Map zoom level can be fetched using the ui.Map.getZoom method.\nprint('defaultMap zoom level', defaultMap.getZoom());\n\n// Map scale can be fetched using the ui.Map.getScale method.\nprint('defaultMap approximate pixel scale', defaultMap.getScale());\n```"]]