ee.FeatureCollection.getMap

這個必要函式會傳回地圖 ID 和權杖,適合用於產生地圖疊加層。

傳回可傳遞至 ee.data.getTileUrl 或 ui.Map.addLayer 的物件,包括額外的「image」欄位,其中包含包裝這個 FeatureCollection 的 Collection.draw 圖片。如果指定了回呼,則為未定義。

用量傳回
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 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

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),
)