ee.FeatureCollection.getMap

一种命令式函数,用于返回适合生成地图叠加层的地图 ID 和令牌。

返回一个可传递给 ee.data.getTileUrl 或 ui.Map.addLayer 的对象,其中包含一个额外的“image”字段,该字段包含一个 Collection.draw 图片,该图片封装了一个包含相应要素的 FeatureCollection。如果指定了回调,则为未定义。

用法返回
FeatureCollection.getMap(visParams, callback)MapId|Object
参数类型详细信息
此:featurecollectionFeatureCollectionFeatureCollection 实例。
visParams对象,可选可视化图表参数。目前仅允许一个参数,即包含 RGB 颜色字符串的“color”。如果未指定 vis_params,则使用颜色 #000000。
callback函数(可选)异步回调。如果未提供,则以同步方式进行调用。

示例

代码编辑器 (JavaScript)

// FeatureCollection of power plants in Belgium.
var fc = ee.FeatureCollection('WRI/GPPD/power_plants')
            .filter('country_lg == "Belgium"');

// Get MapId for styled FeatureCollection.
var mapId = fc.getMap({color: '800080'});
print('mapId for styled FeatureCollection', mapId);

// MapId can be used as an input to Map.addLayer to display the layer.
Map.setCenter(4.56, 50.78, 7);
Map.addLayer(mapId);

// MapId can be used as an input to ee.data.getTileUrl to fetch map tiles.
print('URL for zoom level 6 tile that includes majority of points',
      ee.data.getTileUrl(mapId, 32, 21, 6));

Python 设置

如需了解 Python API 和如何使用 geemap 进行交互式开发,请参阅 Python 环境页面。

import ee
import geemap.core as geemap

Colab (Python)

# FeatureCollection of power plants in Belgium.
fc = ee.FeatureCollection('WRI/GPPD/power_plants').filter(
    'country_lg == "Belgium"'
)

# Get MapId for styled FeatureCollection.
map_id = fc.getMapId({'color': '800080'})
display('map_id for FeatureCollection', map_id)

# MapId can be used as an input to geemap.Map.add_layer to display the layer.
m = geemap.Map()
m.set_center(4.56, 50.78, 7)
m.add_layer(map_id['image'])
display(m)

# MapId can be used as an input to ee.data.getTileUrl to fetch map tiles.
display(
    'URL for zoom level 6 tile that includes majority of points',
    ee.data.getTileUrl(map_id, 32, 21, 6),
)