ee.FeatureCollection.getMap

Một hàm bắt buộc trả về mã nhận dạng và mã thông báo bản đồ, phù hợp để tạo lớp phủ Bản đồ.

Trả về một đối tượng có thể được truyền đến ee.data.getTileUrl hoặc ui.Map.addLayer, bao gồm một trường "image" bổ sung, chứa một hình ảnh Collection.draw bao bọc một FeatureCollection chứa đối tượng này. Không xác định nếu bạn chỉ định một lệnh gọi lại.

Cách sử dụngGiá trị trả về
FeatureCollection.getMap(visParams, callback)MapId|Object
Đối sốLoạiThông tin chi tiết
this: featurecollectionFeatureCollectionĐối tượng FeatureCollection.
visParamsĐối tượng, không bắt buộcCác thông số trực quan hoá. Hiện tại, bạn chỉ được phép dùng một tham số là "color", chứa một chuỗi màu RGB. Nếu bạn không chỉ định vis_params, thì màu #000000 sẽ được dùng.
callbackHàm, không bắt buộcMột lệnh gọi lại không đồng bộ. Nếu không được cung cấp, lệnh gọi sẽ được thực hiện đồng bộ.

Ví dụ

Trình soạn thảo mã (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));

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap cho quá trình phát triển tương tác.

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