Visualizing Geospatial Logic: A Deep Dive into Mapbox Data Workbench and MTS Recipes
Overview: The Evolution of Custom Data Workflows
For years, developers working with

The
Prerequisites
To get the most out of this tutorial, you should have a baseline understanding of:
- Geospatial Data Formats: Familiarity with
GeoJSON,CSV, orKMLstructures. - JSON Syntax: Since recipes are defined in JSON, knowing how to structure objects and arrays is essential.
- Mapbox Account: You need access to the Mapbox Studiodashboard, specifically the Data Manager V2 tab.
- Web Mapping Concepts: A basic grasp of how tilesets work at different zoom levels.
Key Libraries & Tools
- Mapbox Tiling Service(MTS): The underlying engine that processes raw geospatial data into vector tilesets.
- Data Workbench: The visual interface for managing data, editing attributes, and configuring recipes.
- MTS Recipes: JSON-based configuration files that tell MTS exactly how to transform data (e.g., simplifying geometry, aggregating attributes, or setting zoom ranges).
Code Walkthrough: Master the MTS Recipe
The heart of the
1. Defining Layer Attributes
In this snippet, we create a dynamic attribute called key. This logic allows the map to behave differently based on the user's zoom level. At low zooms (0-4), every feature gets the same key (CA). Once the user zooms past level 5, the key becomes a combination of the state and the specific county name.
{
"set": [
"key",
[
"concat",
[
"case",
[">=", ["zoom"], 0], "CA",
""
],
[
"case",
[">=", ["zoom"], 5], ["get", "county_name"],
""
]
]
]
}
2. Aggregation and Union
Once we have our dynamic key, we can tell CA, this union operation merges them into a single state-wide polygon. To ensure we don't lose our underlying data, we use an aggregate function to sum the vote counts from all merged counties.
{
"union": {
"group_by": ["key"],
"aggregate": {
"total_votes": "sum",
"dem_votes": "sum"
}
}
}
3. Managing Visual Density
To prevent a "wall of dots" when displaying point data like city markers, we use the highest_where_in_distance feature. This tells
{
"limit": [
"highest_where_in_distance",
16,
"population"
]
}
Syntax Notes: The Logic of Recipes
When writing
- Functional Expressions: MTS uses a syntax similar to Mapbox GL JSexpressions. These are arrays where the first element is the operator (e.g.,
"+","case","get"). - Zoom Sensitivity: The
["zoom"]global variable is your best friend. It allows you to change the resolution, the data density, and even which attributes are included as the user moves through the map. - Attribute Stripping: Always use
allowed_outputto specify exactly which fields you need. Sending unnecessary data to the client increases load times and costs. If your raw file has 50 columns but your map only uses 3, strip the other 47 in the recipe.
Practical Examples: From Transit to Elections
Case A: Urban Planning and Transit Analysis
A city consultant can upload existing bus routes and overlay them with "Opportunity Zones." Using the
Case B: Electoral Data Visualization
For a state-wide election map, you want the state to appear as a single color at a global view, but split into counties as the user zooms in. By using the union and sum aggregation logic shown in the walkthrough, you create a single tileset that serves both a high-level summary and a detailed local breakdown. This reduces the number of network requests the application has to make.
Tips & Gotchas
- The 300MB Limit: During the public preview, the maximum file size for a single upload is 300MB. If you have larger datasets, consider pre-processing or using the CLI-based Mapbox Tiling Servicefor the initial ingest.
- Beta Constraints: The Data Workbenchcurrently requires you to upload data directly into the tool. It cannot yet access tilesets you previously uploaded via the oldUploads API.
- Zoom Level Costs: Be cautious with
maxzoom. Because tile counts grow exponentially, setting a max zoom of 15 when 12 is sufficient can lead to significantly higher processing costs and longer wait times. - Visual vs. Data: Remember that the colors and styles you see in the workbench are for internal organization only. They do not carry over to your final map style. Final aesthetic decisions like hex codes and line weights happen in the Mapbox StudioStyle Editor.