Creating Layers From Shapefiles

This article describes how to use MapBox to transform shapefile data into a custom layer that you can view on CalTopo or SARTopo.

To start with, register for an account at MapBox under the pay-as-you-go plan.

Shapefiles consist of several files with the same name, but different extensions - typically at least .shp, .prj and .dbf. MapBox requires you to upload these files zipped together, only one shapefile per zipfile:


Click on the "Studio" link at the top right, then "Tilesets", then "New tileset".




A notification will show at the bottom right of the screen while MapBox is processing your upload:


Once complete, your tileset will show below the the list of standard MapBox tilesets:


Click on "styles" at the top right, then "more ways to create" under "Create a new style":


Click "Start blank" to open up MapBox Studio with a blank style:


At this point you want to add your data set twice, as both a line layer (to show the actual lines) and a symbol layer (to show labels). Click on "Add layer", then "No tileset, click to select, then scroll down to the tileset you uploaded and click on it:


Click "Create layer" to add this layer:


Repeat this process to add the second layer, but this time, change the layer type to "Symbol":


If necessary, use the location search tool at the top right of the screen to zoom in on your dataset:


Click on your symbol layer (look for the T icon to the left of the layer name), and the "Text" subtab should come up. Click on "Insert a data field" and use the popup to find the field you want to use as a label:


However, this inserts the field as a "formula", which has issues when rendering raster tiles for use with CalTopo. Make note of the field name, click "Reset value to default", and enter that field name surrounded by curly braces in the "Text field" box. If the field you wanted to use for a label was road_name, enter {road_name}


In order to render labels along lines, rather than horizontally, click on the Placement subtab, then the Placement field, then the line icon:


This leaves your labels overlapping the lines. In order to shift them upward, click on the Position subtab, the "Text anchor" field, and then the "Bottom" option:


You probably want to edit the line layer and make your lines wider:

Click on "Blank" at the top left and give you style a new name:


If you have multiple shapefiles, you can repeat these instructions to add additional shapefiles to the style. When the style looks good, click "Publish style" at the top right:


Click "Publish". If this is an update to a layer you've already been viewing in CalTopo, you may want to click "Publish as new", which will create a new layer with a new ID that will prevent any previously-viewed tiles from being cached and displaying your old style.


Make note of your style's ID. You can get this from the URL of the style editor, or from the Style URL menu option on your styles list (the "Style URL" is mapbox://style, your MapBox user ID, another slash slash, and then the style ID).



Make note of your MapBox access token by clicking on "account" at the top right:


On CalTopo, select Add New Layer -> Add Custom Source:

Select type Tile and Max Zoom 21. Enter a name, and select whether you want the layer to be an overlay (shows up in the list of checkboxes) or a base layer (shows up in the layer dropdown along with an opacity slider). For the URL template, enter:{Z}/{X}/{Y}?access_token=your_access_token

where your_mapbox_username is your mapbox username, your_style_id is the style ID you previously noted, and your_access_token is the access token you previously noted:


Hopefully you will now see your layer overlaid in CalTopo: