This content applies to a previous version of CARTO
In October 2021 we released a new version of our platform. You can find the latest documentation at docs.carto.com
Manipulating Your Data with CARTO Editor
Learn how to manipulate your data with CARTO Editor.
How can I show only one country/area/region on a map?
If you would like to have a map featuring only one region or a given set of boundaries, you can define this with a custom SQL query. From the CARTO Editor, click SQL and apply the following statement:
SELECT * FROM tablename WHERE name = 'country/region/area'
Create a new dataset from the query results and choose a solid color as your basemap. This ensures that only your selected area is displayed.
Tip: If you are comfortable working with the viz.json object, you can add custom code to your js file to set the zoom level and disable panning.
How can I hide a subLayer of a Named Map?
By using the MAPS API, you can create Named Maps, which enable you to create shareable maps from private data. The map configurations are stored on the server and given a unique name.
In order to hide a subLayer of a Named Map, there are two requirements; you must define internal placeholders objects in the map configuration file, and add a WHERE clause to define the placeholder variables in each subLayer.
- Instantiate the Named Map template with CARTO.js
- Create a visualization at runtime
- Hide the subLayer
Controlling the subLayer visibility requires that you use internal placeholders to define each layer in the WHERE clause:
layer.getSubLayer(0).show() // set the placeholder layer0=1
layer.getSubLayer(0).hide() // set layer0=0
Example Named Map configuration with placeholders:
{
"version": "0.0.1",
"name": "buques",
"auth": {
"method": "token",
"valid_tokens": []
},
"placeholders" : {
"layer0": {
"type": "number",
"default": 1
},
"layer1": {
"type": "number",
"default": 1
}
},
"layergroup": {
"version": "1.0.1",
"layers": [
{
"type": "cartodb",
"options": {
"cartocss_version": "2.1.1",
"cartocss": "...",
"sql": " SELECT * FROM t0 where <%= layer0 %> = 1",
"interactivity": "..."
}
},
{
"type": "cartodb",
"options": {
"cartocss_version": "2.1.1",
"cartocss": "...",
"sql": "SELECT * FROM t1 where <%= layer1 %> = 1",
"interactivity": "cartodb_id"
}
}
]
}
}
How to create a password-protected Named Map?
This high-level workflow describes how to create a password-protected Named Map, using the CARTO Engine APIs.
- Upload a dataset with the Import API, by defining the
api_keyand setting the dataset toprivateon import. - Create the config.json file for a Named Map, and include:
- an SQL query to select the private dataset
- set the auth method to
tokenwith one or more auth_tokens (passwords) - Post the config.json file to the Maps API to instantiate the Named Map definition
- Use the CARTO.js
createLayerfunction to create the Named Map, using thelayer.setAuthTokenmethod to set the password.
