Baidu Map Extension
The Baidu Map extension for Apache ECharts enables you to create geographic visualizations using Baidu Maps as the base layer. You can display scatter plots, line charts, heatmaps, and other visualizations on top of Baidu Maps.Overview
The Baidu Map extension provides a coordinate system and rendering layer that integrates seamlessly with ECharts, allowing you to visualize geographic data on Baidu Maps with all the power of ECharts charts.Supported Visualizations
You can use the following chart types with the Baidu Map coordinate system:- Scatter plots (
series-scatter) - Display points on the map - Line charts (
series-lines) - Show routes and connections - Heatmaps (
series-heatmap) - Visualize density and intensity - Custom series - Create custom geographic visualizations
Installation
Using Script Tags
Include the Baidu Map JS SDK and the ECharts extension:Using Webpack/Module Bundlers
If you’re using a module bundler:bmap component.
Basic Usage
Simple Scatter Plot
Configuration Options
BMap Component
Thebmap component accepts the following configuration options:
center
Map center coordinates in[longitude, latitude] format.
- Type:
Array<number> - Default:
[104.114129, 37.550339]
zoom
Map zoom level.- Type:
number - Default:
5 - Range: Typically 3-19 (depends on map configuration)
roam
Enable dragging and zooming.- Type:
boolean | string - Default:
false - Options:
false: Disable all interactionstrue: Enable both dragging and zooming'scale': Enable zooming only'move': Enable dragging only
mapStyle
Baidu Map 2.0 custom style configuration.- Type:
Object - Default:
{} - Reference: Baidu Map Style Editor (v2.0)
mapStyleV2
Baidu Map 3.0 custom style configuration.- Type:
Object - Default:
{} - Reference: Baidu Map Custom Styling (v3.0)
mapOptions
Baidu Map initialization options.- Type:
Object - Default:
{} - Reference: Baidu Map API Reference
Using Series with BMap
Scatter Series
Display points on the map:Lines Series
Draw lines between points (e.g., routes, connections):Heatmap Series
Create density heatmaps:Accessing the Baidu Map Instance
You can access the underlying Baidu Map instance to use Baidu Map’s native controls and features:Complete Example
Here’s a complete example showing air quality data for major Chinese cities:Examples
Official examples from the ECharts gallery:- Air Quality in Major Cities
- Beijing Bus Routes
- Beijing Bus Routes with Effect
- Hangzhou Popular Walking Routes (Heatmap)
API Reference
getBMap()
Get the Baidu Map instance.BMap.Map - The Baidu Map instance
Event: bmapRoam
Triggered when the map is panned or zoomed.Browser Support
The Baidu Map extension works in all modern browsers that support:- ECharts 5.0+
- Baidu Maps JavaScript API v2.0 or v3.0
Notes
- You must include the Baidu Map JS SDK before the extension
- An API key is required from Baidu Maps Open Platform
- Data coordinates should be in
[longitude, latitude]format - The
encodeoption can be used to specify which dimension represents the value - Only one
bmapcomponent is allowed per chart instance