@naivemap/mapbox-gl-echarts-layer 0.3.2 → 0.4.0-alpha.0

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Naive Map
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Naive Map
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,52 +1,11 @@
1
- ## EChartsLayer class
2
-
3
- ```bash
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
- >
36
- ```
37
-
38
- ### Methods
39
-
40
- | Method | Description |
41
- | ---------------------------------- | ------------------------------------------------------- |
42
- | **setOption** `(option: ECOption)` | Call `echartsInstance.setOption()` to update the chart. |
43
-
44
- ## Example
45
-
46
- ```ts
47
- // echart option
48
- const option = {...}
49
- const layer = new EChartsLayer('layer-id', option)
50
-
51
- map.addLayer(layer)
52
- ```
1
+ # @naivemap/mapbox-gl-echarts-layer
2
+
3
+ EChartsLayer ([@naivemap/maplibre-gl-echarts-layer](https://www.npmjs.com/package/@naivemap/maplibre-gl-echarts-layer)): Integrates Apache ECharts with MapLibre GL JS, specifically enabling the use of **Lines graphs** and **Scatter (bubble)** charts as a map layer. This allows for visualizing connections, paths, and point-based data with the rich styling capabilities of ECharts.
4
+
5
+ [API References](https://www.naivemap.com/maplibre-gl-layers/api/mapbox-gl-echarts-layer/)
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @naivemap/mapbox-gl-echarts-layer echarts
11
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";const t=require("@naivemap/echarts-layer-core"),o=require("@naivemap/map-gl-layer-adaptor");class s{id;type;renderingMode;_core;_adaptor;constructor(e,r){this.id=e,this.type="custom",this.renderingMode="2d",this._core=new t(r),this._adaptor=o.createMapboxLayerAdaptor(this._core,{id:e,renderingMode:this.renderingMode})}onAdd(e,r){this._adaptor.onAdd(e,r)}onRemove(e,r){this._adaptor.onRemove(e,r)}setOption(e,r){this._core.setOption(e,r)}render(e,r){this._adaptor.render(e,r)}}module.exports=s;
@@ -0,0 +1,6 @@
1
+ export * from './mapbox-gl-echarts-layer/src/index'
2
+ export {}
3
+ import MapboxEChartsLayer from './mapbox-gl-echarts-layer/src/index'
4
+ export default MapboxEChartsLayer
5
+ export * from './mapbox-gl-echarts-layer/src/index'
6
+ export {}
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ import t from "@naivemap/echarts-layer-core";
2
+ import { createMapboxLayerAdaptor as o } from "@naivemap/map-gl-layer-adaptor";
3
+ class s {
4
+ id;
5
+ /**
6
+ * @ignore
7
+ */
8
+ type;
9
+ /**
10
+ * @ignore
11
+ */
12
+ renderingMode;
13
+ _core;
14
+ _adaptor;
15
+ /**
16
+ * @param id - A unique layer id
17
+ * @param ecOption - The ECharts option object used to configure the visualization.
18
+ * @see https://echarts.apache.org/en/option.html
19
+ */
20
+ constructor(e, r) {
21
+ this.id = e, this.type = "custom", this.renderingMode = "2d", this._core = new t(r), this._adaptor = o(this._core, {
22
+ id: e,
23
+ renderingMode: this.renderingMode
24
+ });
25
+ }
26
+ onAdd(e, r) {
27
+ this._adaptor.onAdd(e, r);
28
+ }
29
+ onRemove(e, r) {
30
+ this._adaptor.onRemove(e, r);
31
+ }
32
+ /**
33
+ * Updates the ECharts visualization with a new configuration.
34
+ * This is the primary method for dynamically changing the displayed data or styles.
35
+ *
36
+ * @param option - The new ECharts option object to apply.
37
+ * @param notMerge - If true, the new options will completely replace the existing ones.
38
+ * If false or undefined, the new options will be merged with the old ones.
39
+ * Defaults to `false`.
40
+ * @see https://echarts.apache.org/en/api.html#echartsInstance.setOption
41
+ */
42
+ setOption(e, r) {
43
+ this._core.setOption(e, r);
44
+ }
45
+ render(e, r) {
46
+ this._adaptor.render(e, r);
47
+ }
48
+ }
49
+ export {
50
+ s as default
51
+ };
@@ -0,0 +1,38 @@
1
+ import { ECOption } from '../../echarts-layer-core/src/index.ts';
2
+ import { CustomLayerInterface, Map } from 'mapbox-gl';
3
+ /**
4
+ * A custom Mapbox GL JS layer that renders Apache ECharts visualizations.
5
+ */
6
+ export default class EChartsLayer implements CustomLayerInterface {
7
+ id: string;
8
+ /**
9
+ * @ignore
10
+ */
11
+ type: 'custom';
12
+ /**
13
+ * @ignore
14
+ */
15
+ renderingMode?: '2d' | '3d' | undefined;
16
+ private _core;
17
+ private _adaptor;
18
+ /**
19
+ * @param id - A unique layer id
20
+ * @param ecOption - The ECharts option object used to configure the visualization.
21
+ * @see https://echarts.apache.org/en/option.html
22
+ */
23
+ constructor(id: string, ecOption: ECOption);
24
+ onAdd(map: Map, gl: WebGLRenderingContext): void;
25
+ onRemove(map: Map, gl: WebGLRenderingContext): void;
26
+ /**
27
+ * Updates the ECharts visualization with a new configuration.
28
+ * This is the primary method for dynamically changing the displayed data or styles.
29
+ *
30
+ * @param option - The new ECharts option object to apply.
31
+ * @param notMerge - If true, the new options will completely replace the existing ones.
32
+ * If false or undefined, the new options will be merged with the old ones.
33
+ * Defaults to `false`.
34
+ * @see https://echarts.apache.org/en/api.html#echartsInstance.setOption
35
+ */
36
+ setOption(option: ECOption, notMerge?: boolean): void;
37
+ render(gl: WebGLRenderingContext, args: unknown): void;
38
+ }
@@ -0,0 +1,3 @@
1
+ import { default as EChartsLayer } from './EChartsLayer';
2
+ export type { ECOption } from '../../echarts-layer-core/src/index.ts';
3
+ export default EChartsLayer;
package/package.json CHANGED
@@ -1,55 +1,48 @@
1
1
  {
2
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",
3
+ "version": "0.4.0-alpha.0",
4
+ "description": "A Mapbox GL JS layer to integrate Apache ECharts' Lines and Scatter charts.",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "type": "module",
10
8
  "exports": {
11
- "./package.json": "./package.json",
12
9
  ".": {
13
- "import": "./dist/es/index.js",
14
- "require": "./dist/js/index.js"
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
15
13
  }
16
14
  },
17
- "types": "dist/js/index.d.ts",
18
- "sideEffects": false,
19
15
  "files": [
20
16
  "dist"
21
17
  ],
22
18
  "keywords": [
23
- "mapbox-gl",
19
+ "mapbox",
24
20
  "echarts",
25
- "scatter",
26
- "lines"
21
+ "layer",
22
+ "custom"
27
23
  ],
24
+ "author": "naivemap",
25
+ "license": "MIT",
26
+ "types": "./dist/index.d.ts",
27
+ "repository": "https://github.com/naivemap/maplibre-gl-layers",
28
28
  "publishConfig": {
29
29
  "access": "public"
30
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"
31
+ "sideEffects": false,
32
+ "dependencies": {
33
+ "@naivemap/echarts-layer-core": "0.1.0",
34
+ "@naivemap/map-gl-layer-adaptor": "0.1.0"
44
35
  },
45
36
  "peerDependencies": {
46
- "echarts": "^5.3.0"
37
+ "echarts": "^5.0.0",
38
+ "mapbox-gl": "^2.0.0 || ^3.0.0"
47
39
  },
48
40
  "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"
41
+ "echarts": "^5.6.0",
42
+ "mapbox-gl": "^3.10.0"
53
43
  },
54
- "gitHead": "0d34a954e38a0366112328e2cceaafebece75e3e"
55
- }
44
+ "scripts": {
45
+ "build": "vite build",
46
+ "typedocs": "pnpm typedoc"
47
+ }
48
+ }
package/dist/es/index.js DELETED
@@ -1,104 +0,0 @@
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;
@@ -1,22 +0,0 @@
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
- }
package/dist/js/index.js DELETED
@@ -1,106 +0,0 @@
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;