@naivemap/mapbox-gl-echarts-layer 0.1.4 → 0.3.3
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 +21 -21
- package/README.md +52 -17
- package/dist/es/index.js +103 -0
- package/dist/js/index.d.ts +21 -0
- package/dist/js/index.js +105 -0
- package/package.json +41 -32
- package/dist/mapbox-gl-echarts-layer.es.js +0 -96
- package/dist/mapbox-gl-echarts-layer.umd.js +0 -1
- package/types/index.d.ts +0 -37
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,17 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
```
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { init, registerCoordinateSystem, getCoordinateSystemDimensions, } from 'echarts';
|
|
2
|
+
var COORDINATE_SYSTEM_NAME = 'mapboxgl-echarts';
|
|
3
|
+
var CoordinateSystem = /** @class */ (function () {
|
|
4
|
+
function CoordinateSystem(id, map) {
|
|
5
|
+
this.dimensions = ['x', 'y'];
|
|
6
|
+
this._mapOffset = [0, 0];
|
|
7
|
+
this.id = id;
|
|
8
|
+
this._map = map;
|
|
9
|
+
}
|
|
10
|
+
CoordinateSystem.prototype.create = function (ecModel) {
|
|
11
|
+
var _this = this;
|
|
12
|
+
ecModel.eachSeries(function (seriesModel) {
|
|
13
|
+
if (seriesModel.get('coordinateSystem') === _this.id) {
|
|
14
|
+
seriesModel.coordinateSystem = new CoordinateSystem(_this.id, _this._map);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
CoordinateSystem.prototype.dataToPoint = function (data) {
|
|
19
|
+
var px = this._map.project(data);
|
|
20
|
+
var mapOffset = this._mapOffset;
|
|
21
|
+
return [px.x - mapOffset[0], px.y - mapOffset[1]];
|
|
22
|
+
};
|
|
23
|
+
CoordinateSystem.prototype.pointToData = function (pt) {
|
|
24
|
+
var mapOffset = this._mapOffset;
|
|
25
|
+
var data = this._map.unproject([pt[0] + mapOffset[0], pt[1] + mapOffset[1]]);
|
|
26
|
+
return [data.lng, data.lat];
|
|
27
|
+
};
|
|
28
|
+
return CoordinateSystem;
|
|
29
|
+
}());
|
|
30
|
+
var EChartsLayer = /** @class */ (function () {
|
|
31
|
+
function EChartsLayer(id, ecOption) {
|
|
32
|
+
this.id = id;
|
|
33
|
+
this.type = 'custom';
|
|
34
|
+
this.renderingMode = '2d';
|
|
35
|
+
this._coordSystemName = COORDINATE_SYSTEM_NAME + '-' + Math.random().toString(16).substring(2);
|
|
36
|
+
this._ecOption = ecOption;
|
|
37
|
+
}
|
|
38
|
+
EChartsLayer.prototype.onAdd = function (map) {
|
|
39
|
+
this._map = map;
|
|
40
|
+
this._createLayerContainer();
|
|
41
|
+
if (!getCoordinateSystemDimensions(this._coordSystemName)) {
|
|
42
|
+
var coordinateSystem = new CoordinateSystem(this._coordSystemName, this._map);
|
|
43
|
+
registerCoordinateSystem(this._coordSystemName, coordinateSystem);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
EChartsLayer.prototype.onRemove = function () {
|
|
47
|
+
var _a;
|
|
48
|
+
(_a = this._ec) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
49
|
+
this._removeLayerContainer();
|
|
50
|
+
};
|
|
51
|
+
EChartsLayer.prototype.setOption = function (option) {
|
|
52
|
+
var _a;
|
|
53
|
+
(_a = this._ec) === null || _a === void 0 ? void 0 : _a.setOption(option);
|
|
54
|
+
};
|
|
55
|
+
EChartsLayer.prototype.render = function () {
|
|
56
|
+
if (!this._container) {
|
|
57
|
+
this._createLayerContainer();
|
|
58
|
+
}
|
|
59
|
+
if (!this._ec) {
|
|
60
|
+
this._ec = init(this._container);
|
|
61
|
+
this._prepareECharts();
|
|
62
|
+
this._ec.setOption(this._ecOption);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
if (this._map.isMoving()) {
|
|
66
|
+
this._ec.clear();
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this._ec.resize({
|
|
70
|
+
width: this._map.getCanvas().width,
|
|
71
|
+
height: this._map.getCanvas().height,
|
|
72
|
+
});
|
|
73
|
+
this._ec.setOption(this._ecOption);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
EChartsLayer.prototype._prepareECharts = function () {
|
|
78
|
+
var series = this._ecOption.series;
|
|
79
|
+
if (series) {
|
|
80
|
+
for (var i = series.length - 1; i >= 0; i--) {
|
|
81
|
+
// change coordinateSystem to mapboxgl-echarts
|
|
82
|
+
series[i]['coordinateSystem'] = this._coordSystemName;
|
|
83
|
+
// disable update animations
|
|
84
|
+
// series[i]['animation'] = false
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
EChartsLayer.prototype._createLayerContainer = function () {
|
|
89
|
+
var mapContainer = this._map.getCanvasContainer();
|
|
90
|
+
this._container = document.createElement('div');
|
|
91
|
+
this._container.style.width = this._map.getCanvas().style.width;
|
|
92
|
+
this._container.style.height = this._map.getCanvas().style.height;
|
|
93
|
+
mapContainer.appendChild(this._container);
|
|
94
|
+
};
|
|
95
|
+
EChartsLayer.prototype._removeLayerContainer = function () {
|
|
96
|
+
var _a;
|
|
97
|
+
if (this._container) {
|
|
98
|
+
(_a = this._container.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this._container);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
return EChartsLayer;
|
|
102
|
+
}());
|
|
103
|
+
export default EChartsLayer;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 _ecOption;
|
|
13
|
+
constructor(id: string, ecOption: ECOption);
|
|
14
|
+
onAdd(map: mapboxgl.Map): void;
|
|
15
|
+
onRemove(): void;
|
|
16
|
+
setOption(option: ECOption): void;
|
|
17
|
+
render(): void;
|
|
18
|
+
private _prepareECharts;
|
|
19
|
+
private _createLayerContainer;
|
|
20
|
+
private _removeLayerContainer;
|
|
21
|
+
}
|
package/dist/js/index.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
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(id, map) {
|
|
7
|
+
this.dimensions = ['x', 'y'];
|
|
8
|
+
this._mapOffset = [0, 0];
|
|
9
|
+
this.id = id;
|
|
10
|
+
this._map = map;
|
|
11
|
+
}
|
|
12
|
+
CoordinateSystem.prototype.create = function (ecModel) {
|
|
13
|
+
var _this = this;
|
|
14
|
+
ecModel.eachSeries(function (seriesModel) {
|
|
15
|
+
if (seriesModel.get('coordinateSystem') === _this.id) {
|
|
16
|
+
seriesModel.coordinateSystem = new CoordinateSystem(_this.id, _this._map);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
CoordinateSystem.prototype.dataToPoint = function (data) {
|
|
21
|
+
var px = this._map.project(data);
|
|
22
|
+
var mapOffset = this._mapOffset;
|
|
23
|
+
return [px.x - mapOffset[0], px.y - mapOffset[1]];
|
|
24
|
+
};
|
|
25
|
+
CoordinateSystem.prototype.pointToData = function (pt) {
|
|
26
|
+
var mapOffset = this._mapOffset;
|
|
27
|
+
var data = this._map.unproject([pt[0] + mapOffset[0], pt[1] + mapOffset[1]]);
|
|
28
|
+
return [data.lng, data.lat];
|
|
29
|
+
};
|
|
30
|
+
return CoordinateSystem;
|
|
31
|
+
}());
|
|
32
|
+
var EChartsLayer = /** @class */ (function () {
|
|
33
|
+
function EChartsLayer(id, ecOption) {
|
|
34
|
+
this.id = id;
|
|
35
|
+
this.type = 'custom';
|
|
36
|
+
this.renderingMode = '2d';
|
|
37
|
+
this._coordSystemName = COORDINATE_SYSTEM_NAME + '-' + Math.random().toString(16).substring(2);
|
|
38
|
+
this._ecOption = ecOption;
|
|
39
|
+
}
|
|
40
|
+
EChartsLayer.prototype.onAdd = function (map) {
|
|
41
|
+
this._map = map;
|
|
42
|
+
this._createLayerContainer();
|
|
43
|
+
if (!(0, echarts_1.getCoordinateSystemDimensions)(this._coordSystemName)) {
|
|
44
|
+
var coordinateSystem = new CoordinateSystem(this._coordSystemName, this._map);
|
|
45
|
+
(0, echarts_1.registerCoordinateSystem)(this._coordSystemName, coordinateSystem);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
EChartsLayer.prototype.onRemove = function () {
|
|
49
|
+
var _a;
|
|
50
|
+
(_a = this._ec) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
51
|
+
this._removeLayerContainer();
|
|
52
|
+
};
|
|
53
|
+
EChartsLayer.prototype.setOption = function (option) {
|
|
54
|
+
var _a;
|
|
55
|
+
(_a = this._ec) === null || _a === void 0 ? void 0 : _a.setOption(option);
|
|
56
|
+
};
|
|
57
|
+
EChartsLayer.prototype.render = function () {
|
|
58
|
+
if (!this._container) {
|
|
59
|
+
this._createLayerContainer();
|
|
60
|
+
}
|
|
61
|
+
if (!this._ec) {
|
|
62
|
+
this._ec = (0, echarts_1.init)(this._container);
|
|
63
|
+
this._prepareECharts();
|
|
64
|
+
this._ec.setOption(this._ecOption);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
if (this._map.isMoving()) {
|
|
68
|
+
this._ec.clear();
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
this._ec.resize({
|
|
72
|
+
width: this._map.getCanvas().width,
|
|
73
|
+
height: this._map.getCanvas().height,
|
|
74
|
+
});
|
|
75
|
+
this._ec.setOption(this._ecOption);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
EChartsLayer.prototype._prepareECharts = function () {
|
|
80
|
+
var series = this._ecOption.series;
|
|
81
|
+
if (series) {
|
|
82
|
+
for (var i = series.length - 1; i >= 0; i--) {
|
|
83
|
+
// change coordinateSystem to mapboxgl-echarts
|
|
84
|
+
series[i]['coordinateSystem'] = this._coordSystemName;
|
|
85
|
+
// disable update animations
|
|
86
|
+
// series[i]['animation'] = false
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
EChartsLayer.prototype._createLayerContainer = function () {
|
|
91
|
+
var mapContainer = this._map.getCanvasContainer();
|
|
92
|
+
this._container = document.createElement('div');
|
|
93
|
+
this._container.style.width = this._map.getCanvas().style.width;
|
|
94
|
+
this._container.style.height = this._map.getCanvas().style.height;
|
|
95
|
+
mapContainer.appendChild(this._container);
|
|
96
|
+
};
|
|
97
|
+
EChartsLayer.prototype._removeLayerContainer = function () {
|
|
98
|
+
var _a;
|
|
99
|
+
if (this._container) {
|
|
100
|
+
(_a = this._container.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this._container);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
return EChartsLayer;
|
|
104
|
+
}());
|
|
105
|
+
exports.default = EChartsLayer;
|
package/package.json
CHANGED
|
@@ -1,46 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naivemap/mapbox-gl-echarts-layer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
"main": "./dist/mapbox-gl-echarts-layer.umd.js",
|
|
11
|
-
"module": "./dist/mapbox-gl-echarts-layer.es.js",
|
|
3
|
+
"version": "0.3.3",
|
|
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",
|
|
12
10
|
"exports": {
|
|
11
|
+
"./package.json": "./package.json",
|
|
13
12
|
".": {
|
|
14
|
-
"import": "./dist/
|
|
15
|
-
"require": "./dist/
|
|
13
|
+
"import": "./dist/es/index.js",
|
|
14
|
+
"require": "./dist/js/index.js"
|
|
16
15
|
}
|
|
17
16
|
},
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
"repository": "https://github.com/naivemap/mapbox-gl-echarts-layer",
|
|
17
|
+
"types": "dist/js/index.d.ts",
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
25
22
|
"keywords": [
|
|
26
23
|
"mapbox-gl",
|
|
27
|
-
"echarts"
|
|
24
|
+
"echarts",
|
|
25
|
+
"scatter",
|
|
26
|
+
"lines"
|
|
28
27
|
],
|
|
29
|
-
"
|
|
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
|
+
},
|
|
30
45
|
"peerDependencies": {
|
|
31
46
|
"echarts": "^5.3.0"
|
|
32
47
|
},
|
|
33
48
|
"devDependencies": {
|
|
34
|
-
"@types/mapbox-gl": "^2.
|
|
35
|
-
"@types/node": "^17.0.
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"eslint-config-prettier": "^8.3.0",
|
|
41
|
-
"eslint-plugin-prettier": "^4.0.0",
|
|
42
|
-
"prettier": "^2.5.1",
|
|
43
|
-
"typescript": "^4.5.5",
|
|
44
|
-
"vite": "^2.7.13"
|
|
45
|
-
}
|
|
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": "0c380c018a344ca66303d59269532fd7f8112074"
|
|
46
55
|
}
|
|
@@ -1,96 +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, ecOption) {
|
|
29
|
-
this._registered = false;
|
|
30
|
-
this.id = id;
|
|
31
|
-
this.type = "custom";
|
|
32
|
-
this.renderingMode = "2d";
|
|
33
|
-
this._coordSystemName = COORDINATE_SYSTEM_NAME;
|
|
34
|
-
this._ecOption = ecOption;
|
|
35
|
-
}
|
|
36
|
-
onAdd(map) {
|
|
37
|
-
this._map = map;
|
|
38
|
-
this._createLayerContainer();
|
|
39
|
-
}
|
|
40
|
-
onRemove() {
|
|
41
|
-
this._ec.dispose();
|
|
42
|
-
this._removeLayerContainer();
|
|
43
|
-
}
|
|
44
|
-
setOption(option) {
|
|
45
|
-
if (this._ec) {
|
|
46
|
-
this._ec.setOption(option);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
render() {
|
|
50
|
-
if (!this._container) {
|
|
51
|
-
this._createLayerContainer();
|
|
52
|
-
}
|
|
53
|
-
if (!this._ec) {
|
|
54
|
-
this._ec = echarts.init(this._container);
|
|
55
|
-
this._prepareECharts();
|
|
56
|
-
this._ec.setOption(this._ecOption);
|
|
57
|
-
} else {
|
|
58
|
-
if (this._map.isMoving()) {
|
|
59
|
-
this._ec.clear();
|
|
60
|
-
} else {
|
|
61
|
-
this._ec.resize({
|
|
62
|
-
width: this._map.getCanvas().width,
|
|
63
|
-
height: this._map.getCanvas().height
|
|
64
|
-
});
|
|
65
|
-
this._ec.setOption(this._ecOption);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
_prepareECharts() {
|
|
70
|
-
if (!this._registered) {
|
|
71
|
-
const coordinateSystem = new CoordinateSystem(this._map);
|
|
72
|
-
echarts.registerCoordinateSystem(this._coordSystemName, coordinateSystem);
|
|
73
|
-
this._registered = true;
|
|
74
|
-
}
|
|
75
|
-
const series = this._ecOption.series;
|
|
76
|
-
if (series) {
|
|
77
|
-
for (let i = series.length - 1; i >= 0; i--) {
|
|
78
|
-
series[i]["coordinateSystem"] = this._coordSystemName;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
_createLayerContainer() {
|
|
83
|
-
const mapContainer = this._map.getCanvasContainer();
|
|
84
|
-
this._container = document.createElement("div");
|
|
85
|
-
this._container.style.width = this._map.getCanvas().style.width;
|
|
86
|
-
this._container.style.height = this._map.getCanvas().style.height;
|
|
87
|
-
mapContainer.appendChild(this._container);
|
|
88
|
-
}
|
|
89
|
-
_removeLayerContainer() {
|
|
90
|
-
var _a;
|
|
91
|
-
if (this._container) {
|
|
92
|
-
(_a = this._container.parentNode) == null ? void 0 : _a.removeChild(this._container);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
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 h="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")===h&&(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 c{constructor(e,t){this._registered=!1,this.id=e,this.type="custom",this.renderingMode="2d",this._coordSystemName=h,this._ecOption=t}onAdd(e){this._map=e,this._createLayerContainer()}onRemove(){this._ec.dispose(),this._removeLayerContainer()}setOption(e){this._ec&&this._ec.setOption(e)}render(){this._container||this._createLayerContainer(),this._ec?this._map.isMoving()?this._ec.clear():(this._ec.resize({width:this._map.getCanvas().width,height:this._map.getCanvas().height}),this._ec.setOption(this._ecOption)):(this._ec=o.init(this._container),this._prepareECharts(),this._ec.setOption(this._ecOption))}_prepareECharts(){if(!this._registered){const t=new a(this._map);o.registerCoordinateSystem(this._coordSystemName,t),this._registered=!0}const e=this._ecOption.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 c});
|
package/types/index.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/// <reference types="mapbox-gl" />
|
|
2
|
-
import * as echarts from 'echarts'
|
|
3
|
-
import {
|
|
4
|
-
EffectScatterSeriesOption,
|
|
5
|
-
LegendComponentOption,
|
|
6
|
-
LinesSeriesOption,
|
|
7
|
-
ScatterSeriesOption,
|
|
8
|
-
TitleComponentOption,
|
|
9
|
-
TooltipComponentOption,
|
|
10
|
-
} from 'echarts'
|
|
11
|
-
export declare type ECOption = echarts.ComposeOption<
|
|
12
|
-
| TitleComponentOption
|
|
13
|
-
| TooltipComponentOption
|
|
14
|
-
| LegendComponentOption
|
|
15
|
-
| LinesSeriesOption
|
|
16
|
-
| ScatterSeriesOption
|
|
17
|
-
| EffectScatterSeriesOption
|
|
18
|
-
>
|
|
19
|
-
export default class EchartsLayer implements mapboxgl.CustomLayerInterface {
|
|
20
|
-
id: string
|
|
21
|
-
type: 'custom'
|
|
22
|
-
renderingMode: '2d'
|
|
23
|
-
private _container
|
|
24
|
-
private _map
|
|
25
|
-
private _ec
|
|
26
|
-
private _coordSystemName
|
|
27
|
-
private _registered
|
|
28
|
-
private _ecOption
|
|
29
|
-
constructor(id: string, ecOption: ECOption)
|
|
30
|
-
onAdd(map: mapboxgl.Map): void
|
|
31
|
-
onRemove(): void
|
|
32
|
-
setOption(option: ECOption): void
|
|
33
|
-
render(): void
|
|
34
|
-
private _prepareECharts
|
|
35
|
-
private _createLayerContainer
|
|
36
|
-
private _removeLayerContainer
|
|
37
|
-
}
|