From 21b1cea5e8630571c3ad280530857c94921922f1 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Wed, 21 Jan 2015 09:19:50 -0500 Subject: [PATCH 1/2] updates --- docs/Map-API.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/Map-API.md b/docs/Map-API.md index 045446cf..edd8e6e3 100644 --- a/docs/Map-API.md +++ b/docs/Map-API.md @@ -82,12 +82,16 @@ To get the `URL` to fetch the tiles you need to instantiate the map, where `temp curl -X POST 'http://{account}.cartodb.com/api/v1/map/named/:template_id' -H 'Content-Type: application/json' ``` -The response will return JSON with properties for the `layergroupid` and the timestamp (`last_updated`) of the last data modification. +The response will return JSON with properties for the `layergroupid`, `cdn_url`, and the timestamp (`last_updated`) of the last data modification. Here is an example response: ```javascript { + "cdn_url": { + "http": "ashbu.cartocdn.com", + "https": "cartocdn-ashbu.global.ssl.fastly.net" + }, "layergroupid": "c01a54877c62831bb51720263f91fb33:0", "last_updated": "1970-01-01T00:00:00.000Z" } @@ -222,7 +226,7 @@ Which returns JSON with the attributes defined, like: { c: 1, d: 2 } ``` -Notice UTF Grid and attributes endpoints need an intenger parameter, ``layer``. That number is the 0-based index of the layer inside the mapconfig. So in this case 0 returns the UTF grid tiles/attributes for layer 0, the only layer in the example mapconfig. If a second layer was available it could be returned with 1, a third layer with 2, etc. +Notice UTF Grid and attributes endpoints need an integer parameter, ``layer``. That number is the 0-based index of the layer inside the mapconfig. So in this case 0 returns the UTF grid tiles/attributes for layer 0, the only layer in the example mapconfig. If a second layer was available it could be returned with 1, a third layer with 2, etc. ### Create JSONP @@ -279,7 +283,7 @@ The main two differences compared to anonymous maps are: - **templates** Since the mapconfig is static it can contain some variables so the client can modify the map's appearance using those variables -Template maps are persistent with no preset expiration. They can only be created or deleted by a CartoDB user with a valid API_KEY (see auth section). +Template maps are persistent with no preset expiration. They can only be created or deleted by a CartoDB user with a valid API_KEY (see [auth section](http://docs.cartodb.com/cartodb-platform/maps-api.html#auth)). ### Create @@ -406,7 +410,7 @@ POST /api/v1/map/named/:template_name } ``` -The fields you pass as `params.json` depend on the variables allowed by the named map. If there are variables missing it will raise an error (HTTP 400) +The fields you pass as `params.json` depend on the variables allowed by the named map. If there are variables missing it will raise an error (HTTP 400). - **auth_token** *optional* if the named map needs auth From 58a54de5a6a29a20400c5161e4e10c210896e4c9 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Wed, 21 Jan 2015 09:29:57 -0500 Subject: [PATCH 2/2] Added section on CartoDB.js use --- docs/Map-API.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/Map-API.md b/docs/Map-API.md index edd8e6e3..5200f7dc 100644 --- a/docs/Map-API.md +++ b/docs/Map-API.md @@ -615,7 +615,7 @@ curl -X GET 'https://documentation.cartodb.com/api/v1/map/named?api_key=APIKEY' ### Getting a Specific Template -This gets the definition of a template +This gets the definition of a template. #### Definition @@ -648,3 +648,26 @@ curl -X GET 'https://documentation.cartodb.com/api/v1/map/named/:template_name?a "error": "Some error string here" } ``` + +### Use with CartoDB.js +Named maps can be used with CartoDB.js by specifying a named map in a layer source as follows. Named maps are treated almost the same as other layer source types in most other ways. + +```js +var layerSource = { + user_name: '{your_user_name}', + type: 'namedmap', + named_map: { + name: '{template_name}', + layers: [{ + layer_name: "layer1", + interactivity: "column1, column2, ..." + }] + } +} + +cartodb.createLayer('map_dom_id',layerSource) + .addTo(map_object); + +``` + +See [CartoDB.js](http://docs.cartodb.com/cartodb-platform/cartodb-js.html) methods [layer.setParams()](http://docs.cartodb.com/cartodb-platform/cartodb-js.html#layersetparamskey-value) and [layer.setAuthToken()](http://docs.cartodb.com/cartodb-platform/cartodb-js.html#layersetauthtokenauthtoken).