Step 4: Running the program
cartokit
compiles your map into a Mapbox GL JS program in real-time, making
it easy to transfer the code to your development environment.
A core goal of cartokit
is to provide access to your map’s code at all phases of the design process. There is no separate “Export” workflow here; the program is always available under the Program tab in the Editor.
Additionally, we strive to make cartokit
programs runnable without modification. In order to do that, we make some assumptions about the environment in which they’re run.
- We assume you’re using JavaScript modules (also called ECMAScript modules or ES modules), such that
import
statements are valid. - We assume you’re using a bundler or build system, such as Webpack, Rollup, Vite, or esbuild such that “bare”
import
statements likeimport mapboxgl from 'mapbox-gl';
are resolved correctly.
For this tutorial, we’ll use Vite’s vanilla
template to create a new vanilla JS project using the Vite build system. You can follow the instructions on scaffolding a Vite project to get started.
Once you have your project scaffolded, take the following steps:
-
Install
mapbox-gl
as a dependency: -
Apply the following diff to the root
index.html
file: -
Copy the program from the Program tab in the Editor and paste it into
src/main.js
. -
Replace
"<YOUR_MAPBOX_ACCESS_TOKEN>"
in the program with your own Mapbox access token. -
Run your
dev
command and navigate tohttp://localhost:5173
in your browser. You should see your map running in a web browser.sh npm run dev
sh pnpm dev
sh yarn dev
That’s it! With just a few code modifications, we’ve got our cartokit
-generated program running in our own local development environment. Notice that we wrote none of the core mapping code ourselves; cartokit
did all the heavy lifting for us!
Next steps
Congratulations on making your first map with cartokit
! For more specific questions on functionality, check out our Guides. Can’t find what you’re looking for or want to leave us some feedback? Let us know on GitHub or X. We can’t wait to see what you build, and happy mapping 🗺!