@naivemap/mapbox-gl-echarts-layer 0.1.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,17 +1,52 @@
1
- # mapbox-gl-echarts-layer
2
-
3
- [demo](https://huanglii.github.io/mapbox-gl-js-cookbook/example/echarts-scatter.html)
1
+ ## EChartsLayer class
4
2
 
5
3
  ```bash
6
- npm i @naivemap/mapbox-gl-echarts-layer
4
+ npm i @naivemap/mapbox-gl-echarts-layer echarts
5
+ ```
6
+
7
+ <b>Signature:</b>
8
+
9
+ ```typescript
10
+ export default class EChartsLayer implements mapboxgl.CustomLayerInterface
11
+ ```
12
+
13
+ <b>Implements:</b> mapboxgl.CustomLayerInterface
14
+
15
+ ## Constructors
16
+
17
+ | Constructor | Description |
18
+ | --- | --- |
19
+ | (constructor)(`id`: `string`, `option`: `ECOption`) | Constructs a new instance of the <code>EChartsLayer</code> class |
20
+
21
+ ### Parameters
22
+
23
+ **id** `(string)` The ID of the layer.
24
+
25
+ **option** `(ECOption)` The option of the [Lines graph](https://echarts.apache.org/zh/option.html#series-lines) and [Scatter (bubble) chart](https://echarts.apache.org/zh/option.html#series-scatter).
26
+
27
+ ```ts
28
+ export type ECOption = echarts.ComposeOption<
29
+ | TitleComponentOption
30
+ | TooltipComponentOption
31
+ | LegendComponentOption
32
+ | LinesSeriesOption
33
+ | ScatterSeriesOption
34
+ | EffectScatterSeriesOption
35
+ >
7
36
  ```
8
37
 
9
- ```js
10
- import EchartsLayer from '@naivemap/mapbox-gl-echarts-layer'
38
+ ### Methods
39
+
40
+ | Method | Description |
41
+ | ---------------------------------- | ------------------------------------------------------- |
42
+ | **setOption** `(option: ECOption)` | Call `echartsInstance.setOption()` to update the chart. |
43
+
44
+ ## Example
11
45
 
46
+ ```ts
12
47
  // echart option
13
48
  const option = {...}
14
- const layer = new EchartsLayer('layer-id', option)
49
+ const layer = new EChartsLayer('layer-id', option)
15
50
 
16
51
  map.addLayer(layer)
17
52
  ```
@@ -0,0 +1,104 @@
1
+ import { init, registerCoordinateSystem, } from 'echarts';
2
+ var COORDINATE_SYSTEM_NAME = 'mapboxgl-echarts';
3
+ var CoordinateSystem = /** @class */ (function () {
4
+ function CoordinateSystem(map) {
5
+ this.dimensions = ['x', 'y'];
6
+ this._mapOffset = [0, 0];
7
+ this.map = map;
8
+ }
9
+ CoordinateSystem.prototype.create = function (ecModel) {
10
+ var _this = this;
11
+ ecModel.eachSeries(function (seriesModel) {
12
+ if (seriesModel.get('coordinateSystem') === COORDINATE_SYSTEM_NAME) {
13
+ seriesModel.coordinateSystem = new CoordinateSystem(_this.map);
14
+ }
15
+ });
16
+ };
17
+ CoordinateSystem.prototype.dataToPoint = function (data) {
18
+ var px = this.map.project(data);
19
+ var mapOffset = this._mapOffset;
20
+ return [px.x - mapOffset[0], px.y - mapOffset[1]];
21
+ };
22
+ CoordinateSystem.prototype.pointToData = function (pt) {
23
+ var mapOffset = this._mapOffset;
24
+ var data = this.map.unproject([pt[0] + mapOffset[0], pt[1] + mapOffset[1]]);
25
+ return [data.lng, data.lat];
26
+ };
27
+ return CoordinateSystem;
28
+ }());
29
+ var EChartsLayer = /** @class */ (function () {
30
+ function EChartsLayer(id, ecOption) {
31
+ this._registered = false;
32
+ this.id = id;
33
+ this.type = 'custom';
34
+ this.renderingMode = '2d';
35
+ this._coordSystemName = COORDINATE_SYSTEM_NAME;
36
+ this._ecOption = ecOption;
37
+ }
38
+ EChartsLayer.prototype.onAdd = function (map) {
39
+ this._map = map;
40
+ this._createLayerContainer();
41
+ };
42
+ EChartsLayer.prototype.onRemove = function () {
43
+ var _a;
44
+ (_a = this._ec) === null || _a === void 0 ? void 0 : _a.dispose();
45
+ this._removeLayerContainer();
46
+ };
47
+ EChartsLayer.prototype.setOption = function (option) {
48
+ var _a;
49
+ (_a = this._ec) === null || _a === void 0 ? void 0 : _a.setOption(option);
50
+ };
51
+ EChartsLayer.prototype.render = function () {
52
+ if (!this._container) {
53
+ this._createLayerContainer();
54
+ }
55
+ if (!this._ec) {
56
+ this._ec = init(this._container);
57
+ this._prepareECharts();
58
+ this._ec.setOption(this._ecOption);
59
+ }
60
+ else {
61
+ if (this._map.isMoving()) {
62
+ this._ec.clear();
63
+ }
64
+ else {
65
+ this._ec.resize({
66
+ width: this._map.getCanvas().width,
67
+ height: this._map.getCanvas().height,
68
+ });
69
+ this._ec.setOption(this._ecOption);
70
+ }
71
+ }
72
+ };
73
+ EChartsLayer.prototype._prepareECharts = function () {
74
+ if (!this._registered) {
75
+ var coordinateSystem = new CoordinateSystem(this._map);
76
+ registerCoordinateSystem(this._coordSystemName, coordinateSystem);
77
+ this._registered = true;
78
+ }
79
+ var series = this._ecOption.series;
80
+ if (series) {
81
+ for (var i = series.length - 1; i >= 0; i--) {
82
+ // change coordinateSystem to mapboxgl-echarts
83
+ series[i]['coordinateSystem'] = this._coordSystemName;
84
+ // disable update animations
85
+ // series[i]['animation'] = false
86
+ }
87
+ }
88
+ };
89
+ EChartsLayer.prototype._createLayerContainer = function () {
90
+ var mapContainer = this._map.getCanvasContainer();
91
+ this._container = document.createElement('div');
92
+ this._container.style.width = this._map.getCanvas().style.width;
93
+ this._container.style.height = this._map.getCanvas().style.height;
94
+ mapContainer.appendChild(this._container);
95
+ };
96
+ EChartsLayer.prototype._removeLayerContainer = function () {
97
+ var _a;
98
+ if (this._container) {
99
+ (_a = this._container.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this._container);
100
+ }
101
+ };
102
+ return EChartsLayer;
103
+ }());
104
+ export default EChartsLayer;
@@ -0,0 +1,22 @@
1
+ /// <reference types="mapbox-gl" />
2
+ import { ComposeOption, EffectScatterSeriesOption, LegendComponentOption, LinesSeriesOption, ScatterSeriesOption, TitleComponentOption, TooltipComponentOption } from 'echarts';
3
+ export declare type ECOption = ComposeOption<TitleComponentOption | TooltipComponentOption | LegendComponentOption | LinesSeriesOption | ScatterSeriesOption | EffectScatterSeriesOption>;
4
+ export default class EChartsLayer implements mapboxgl.CustomLayerInterface {
5
+ id: string;
6
+ type: 'custom';
7
+ renderingMode?: '2d' | '3d' | undefined;
8
+ private _container;
9
+ private _map;
10
+ private _ec;
11
+ private _coordSystemName;
12
+ private _registered;
13
+ private _ecOption;
14
+ constructor(id: string, ecOption: ECOption);
15
+ onAdd(map: mapboxgl.Map): void;
16
+ onRemove(): void;
17
+ setOption(option: ECOption): void;
18
+ render(): void;
19
+ private _prepareECharts;
20
+ private _createLayerContainer;
21
+ private _removeLayerContainer;
22
+ }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var echarts_1 = require("echarts");
4
+ var COORDINATE_SYSTEM_NAME = 'mapboxgl-echarts';
5
+ var CoordinateSystem = /** @class */ (function () {
6
+ function CoordinateSystem(map) {
7
+ this.dimensions = ['x', 'y'];
8
+ this._mapOffset = [0, 0];
9
+ this.map = map;
10
+ }
11
+ CoordinateSystem.prototype.create = function (ecModel) {
12
+ var _this = this;
13
+ ecModel.eachSeries(function (seriesModel) {
14
+ if (seriesModel.get('coordinateSystem') === COORDINATE_SYSTEM_NAME) {
15
+ seriesModel.coordinateSystem = new CoordinateSystem(_this.map);
16
+ }
17
+ });
18
+ };
19
+ CoordinateSystem.prototype.dataToPoint = function (data) {
20
+ var px = this.map.project(data);
21
+ var mapOffset = this._mapOffset;
22
+ return [px.x - mapOffset[0], px.y - mapOffset[1]];
23
+ };
24
+ CoordinateSystem.prototype.pointToData = function (pt) {
25
+ var mapOffset = this._mapOffset;
26
+ var data = this.map.unproject([pt[0] + mapOffset[0], pt[1] + mapOffset[1]]);
27
+ return [data.lng, data.lat];
28
+ };
29
+ return CoordinateSystem;
30
+ }());
31
+ var EChartsLayer = /** @class */ (function () {
32
+ function EChartsLayer(id, ecOption) {
33
+ this._registered = false;
34
+ this.id = id;
35
+ this.type = 'custom';
36
+ this.renderingMode = '2d';
37
+ this._coordSystemName = COORDINATE_SYSTEM_NAME;
38
+ this._ecOption = ecOption;
39
+ }
40
+ EChartsLayer.prototype.onAdd = function (map) {
41
+ this._map = map;
42
+ this._createLayerContainer();
43
+ };
44
+ EChartsLayer.prototype.onRemove = function () {
45
+ var _a;
46
+ (_a = this._ec) === null || _a === void 0 ? void 0 : _a.dispose();
47
+ this._removeLayerContainer();
48
+ };
49
+ EChartsLayer.prototype.setOption = function (option) {
50
+ var _a;
51
+ (_a = this._ec) === null || _a === void 0 ? void 0 : _a.setOption(option);
52
+ };
53
+ EChartsLayer.prototype.render = function () {
54
+ if (!this._container) {
55
+ this._createLayerContainer();
56
+ }
57
+ if (!this._ec) {
58
+ this._ec = (0, echarts_1.init)(this._container);
59
+ this._prepareECharts();
60
+ this._ec.setOption(this._ecOption);
61
+ }
62
+ else {
63
+ if (this._map.isMoving()) {
64
+ this._ec.clear();
65
+ }
66
+ else {
67
+ this._ec.resize({
68
+ width: this._map.getCanvas().width,
69
+ height: this._map.getCanvas().height,
70
+ });
71
+ this._ec.setOption(this._ecOption);
72
+ }
73
+ }
74
+ };
75
+ EChartsLayer.prototype._prepareECharts = function () {
76
+ if (!this._registered) {
77
+ var coordinateSystem = new CoordinateSystem(this._map);
78
+ (0, echarts_1.registerCoordinateSystem)(this._coordSystemName, coordinateSystem);
79
+ this._registered = true;
80
+ }
81
+ var series = this._ecOption.series;
82
+ if (series) {
83
+ for (var i = series.length - 1; i >= 0; i--) {
84
+ // change coordinateSystem to mapboxgl-echarts
85
+ series[i]['coordinateSystem'] = this._coordSystemName;
86
+ // disable update animations
87
+ // series[i]['animation'] = false
88
+ }
89
+ }
90
+ };
91
+ EChartsLayer.prototype._createLayerContainer = function () {
92
+ var mapContainer = this._map.getCanvasContainer();
93
+ this._container = document.createElement('div');
94
+ this._container.style.width = this._map.getCanvas().style.width;
95
+ this._container.style.height = this._map.getCanvas().style.height;
96
+ mapContainer.appendChild(this._container);
97
+ };
98
+ EChartsLayer.prototype._removeLayerContainer = function () {
99
+ var _a;
100
+ if (this._container) {
101
+ (_a = this._container.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this._container);
102
+ }
103
+ };
104
+ return EChartsLayer;
105
+ }());
106
+ exports.default = EChartsLayer;
package/package.json CHANGED
@@ -1,42 +1,55 @@
1
- {
2
- "name": "@naivemap/mapbox-gl-echarts-layer",
3
- "version": "0.1.1",
4
- "description": "mapbox-gl-echarts-layer",
5
- "files": [
6
- "dist"
7
- ],
8
- "types": "./dist/mapbox-gl-echarts-layer.d.ts",
9
- "main": "./dist/mapbox-gl-echarts-layer.umd.js",
10
- "module": "./dist/mapbox-gl-echarts-layer.es.js",
11
- "exports": {
12
- ".": {
13
- "import": "./dist/mapbox-gl-echarts-layer.es.js",
14
- "require": "./dist/mapbox-gl-echarts-layer.umd.js"
15
- }
16
- },
17
- "scripts": {
18
- "dev": "vite",
19
- "lint": "eslint src --fix --ext .ts,.tsx,.vue,.js,.jsx",
20
- "prettier": "prettier --write .",
21
- "build": "vite build"
22
- },
23
- "repository": "https://github.com/naivemap/mapbox-gl-echarts-layer",
24
- "keywords": ["mapbox-gl", "echarts"],
25
- "license": "MIT",
26
- "peerDependencies": {
27
- "echarts": "^5.3.0"
28
- },
29
- "devDependencies": {
30
- "@types/mapbox-gl": "^2.6.1",
31
- "@types/node": "^17.0.15",
32
- "@typescript-eslint/eslint-plugin": "^5.10.2",
33
- "@typescript-eslint/parser": "^5.10.2",
34
- "echarts": "^5.3.0",
35
- "eslint": "^8.8.0",
36
- "eslint-config-prettier": "^8.3.0",
37
- "eslint-plugin-prettier": "^4.0.0",
38
- "prettier": "^2.5.1",
39
- "typescript": "^4.5.5",
40
- "vite": "^2.7.13"
41
- }
42
- }
1
+ {
2
+ "name": "@naivemap/mapbox-gl-echarts-layer",
3
+ "version": "0.3.2",
4
+ "description": "Integrate the Lines graph and Scatter (bubble) chart of Apache ECharts.",
5
+ "author": "huanglii <li.huangli@qq.com>",
6
+ "homepage": "https://github.com/naivemap/mapbox-gl-layers#readme",
7
+ "license": "MIT",
8
+ "main": "dist/js/index.js",
9
+ "module": "dist/es/index.js",
10
+ "exports": {
11
+ "./package.json": "./package.json",
12
+ ".": {
13
+ "import": "./dist/es/index.js",
14
+ "require": "./dist/js/index.js"
15
+ }
16
+ },
17
+ "types": "dist/js/index.d.ts",
18
+ "sideEffects": false,
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "keywords": [
23
+ "mapbox-gl",
24
+ "echarts",
25
+ "scatter",
26
+ "lines"
27
+ ],
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/naivemap/mapbox-gl-layers.git"
34
+ },
35
+ "scripts": {
36
+ "test": "echo \"Error: run tests from root\" && exit 1",
37
+ "build": "npm-run-all build:*",
38
+ "build:es": "tsc --outDir dist/es --module esnext --declaration false",
39
+ "build:js": "tsc",
40
+ "prepublishOnly": "npm-run-all build:*"
41
+ },
42
+ "bugs": {
43
+ "url": "https://github.com/naivemap/mapbox-gl-layers/issues"
44
+ },
45
+ "peerDependencies": {
46
+ "echarts": "^5.3.0"
47
+ },
48
+ "devDependencies": {
49
+ "@types/mapbox-gl": "^2.7.2",
50
+ "@types/node": "^17.0.36",
51
+ "echarts": "^5.3.2",
52
+ "npm-run-all": "^4.1.5"
53
+ },
54
+ "gitHead": "0d34a954e38a0366112328e2cceaafebece75e3e"
55
+ }
@@ -1,20 +0,0 @@
1
- /// <reference types="mapbox-gl" />
2
- export default class EchartsLayer {
3
- id: string;
4
- type: string;
5
- renderingMode: string;
6
- private _container;
7
- private _map;
8
- private _ec;
9
- private _coordSystemName;
10
- private _registered;
11
- private _ecOptions;
12
- constructor(id: string, ecOptions: any);
13
- onAdd(map: mapboxgl.Map): void;
14
- onRemove(): void;
15
- setOption(option: any): void;
16
- render(): void;
17
- private _prepareECharts;
18
- private _createLayerContainer;
19
- private _removeLayerContainer;
20
- }
@@ -1,87 +0,0 @@
1
- import * as echarts from "echarts";
2
- const COORDINATE_SYSTEM_NAME = "mapboxgl-echarts";
3
- class CoordinateSystem {
4
- constructor(map) {
5
- this.dimensions = ["x", "y"];
6
- this._mapOffset = [0, 0];
7
- this.map = map;
8
- }
9
- create(ecModel) {
10
- ecModel.eachSeries((seriesModel) => {
11
- if (seriesModel.get("coordinateSystem") === COORDINATE_SYSTEM_NAME) {
12
- seriesModel.coordinateSystem = new CoordinateSystem(this.map);
13
- }
14
- });
15
- }
16
- dataToPoint(data) {
17
- const px = this.map.project(data);
18
- const mapOffset = this._mapOffset;
19
- return [px.x - mapOffset[0], px.y - mapOffset[1]];
20
- }
21
- pointToData(pt) {
22
- const mapOffset = this._mapOffset;
23
- const data = this.map.unproject([pt[0] + mapOffset[0], pt[1] + mapOffset[1]]);
24
- return [data.lng, data.lat];
25
- }
26
- }
27
- class EchartsLayer {
28
- constructor(id, ecOptions) {
29
- this._registered = false;
30
- this.id = id;
31
- this.type = "custom";
32
- this.renderingMode = "2d";
33
- this._coordSystemName = COORDINATE_SYSTEM_NAME;
34
- this._ecOptions = ecOptions;
35
- }
36
- onAdd(map) {
37
- this._map = map;
38
- this._createLayerContainer();
39
- }
40
- onRemove() {
41
- this._removeLayerContainer();
42
- }
43
- setOption(option) {
44
- if (this._ec) {
45
- this._ec.setOption(option);
46
- }
47
- }
48
- render() {
49
- if (!this._container) {
50
- this._createLayerContainer();
51
- }
52
- if (!this._ec) {
53
- this._ec = echarts.init(this._container);
54
- this._prepareECharts();
55
- this._ec.setOption(this._ecOptions, false);
56
- } else {
57
- this._ec.resize();
58
- }
59
- }
60
- _prepareECharts() {
61
- if (!this._registered) {
62
- const coordinateSystem = new CoordinateSystem(this._map);
63
- echarts.registerCoordinateSystem(this._coordSystemName, coordinateSystem);
64
- this._registered = true;
65
- }
66
- const series = this._ecOptions.series;
67
- if (series) {
68
- for (let i = series.length - 1; i >= 0; i--) {
69
- series[i]["coordinateSystem"] = this._coordSystemName;
70
- }
71
- }
72
- }
73
- _createLayerContainer() {
74
- const mapContainer = this._map.getCanvasContainer();
75
- this._container = document.createElement("div");
76
- this._container.style.width = this._map.getCanvas().style.width;
77
- this._container.style.height = this._map.getCanvas().style.height;
78
- mapContainer.appendChild(this._container);
79
- }
80
- _removeLayerContainer() {
81
- var _a;
82
- if (this._container) {
83
- (_a = this._container.parentNode) == null ? void 0 : _a.removeChild(this._container);
84
- }
85
- }
86
- }
87
- export { EchartsLayer as default };
@@ -1 +0,0 @@
1
- (function(n,r){typeof exports=="object"&&typeof module!="undefined"?module.exports=r(require("echarts")):typeof define=="function"&&define.amd?define(["echarts"],r):(n=typeof globalThis!="undefined"?globalThis:n||self,n.EchartsLayer=r(n.echarts))})(this,function(n){"use strict";function r(i){if(i&&i.__esModule)return i;var e={__proto__:null,[Symbol.toStringTag]:"Module"};return i&&Object.keys(i).forEach(function(t){if(t!=="default"){var s=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:function(){return i[t]}})}}),e.default=i,Object.freeze(e)}var o=r(n);const c="mapboxgl-echarts";class a{constructor(e){this.dimensions=["x","y"],this._mapOffset=[0,0],this.map=e}create(e){e.eachSeries(t=>{t.get("coordinateSystem")===c&&(t.coordinateSystem=new a(this.map))})}dataToPoint(e){const t=this.map.project(e),s=this._mapOffset;return[t.x-s[0],t.y-s[1]]}pointToData(e){const t=this._mapOffset,s=this.map.unproject([e[0]+t[0],e[1]+t[1]]);return[s.lng,s.lat]}}class h{constructor(e,t){this._registered=!1,this.id=e,this.type="custom",this.renderingMode="2d",this._coordSystemName=c,this._ecOptions=t}onAdd(e){this._map=e,this._createLayerContainer()}onRemove(){this._removeLayerContainer()}setOption(e){this._ec&&this._ec.setOption(e)}render(){this._container||this._createLayerContainer(),this._ec?this._ec.resize():(this._ec=o.init(this._container),this._prepareECharts(),this._ec.setOption(this._ecOptions,!1))}_prepareECharts(){if(!this._registered){const t=new a(this._map);o.registerCoordinateSystem(this._coordSystemName,t),this._registered=!0}const e=this._ecOptions.series;if(e)for(let t=e.length-1;t>=0;t--)e[t].coordinateSystem=this._coordSystemName}_createLayerContainer(){const e=this._map.getCanvasContainer();this._container=document.createElement("div"),this._container.style.width=this._map.getCanvas().style.width,this._container.style.height=this._map.getCanvas().style.height,e.appendChild(this._container)}_removeLayerContainer(){var e;this._container&&((e=this._container.parentNode)==null||e.removeChild(this._container))}}return h});