4

The team at CartoDB have recently(last few days) made some useful updates that now allow public visualisation maps to reference data in private tables. The change has only been made in the last day or two to the public UI.

Is it possible to run a query on the maps visitations? I have a bit of html that uses cartodb.js to query the data based on some sliders.

I now getting an exception thrown in the console:

Uncaught Error: sql is read-only in NamedMaps

or

Uncaught Error: cartocss is read-only in NamedMaps

The code is:

subLayerOptions = {sql: "SELECT * FROM ......(dynamic query)...",};
layer.getSubLayer(0).set(subLayerOptions);

The code will work if I make the table public again.

1 Answer 1

6

It's not possible to change SQL or CartoCSS of a visualization with private data. The reason is pretty clear: if we allow to change SQL any user could read somehow your data.

So to cover your use case we introduced the concept of template maps. That allow you to create maps with hidden sql and cartocss but with some configurable parameters.

Basically it works creating a named map with templates in the SQL or cartocss:

placeholders: {
    color: {
        type: 'css_color',
        default: 'red'
    },
    cartodb_id: {
        type: 'number',
        default: 1
    }
},
layergroup: {
    //seehttps: //github.com/CartoDB/Windshaft/wiki/MapConfig-specification"version": "1.0.1",
    "layers": [
        {
            "type": "cartodb",
            "options": {
                "cartocss_version": "2.1.1",
                "cartocss": "#layer { polygon-fill: <%= color %>; }",
                "sql": "select * from european_countries_e WHERE cartodb_id = <%= cartodb_id %>"
            }
        }
    ]
}

You can read more about this here: https://github.com/CartoDB/Windshaft-cartodb/wiki/Template-maps

We are working on supporting this from cartodb.js, I will update this as I finish it.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.