Page Summary
-
FeatureCollection.getMapis an imperative function that returns a map id and token. -
This function is suitable for generating a Map overlay and can also return an object for use with
ee.data.getTileUrlorui.Map.addLayer. -
The function accepts optional visualization parameters, specifically 'color', and an optional async callback.
-
Examples are provided for using
FeatureCollection.getMapin both JavaScript (Code Editor) and Python (Colab) to get a MapId and display the FeatureCollection or fetch map tiles.
Returns an object which may be passed to ee.data.getTileUrl or ui.Map.addLayer, including an additional 'image' field, containing a Collection.draw image wrapping a FeatureCollection containing this feature. Undefined if a callback was specified.
| Usage | Returns |
|---|---|
FeatureCollection.getMap(visParams, callback) | MapId|Object |
| Argument | Type | Details |
|---|---|---|
this: featurecollection | FeatureCollection | The FeatureCollection instance. |
visParams | Object, optional | The visualization parameters. Currently only one parameter, 'color', containing an RGB color string is allowed. If vis_params isn't specified, then the color #000000 is used. |
callback | Function, optional | An async callback. If not supplied, the call is made synchronously. |
Examples
Code Editor (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));
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), )