Display stations on a map using a MVT response
Rendering stations on a map can be done performant and secure by using a tile service. In this example, the MVT response format will be used. MVT stands for Mapbox Vector Tiles and can be used on a Mapbox map.
View on Github
Requirements
- Chargetrip API key - to plot routes outside this region
- Mapbox API key - to display the map
- URQL - a lightweight graphQL client
Steps to take
- To render the tiles a tile service URL is required and requests made to Mapbox need to be transformed. Transforming the request helps with setting headers and controlling the tiles caching mechanism.
- After configuring the tile service URL and transforming the headers, it's required to set the filters. At least a
power
andconnector
filter needs to be present. This can be done by adding these as url query parameters.
Next steps
MVT is one format, but the Chargetrip tile response also supports GeoJSON. This will be explained in the next example.
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
import { displayMap } from './map';
/**
* This project illustrates how the MVT response from the Tile Service can be used in combination with Mapbox.
* The project structure contains:
*
* - map.js - All map rendering (tile server)
*/
displayMap();