All Projects → mapbox → mapbox-gl-traffic

mapbox / mapbox-gl-traffic

Licence: BSD-3-Clause license
Show and hide traffic layers in your Mapbox GL traffic style

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Mapbox GL Traffic Build Status npm

Add a traffic toggle control to Mapbox GL JS.

🌐 Check the demo

demo

Usage

mapbox-gl-traffic is a Mapbox GL JS plugin that you can easily add on top of your map. Check index.html for a complete example.

Make sure to include the CSS and JS files.

When using NPM

Check how to use Mapbox GL JS in a module bundler.

npm install --save mapbox-gl @mapbox/mapbox-gl-traffic
const mapboxgl = require('mapbox-gl')
const MapboxTraffic = require('@mapbox/mapbox-gl-traffic');
const map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/traffic-night-v2',
    center: [-77.0259, 38.9010],
    zoom: 9
});
map.on('load', () => {
    map.addControl(new MapboxTraffic());
});

Examples

API

Table of Contents

MapboxTraffic

Create a new Mapbox GL JS plugin that allows you to hide and show traffic layers in your map and an optional toggle button.

Parameters

  • options object Options to configure the plugin.
    • options.showTraffic boolean Show or hide traffic overlay by default. (optional, default false)
    • options.showTrafficButton boolean Show a toggle button to turn traffic on and off. (optional, default true)
    • options.trafficSource RegExp The traffic source regex used to determine whether a layer displays traffic or not. (optional, default /mapbox-traffic-v\d/)

toggleTraffic

Toggle visibility of traffic layer.

Develop

Run the linter and watch for changes to rebuild with browserify.

npm install
npm run test
npm run watch

Create a minified standalone build.

npm install
npm run build
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].