项目作者: plainheart

项目描述 :
🚩 An AMap (https://lbs.amap.com) extension for Apache ECharts (https://github.com/apache/echarts)
高级语言: JavaScript
项目地址: git://github.com/plainheart/echarts-extension-amap.git
创建时间: 2019-02-24T12:38:24Z
项目社区:https://github.com/plainheart/echarts-extension-amap

开源协议:MIT License

下载


NPM version
Build Status
NPM Downloads
jsDelivr Downloads
License

AMap extension for Apache ECharts

中文说明

Online example on CodePen

This is an AMap extension for Apache ECharts which is used to display visualizations such as Scatter, Lines, Heatmap, and Pie.

Examples

Scatter: examples/scatter.html

Preview-Scatter

Heatmap: examples/heatmap.html

Preview-Heatmap

Lines: examples/lines.html

Preview-Lines

Pie: examples/pie.html (Since v1.11.0)

Preview-Pie

Installation

  1. npm install echarts-extension-amap --save

Import

Import packaged distribution file echarts-extension-amap.min.js and add AMap API script and ECharts script.

  1. <!-- import JavaScript API of AMap, please replace the ak with your own key and specify the version and plugins you need -->
  2. <!-- Plugin `AMap.CustomLayer` is required if you are using a version of library less than v1.9.0 -->
  3. <script src="https://webapi.amap.com/maps?v=1.4.15&key={ak}&plugin=AMap.Scale,AMap.ToolBar"></script>
  4. <!-- import ECharts -->
  5. <script src="/path/to/echarts.min.js"></script>
  6. <!-- import echarts-extension-amap -->
  7. <script src="dist/echarts-extension-amap.min.js"></script>

You can also import this extension by require or import if you are using webpack or any other bundler.

  1. // use require
  2. require('echarts');
  3. require('echarts-extension-amap');
  4. // use import
  5. import * as echarts from 'echarts';
  6. import 'echarts-extension-amap';

If importing dynamically the API script is needed, it’s suggested to use @amap/amap-jsapi-loader">amap-jsapi-loader or wrap a dynamic and asynchronized script loader manually through Promise.

Use CDN

jsDelivr

Use the latest version

https://cdn.jsdelivr.net/npm/echarts-extension-amap/dist/echarts-extension-amap.min.js

Use a specific version

amap@1.12.0/dist/echarts-extension-amap.min.js"">https://cdn.jsdelivr.net/npm/echarts-extension-amap@1.12.0/dist/echarts-extension-amap.min.js

unpkg

Use the latest version

https://unpkg.com/echarts-extension-amap/dist/echarts-extension-amap.min.js

Use a specific version

amap@1.12.0/dist/echarts-extension-amap.min.js"">https://unpkg.com/echarts-extension-amap@1.12.0/dist/echarts-extension-amap.min.js

This extension will register itself as a component of echarts after it is imported.

Apache ECharts 5 import on demand

Apache ECharts has provided us the new tree-shaking API since v5.0.1. This is how to use it in this extension:

  1. // import scatter, effectScatter and amap extension component on demand
  2. import * as echarts from 'echarts/core';
  3. import {
  4. ScatterChart,
  5. ScatterSeriesOption,
  6. EffectScatterChart,
  7. EffectScatterSeriesOption
  8. } from 'echarts/charts';
  9. import {
  10. TooltipComponent,
  11. TitleComponentOption
  12. } from 'echarts/components';
  13. import { CanvasRenderer } from 'echarts/renderers';
  14. import {
  15. install as AMapComponent,
  16. AMapComponentOption
  17. } from 'echarts-extension-amap/export';
  18. // import the official type definition for AMap 2.0
  19. import '@amap/amap-jsapi-types';
  20. // compose required options
  21. type ECOption = echarts.ComposeOption<
  22. | ScatterSeriesOption
  23. | EffectScatterSeriesOption
  24. | TitleComponentOption
  25. // unite AMapComponentOption with the initial options of AMap `AMap.MapOptions`
  26. > & AMapComponentOption<AMap.MapOptions>;
  27. // register renderers, components and charts
  28. echarts.use([
  29. CanvasRenderer,
  30. TooltipComponent,
  31. AMapComponent,
  32. ScatterChart,
  33. EffectScatterChart
  34. ]);
  35. // define ECharts option
  36. const option: ECOption = {
  37. // AMap extension option
  38. amap: {
  39. // ...
  40. },
  41. title: {
  42. // ...
  43. },
  44. series: [
  45. {
  46. type: 'scatter',
  47. // Use AMap coordinate system
  48. coordinateSystem: 'amap',
  49. // ...
  50. }
  51. ]
  52. // ...
  53. };

Usage

  1. option = {
  2. // load amap component
  3. amap: {
  4. // enable 3D mode
  5. // Note that it's suggested to enable 3D mode to improve echarts rendering.
  6. viewMode: '3D',
  7. // initial options of AMap
  8. // See https://lbs.amap.com/api/javascript-api/reference/map#MapOption for details
  9. // initial map center [lng, lat]
  10. center: [108.39, 39.9],
  11. // initial map zoom
  12. zoom: 4,
  13. // whether the map and echarts automatically handles browser window resize to update itself.
  14. resizeEnable: true,
  15. // customized map style, see https://lbs.amap.com/dev/mapstyle/index for details
  16. mapStyle: 'amap://styles/dark',
  17. // whether echarts layer should be rendered when the map is moving. Default is true.
  18. // if false, it will only be re-rendered after the map `moveend`.
  19. // It's better to set this option to false if data is large.
  20. renderOnMoving: true,
  21. // the zIndex of echarts layer for AMap, default value is 2000.
  22. // deprecated since v1.9.0, use `echartsLayerInteractive` instead.
  23. echartsLayerZIndex: 2019,
  24. // whether echarts layer is interactive. Default value is true
  25. // supported since v1.9.0
  26. echartsLayerInteractive: true,
  27. // whether to enable large mode. Default value is false
  28. // supported since v1.9.0
  29. largeMode: false
  30. // Note: Please DO NOT use the initial option `layers` to add Satellite/RoadNet/Other layers now.
  31. // There are some bugs about it, we can use `amap.add` instead.
  32. // Refer to the codes at the bottom.
  33. // More initial options...
  34. },
  35. series: [
  36. {
  37. type: 'scatter',
  38. // use `amap` as the coordinate system
  39. coordinateSystem: 'amap',
  40. // data items [[lng, lat, value], [lng, lat, value], ...]
  41. data: [[120, 30, 8], [120.1, 30.2, 20]],
  42. encode: {
  43. // encode the third element of data item as the `value` dimension
  44. value: 2
  45. }
  46. }
  47. ]
  48. };
  49. // Get AMap extension component
  50. var amapComponent = chart.getModel().getComponent('amap');
  51. // Get the instance of AMap
  52. var amap = amapComponent.getAMap();
  53. // Add some controls provided by AMap.
  54. amap.addControl(new AMap.Scale());
  55. amap.addControl(new AMap.ToolBar());
  56. // Add SatelliteLayer and RoadNetLayer to map
  57. var satelliteLayer = new AMap.TileLayer.Satellite();
  58. var roadNetLayer = new AMap.TileLayer.RoadNet();
  59. amap.add([satelliteLayer, roadNetLayer]);
  60. // Add a marker to map
  61. amap.add(new AMap.Marker({
  62. position: [115, 35]
  63. }));
  64. // Make the overlay layer of AMap interactive
  65. amapComponent.setEChartsLayerInteractive(false);