Somebody else in our CartoDB organisation has created a map.
I need to use the Static Maps API to get a .jpg image from the map, as described here. I'll be storing the .jpg locally and serving it up to a customer via our own API.
I've tried various values for the :token
parameter, but none seems to work:
- map name (slightly complicated because it contains a space, which I've substituted with both + and %20)
- our API key (we use CartoDB.js elsewhere in our organisation)
- the GUID in the three samples I see when on
https://
I click "publish" on the map..cartodb.com/dashboard/maps
This leads me to construct a URL like:
https://
But when I try to visit the URL in my browser, I get the message:
{"errors":["Invalid or nonexistent map configuration token '
How do I find the layergroupid?
Answer
If you have a Map (named map if it has private data) created already in the Editor, you will be able to find it's template map name in the viz.json file of the map. (Available at the third link in the Publish button under the CartoDB.js title).
Inside your viz.json, look for "named_map" and "name"
{
type: "namedmap",
order: 1,
options: {
type: "namedmap",
user_name: "iriberri",
maps_api_template: "https://{user}.cartodb.com:443",
sql_api_template: "https://{user}.cartodb.com:443",
tiler_protocol: "http",
tiler_domain: "cartodb.com",
tiler_port: "80",
filter: "mapnik",
named_map: {
name: "tpl_59dc29e0_f006_11e5_9245_0e674067d321", <------ named map name
stat_tag: "59dc29e0-f006-11e5-9245-0e674067d321",
params: {
layer0: 1,
layer1: 1
},
Now you have your named map name you can instantiate it in order to get the layergroupid.
Notice that the layergroupid token will expire after some time, so each time that you need to use it you'll have to instantiate it. In order to instantiate it, no browser or javascript is required, just:
CURL -X POST \
-H 'Content-Type: application/json' \
-d '' \
'https://USERNAME.cartodb.com/api/v1/map/named/THE_MAP_NAME_IN_THE_VIZJSON?api_key=APIKEY'
And this will return a JSON object with the layergroupid and other information.
No comments:
Post a Comment