Skip to content

Developer Tools and Resources ​

This page provides a comprehensive overview of the tools, utilities, and resources available for developers working with the Mapbox GL JS codebase. Whether you're building the library from source, debugging rendering issues, or extending functionality, this guide will help you navigate the development ecosystem.

For more detailed information on specific topics, see the following sub-pages:

Development Environment Setup ​

To work effectively with the Mapbox GL JS codebase, you'll need to set up a development environment:

  1. Clone the repository: git clone https://github.com/mapbox/mapbox-gl-js.git
  2. Install dependencies: npm ci
  3. Run the development server: npm start

The development server will watch for changes to source files and automatically rebuild the library.

Build System Overview ​

Mapbox GL JS uses a modern build system centered around Rollup with plugins for TypeScript transpilation, module resolution, and minification. The build process creates multiple artifacts optimized for different use cases.

Build System Architecture ​

SVG
100%

Key Build Commands ​

The repository provides various npm scripts for different build scenarios:

CommandDescription
npm run build-devDevelopment build with source maps and debugging tools
npm run watch-devWatch mode for development
npm run build-prodProduction build (unminified)
npm run build-prod-minMinified production build
npm run build-cspContent Security Policy compliant build
npm run build-cssBuild CSS stylesheets
npm run build-style-specBuild the style specification module
npm run build-dtsGenerate TypeScript declaration files

Development Workflow ​

For active development, the repository provides a convenient start script:

npm start

This command runs multiple processes in parallel:

  1. Generates an access token script
  2. Watches CSS files for changes
  3. Watches source files and rebuilds in development mode
  4. Starts a static HTTP server on port 9966

Testing Infrastructure ​

Mapbox GL JS implements a comprehensive testing approach with multiple test types and runners. This ensures both unit-level correctness and proper visual rendering across browsers.

Testing Architecture ​

SVG
100%

Key Test Types ​

The codebase includes several types of tests:

  1. Unit Tests: Tests for individual components using Vitest

    • Run with npm run test-unit
  2. Rendering Tests: Visual regression tests for rendering capabilities

  3. Query Tests: Tests for spatial querying functionality

    • Run with npm run test-query
  4. Expression Tests: Tests for the style expression evaluation system

    • Run with npm run test-expressions
  5. Type Checking: Verification of TypeScript types

    • Run with npm run test-typings

Continuous Integration ​

CI/CD is handled by CircleCI, which runs tests on multiple platforms (Linux, macOS, Windows) and browsers (Chrome, Firefox, Safari). The configuration is defined in .circleci/config.yml

Debugging Tools ​

Mapbox GL JS includes several built-in debugging tools to help diagnose rendering issues and performance problems.

Debug UI ​

When using the development build, you can enable a debugging UI by setting the devtools option:

const map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/streets-v11',
    devtools: true
});

This UI provides controls for inspecting map properties, monitoring performance metrics, and visualizing internal state.

Debug Rendering Modes ​

Several debug rendering modes help visualize internal rendering structures:

  1. Collision Boxes: Visualize text and icon collision detection

  2. Tile Boundaries: Visualize tile loading and boundaries

    • Enable with map.showTileBoundaries = true
  3. Terrain Wireframe: Visualize terrain mesh (when terrain is enabled)

    • Enable with map.showTerrainWireframe = true

Performance Monitoring ​

For performance monitoring, use the renderstart and render events to measure frame rendering duration:

map.on('renderstart', () => { /* Record start time */ });
map.on('render', () => { /* Calculate frame duration */ });

Network Request Architecture ​

Mapbox GL JS implements a flexible system for handling network requests, supporting request transformation, authentication, and caching.

Request Pipeline ​

The networking system processes requests through the following pipeline:

  1. Request Creation: Generate a request for a resource (style, tile, etc.)
  2. Request Transformation: Apply custom transformations (if configured)
  3. Authentication: Add access tokens and credentials
  4. Request Execution: Send the HTTP request
  5. Response Caching: Cache responses for improved performance
  6. Response Parsing: Parse the response into the appropriate format

Customizing Requests ​

You can customize network requests by providing a transformRequest function:

const map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/streets-v11',
    transformRequest: (url, resourceType) => {
        // Modify the request
        return { url, headers, credentials, method };
    }
});

The resourceType parameter identifies the type of resource:

  • 'Style': Style JSON document
  • 'Source': Source data
  • 'Tile': Map tiles
  • 'Glyphs': Font glyphs
  • 'SpriteImage': Sprite images
  • 'SpriteJSON': Sprite metadata
  • 'Image': Custom images

Development Resources ​

Code Organization ​

The Mapbox GL JS codebase is organized into several main directories:

  • src/: Source code

    • src/style-spec/: Style specification implementation
    • src/render/: Rendering engine
    • src/geo/: Geographic utilities
    • src/ui/: UI components (markers, popups, controls)
    • src/util/: Utility functions
    • src/shaders/: GLSL shader code
  • test/: Test code

    • test/unit/: Unit tests
    • test/integration/: Integration tests (rendering, query)
    • test/build/: Build tests
  • debug/: Debugging utilities and examples

  • dist/: Build output (generated during build)

Development Tools ​

The repository includes several tools to help maintain code quality:

  1. Linting:

    • ESLint for JavaScript/TypeScript: npm run lint
    • Stylelint for CSS: npm run lint-css
    • Configuration in .stylelintrc
  2. Bundle Size Checking:

    • Ensures bundle size doesn't exceed limits
    • Run with npm run check-bundle-size
  3. TypeScript Suppressions Checking:

    • Monitors TypeScript error suppressions
    • Run with npm run check-ts-suppressions
  4. Code Generation:

    • Generates code for style specification, struct arrays, etc.
    • Run with npm run codegen

Community Resources ​

Beyond the code repository itself, these resources can help developers working with Mapbox GL JS:

  1. API Documentation: https://docs.mapbox.com/mapbox-gl-js/api/
  2. Style Specification: https://docs.mapbox.com/mapbox-gl-js/style-spec/
  3. Example Gallery: https://docs.mapbox.com/mapbox-gl-js/examples/
  4. GitHub Repository: https://github.com/mapbox/mapbox-gl-js
  5. Contributing Guide: CONTRIBUTING.md

Dependency Management ​

Mapbox GL JS uses npm for dependency management. The core dependencies are listed in package.json18-46 and developer dependencies in package.json48-122

Key dependencies include:

  • @mapbox/vector-tile: Vector tile decoding
  • geojson-vt: GeoJSON vector tile processing
  • earcut: Polygon triangulation for WebGL rendering
  • gl-matrix: Matrix math operations for WebGL
  • supercluster: Point clustering algorithm

The TypeScript type definitions are also included as dependencies to ensure type safety.

Using the Style Specification Tools ​

The Mapbox GL Style Specification is published as a separate npm package (@mapbox/mapbox-gl-style-spec) that includes several command-line utilities:

ToolDescription
gl-style-validateValidate a style against the specification
gl-style-formatFormat a style to make it more readable
gl-style-migrateMigrate a style from an older version
gl-style-compositeComposite multiple styles together

These tools are defined in src/style-spec/package.json39-44 and can be installed via npm or used directly from the repository.