fetchMap
fetchMap
is a function designed to allow developers to retrieve layers and other details from a CARTO Builder map, in order to integrate them into custom applications. Developers can then choose to:
Replicate the map nearly exactly as configured in CARTO
Integrate those layers in the application with customizations
Use this information in any other way (eg: storing map metadata in a database)
Usage
Options
accessToken (optional): When the map that you're requesting is private/shared (in other words, not public) you will be required to pass a valid OAuth Access Token that represents a user with access to the map. Learn more about OAuth Access Tokens.
apiBaseUrl (optional): The base URL that hosts your APIs. It varies depending on your CARTO region/deployment method. By default it will use
https://gcp-us-east1.api.carto.com
which is the URL for the CARTO cloud US-based tenant, but it will be different if you operate in another region or in your own deployment. Learn how to obtain your API Base URL.autoRefresh (optional): Interval in seconds at which to autoRefresh the data from the map. If provided,
onNewData
must also be provided. Make sure your map's data freshness settings are consistent with the desired experience.onNewData (optional): Callback function that will be invoked whenever data in layers is changed. If provided,
autoRefresh
must also be provided.clientId (optional): An arbitrary string that can be used to identify the application, area or functionality that is performing the requests. It will be reflected later in the CARTO Activity Data, allowing developers to track usage in their applications.
headers (optional): An array of valid HTTP headers that will be attached to all requests originating from this source. This is useful to send any extra header or to control the cache in your sources.
Response
The response of fetchMap will be a long, structured JSON that contains all the necessary information in order for you to integrate that map in your own CARTO + deck.gl application.
We recommend developers to use Typescript, following the types available in @carto/api-client to build code that depends on fetchMap.
Recommended approach: import fetchMap from @carto/api-client
When importing from @carto/api-client, the
layers
array will contain properties for CARTO + deck.gl layers, not the layers themselves. In order to build the layers in deck.gl you can use your own logic, or use ourLayerFactory
implementation, available in this example.
Deprecation path: importing fetchMap from @deckgl/carto
,
When importing from @deck.gl/carto, the layers will be automatically compatible with CARTO + deck.gl, following the previous implementation of fetchMap. This may be removed in future major versions of deck.gl
Basic examples
Complete example
A fully working example of a simple application using fetchMap
can be found in our Examples gallery.
Last updated
Was this helpful?