Spatial Analysis in 2025: Key Trends Report
| Download Now
CARTO
Platform
Overview
Visualization
Analytics
App Development
Data Enrichment
AI Agents
Enterprise & Security
Pricing
CARTO for
Google Cloud
AWS
Azure
Snowflake
Databricks
Oracle
Solutions
By Industry
By Use Case
By Role
Telecoms
Icon/indus/Insurance-menu
Icon/indus/Insurance-menu-mobile
Insurance
Logistics
Real Estate
Financial Services
Retail
Marketing & Advertising
Mobility
All industries
Network Deployment
Catastrophe Modeling
Fraud Detection
Market Analysis
Environmental Management
Site Selection
Geomarketing
Data Monetization
IoT Analytics
Supply Chain Optimization
Healthcare Analytics
Territory Planning
All use cases
Data Analyst
Data Scientist
GIS Professional
Developer
Customers
Resources
Learn
Documentation
CARTO Academy
Blog
Reports
Glossary
Connect
Events
Partners
Webinars
Log inRequest a demo
Try for free
2050-01-01
1990-01-01
"ES", "GB"

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

Back to Help Center

How to customize the Map Viewer style

Customizing your map style using deck.gl declarative language

deck.gl supports a declarative system for describing layers and their props. This feature can be used to generate powerful visualizations directly from a JSON document. You can describe a visualization in abstract terms and view the results without needing to write JavaScript code.

This declarative system is used in deck.gl Playground and supports the layers from CARTO’s module. It is also the system used in CARTO Viewer to create and share tilesets visualizations.

The declarative language allows you to define the style and cartography of your visualization and set other general map options. Technically this language is based on JSON that gets transformed into Javascript objects and functions. Check out the official documentation on the JSON format for further technical details.

API reference

The declarative system creates deck.gl objects from a JSON representation. For instance, the initialViewState element in the JSON representation (declarative way) corresponds to a view state object when you are working with deck.gl in a programmatic way.

Usually the name-value pairs in the JSON representation correspond to object properties in deck.gl objects and the arrays correspond to JavaScript arrays. There are a couple of specific name-value pairs that are very useful:

  • @@type: Indicates the class of the object you want to create; for instance, for specifying the type of layer.
  • @@function: Specifies a function to be executed to evaluate a data accessor; for instance, for using helpers to specify the color assigned to features.

General parameters

initialViewState

Type: object

Description: Defines the initial view state for the visualization.

Property NameTypeDescription
latitudenumberLatitude at the map center.
longitudenumberLongitude at the map center.
zoomnumberInitial zoom level.
pitchnumberDefault: 0. Pitch angle (in degrees).
bearingnumberDefault: 0. Bearing angle (in degrees).
minZoomnumberDefault: 0. Min zoom level.
maxZoomnumberDefault: 20. Max zoom level.
minPitchnumberDefault: 0. Min pitch angle.
maxPitchnumberDefault: 60. Max pitch angle.

Example: Visualization centered at (0, 0) coordinates, zoom level 2.

{
  "initialViewState": {
    "latitude": 0,
    "longitude": 0,
    "zoom": 2
  }
}

views

Type: array

Description: Defines the views.

Each view object has the following properties:

Property NameTypeDescription
@@typestringUse MapView in the CARTO viewer for a Web Mercator Projection. Other types of views are also supported by the declarative syntax (but not in CARTO viewer) like FirstPersonView, GlobeView, OrthographicView or OrbitView.
controllerbooleanIndicates if the map is interactive (supports pan, zoom…) or not.
mapStylenumberBasemap to use in the map. It can be a full URL to a vector style, or it can be a string from the deck.gl basemap dictionary.

Example: Configuring an interactive MapView with the CARTO Positron basemap.

{
  "views": [
    {
      "@@type": "MapView",
      "controller": true,
      "mapStyle": "@@#CARTO_BASEMAP.POSITRON"
    }
  ]
}

Layers (Basic Properties)

Type: array

Description: Layers to overlay on the map. It is an array so you can compose multiple layers and define their blending functions.

Property NameTypeDescription
@@typestring“CartoBQTilerLayer” or “CartoSQLLayer”
datastringIn the case of a BigQuery TileSet you indicate the project.dataset.table_name. In the case of CartoSQLLayer you indicate the SQL used to retrieve data from your CARTO account.
credentialsobjectCARTO authentication credentials
credentials.usernameobjectCARTO username
credentials.apiKeyobjectCARTO API Key. For private maps you add the api key here, for a public map you can use default_public.
credentials.regionobjectDefault: us. Region where the user’s database is located; possible values are us or eu.
credentials.mapsUrlobjectDefault: https://{user}.carto.com/api/v1/map. For on-premise users, set the URL to point to your instance.
credentials.sqlUrlobjectDefault: https://{user}.carto.com/api/v2/sql. For on-premise users, set the URL to point to your instance.
pickablebooleanDefault: false. Indicates whether the layer responds to mouse pointer picking events.
uniqueIdPropertystringDefault: cartodb_id. Needed for highlighting a feature split across two or more tiles.
visiblebooleanDefault: true. Indicates whether the layer is visible or not.

Example: Visualizing a BigQuery Tileset Layer from a public tileset named cartobq.maps.osm_buildings that responds to mouse pointer picking events.

{
  "layers": [
    {
      "@@type": "CartoBQTilerLayer",
      "data": "cartobq.maps.osm_buildings",
      "credentials": {
        "username": "public",
        "apiKey": "default_public"
      },
      "pickable": true
    }
  ]
}

Layers (Styling Properties)

Styling properties for layers based on the GeoJsonLayer:

Property NameTypeDescription
autoHighlightbooleanDefault: false. When true, current object pointed to by mouse is highlighted with highlightColor. Requires pickable to be true.
elevationScalenumberDefault: 1. Elevation multiplier.
extrudedbooleanDefault: false. Whether to extrude the polygons based on the elevations provided by getElevation.
filledbooleanDefault: true. Whether to draw filled polygons (solid fill).
getFillColorarray or @@functionThe fill color in RGBA array format, or a function called on each object.
getLineColorarray or @@functionThe outline color in RGBA array format, or a function called on each object.
getRadiusnumber or @@functionThe radius of each object, in units specified by radiusUnits (default meters).
getLineWidthnumber or @@functionThe width of the outline, in units specified by lineWidthUnits (default meters).
highlightColorarray or @@functionDefault: [0, 0, 128, 128]. RGBA color to blend with the highlighted object.
lineJointRoundedbooleanDefault: false. If true, draw round joints. Otherwise draw miter joints.
lineWidthMinPixelsnumberDefault: 0. The minimum line width in pixels.
lineWidthScalenumberDefault: 1. The line width multiplier applied to all outlines.
opacitynumberDefault: 1. The opacity of the layer.
pointRadiusMinPixelsnumberThe minimum radius for point features in pixels.
strokedbooleanDefault: true. Whether to draw an outline around the polygon.

Creating visualizations

Style helpers

In common types of thematic map visualizations, a color is assigned to each feature based on a property. You can use the available helper functions:

  • colorBins: Data values are rounded down to the nearest value in the domain and styled with the corresponding color.
  • colorCategories: Data values listed in the domain are mapped one to one with corresponding colors in the range.
  • colorContinuous: Data values are interpolated linearly across values in the domain and styled with a blend of the corresponding color.

These helper functions support the following properties:

Property NameTypeDescription
attrstringAttribute or column to symbolize by.
domainarrayClass break values (colorBins), category list (colorCategories), or data range (colorContinuous).
colorsstring or arrayDefault: PurpOr. A valid named CARTOColors palette string or an array of RGBA colors.
nullColorarrayDefault: [204, 204, 204]. Color for null values.
othersColorarrayDefault: [119, 119, 119]. Only for colorCategories. Fallback color for unassigned categories.

ColorBins example

Create bins on a numeric feature property and assign a different color to each bin:

{
  "layers": [
    {
      "getFillColor": {
        "@@function": "colorBins",
        "attr": "aggregated_total",
        "domain": [10, 100, 1000, 10000, 100000, 1000000],
        "colors": "Temps"
      }
    }
  ]
}

ColorCategories example

Assign a different color to each feature depending on a string property value:

{
  "layers": [
    {
      "getFillColor": {
        "@@function": "colorCategories",
        "attr": "pop_cat",
        "domain": ["low", "medium", "high"],
        "colors": "RedOr"
      }
    }
  ]
}

ColorContinuous example

Assign a different color to each feature by interpolating between numeric property values:

{
  "layers": [
    {
      "getFillColor": {
        "@@function": "colorContinuous",
        "attr": "aggregated_total",
        "domain": [1, 100, 1000, 10000, 500000],
        "colors": "Peach"
      }
    }
  ]
}

Highlighting features

It is possible to highlight features on hover using the following attributes in the layer object:

{
  "autoHighlight": true,
  "pickable": true,
  "highlightColor": [232, 133, 113],
  "uniqueIdProperty": "id"
}

The uniqueIdProperty is needed to specify the attribute that identifies the feature uniquely across the dataset. It is case sensitive.

CARTO
carto-logo
  • Platform

  • Overview

  • Visualization

  • Analytics

  • App Development

  • Data Enrichment

  • Security & Governance

  • Gen AI

  • Pricing

  • Solutions

  • Data Analyst

  • Developer

  • Data Scientist

  • GIS Professional

  • By Industry

  • By Use Case

  • Resources

  • Customer Stories

  • Blog

  • Glossary

  • Documentation

  • Academy

  • Reports

  • Events

  • Webinars

  • Partners

  • Company

  • About us

  • Newsroom

  • Careers

  • Brand

  • Grants

Unlock the power of spatial analysis.

youtube logofacebook logotwitter logolinkedin logo

© CARTO 2024

Terms

Privacy Notice

Whistleblower Form