@naivemap/maplibre-gl-echarts-layer 0.2.0-alpha.1 → 0.2.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/dist/index.es.js +119 -14
- package/dist/index.umd.js +1 -1
- package/package.json +3 -3
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,111 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
class
|
|
1
|
+
import { getCoordinateSystemDimensions as s, registerCoordinateSystem as a, init as h } from "echarts";
|
|
2
|
+
const c = "gl-layer-echarts";
|
|
3
|
+
class n {
|
|
4
|
+
id;
|
|
5
|
+
dimensions = ["x", "y"];
|
|
6
|
+
_map;
|
|
7
|
+
_mapOffset = [0, 0];
|
|
8
|
+
constructor(e, t) {
|
|
9
|
+
this.id = e, this._map = t;
|
|
10
|
+
}
|
|
11
|
+
create(e) {
|
|
12
|
+
e.eachSeries((t) => {
|
|
13
|
+
t.get("coordinateSystem") === this.id && (t.coordinateSystem = new n(this.id, this._map));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
dataToPoint(e) {
|
|
17
|
+
const t = this._map.project(e), i = this._mapOffset;
|
|
18
|
+
return [t.x - i[0], t.y - i[1]];
|
|
19
|
+
}
|
|
20
|
+
pointToData(e) {
|
|
21
|
+
const t = this._mapOffset, i = this._map.unproject([e[0] + t[0], e[1] + t[1]]);
|
|
22
|
+
return [i.lng, i.lat];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
class d {
|
|
26
|
+
_container;
|
|
27
|
+
_map;
|
|
28
|
+
_ec;
|
|
29
|
+
_coordSystemName;
|
|
30
|
+
_ecOption;
|
|
31
|
+
constructor(e) {
|
|
32
|
+
this._coordSystemName = c + "-" + Math.random().toString(16).substring(2), this._ecOption = e;
|
|
33
|
+
}
|
|
34
|
+
onAdd(e) {
|
|
35
|
+
if (this._map = e, this._createLayerContainer(), !s(this._coordSystemName)) {
|
|
36
|
+
const t = new n(this._coordSystemName, this._map);
|
|
37
|
+
a(this._coordSystemName, t);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
onRemove() {
|
|
41
|
+
this._ec?.dispose(), this._removeLayerContainer();
|
|
42
|
+
}
|
|
43
|
+
setOption(e, t) {
|
|
44
|
+
this._ecOption = e, this._ec?.setOption(e, t);
|
|
45
|
+
}
|
|
46
|
+
render() {
|
|
47
|
+
if (this._container || this._createLayerContainer(), !this._ec) {
|
|
48
|
+
this._ec = h(this._container), this._prepareECharts(), this._ec.setOption(this._ecOption);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (this._map.isMoving()) {
|
|
52
|
+
this._ec.clear();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this._ec.resize({
|
|
56
|
+
width: this._map.getCanvas().width,
|
|
57
|
+
height: this._map.getCanvas().height
|
|
58
|
+
}), this._prepareECharts(), this._ec.setOption(this._ecOption);
|
|
59
|
+
}
|
|
60
|
+
_prepareECharts() {
|
|
61
|
+
const e = this._ecOption.series;
|
|
62
|
+
if (e)
|
|
63
|
+
for (let t = e.length - 1; t >= 0; t--)
|
|
64
|
+
e[t].coordinateSystem = this._coordSystemName;
|
|
65
|
+
}
|
|
66
|
+
_createLayerContainer() {
|
|
67
|
+
const e = this._map.getCanvasContainer();
|
|
68
|
+
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);
|
|
69
|
+
}
|
|
70
|
+
_removeLayerContainer() {
|
|
71
|
+
this._container && this._container.parentNode?.removeChild(this._container);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function _(r) {
|
|
75
|
+
if (Array.isArray(r))
|
|
76
|
+
return r;
|
|
77
|
+
const e = r?.defaultProjectionData?.mainMatrix;
|
|
78
|
+
if (e)
|
|
79
|
+
return e;
|
|
80
|
+
throw new Error("Unable to resolve projection matrix from render arguments.");
|
|
81
|
+
}
|
|
82
|
+
function p(r, e) {
|
|
83
|
+
let t;
|
|
84
|
+
return {
|
|
85
|
+
id: e.id,
|
|
86
|
+
type: "custom",
|
|
87
|
+
renderingMode: e.renderingMode ?? "2d",
|
|
88
|
+
onAdd(i, o) {
|
|
89
|
+
t = i, r.onAdd(i, o);
|
|
90
|
+
},
|
|
91
|
+
onRemove(i, o) {
|
|
92
|
+
r.onRemove(i, o), t = void 0;
|
|
93
|
+
},
|
|
94
|
+
render(i, o) {
|
|
95
|
+
if (!t)
|
|
96
|
+
throw new Error("Layer adaptor render invoked before onAdd.");
|
|
97
|
+
r.render({
|
|
98
|
+
map: t,
|
|
99
|
+
gl: i,
|
|
100
|
+
matrix: (e.resolveMatrix ?? _)(o),
|
|
101
|
+
rawArgs: o,
|
|
102
|
+
prepareStencilMask: e.prepareStencilMask ? () => e.prepareStencilMask(t) : void 0
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const m = p;
|
|
108
|
+
class g {
|
|
4
109
|
id;
|
|
5
110
|
/**
|
|
6
111
|
* @ignore
|
|
@@ -17,8 +122,8 @@ class s {
|
|
|
17
122
|
* @param ecOption - The ECharts option object used to configure the visualization.
|
|
18
123
|
* @see https://echarts.apache.org/en/option.html
|
|
19
124
|
*/
|
|
20
|
-
constructor(e,
|
|
21
|
-
this.id = e, this.type = "custom", this.renderingMode = "2d", this._core = new t
|
|
125
|
+
constructor(e, t) {
|
|
126
|
+
this.id = e, this.type = "custom", this.renderingMode = "2d", this._core = new d(t), this._adaptor = m(this._core, {
|
|
22
127
|
id: e,
|
|
23
128
|
renderingMode: this.renderingMode
|
|
24
129
|
});
|
|
@@ -26,14 +131,14 @@ class s {
|
|
|
26
131
|
/**
|
|
27
132
|
* @ignore
|
|
28
133
|
*/
|
|
29
|
-
onAdd(e,
|
|
30
|
-
this._adaptor.onAdd(e,
|
|
134
|
+
onAdd(e, t) {
|
|
135
|
+
this._adaptor.onAdd(e, t);
|
|
31
136
|
}
|
|
32
137
|
/**
|
|
33
138
|
* @ignore
|
|
34
139
|
*/
|
|
35
|
-
onRemove(e,
|
|
36
|
-
this._adaptor.onRemove(e,
|
|
140
|
+
onRemove(e, t) {
|
|
141
|
+
this._adaptor.onRemove(e, t);
|
|
37
142
|
}
|
|
38
143
|
/**
|
|
39
144
|
* Updates the ECharts visualization with a new configuration.
|
|
@@ -45,16 +150,16 @@ class s {
|
|
|
45
150
|
* Defaults to `false`.
|
|
46
151
|
* @see https://echarts.apache.org/en/api.html#echartsInstance.setOption
|
|
47
152
|
*/
|
|
48
|
-
setOption(e,
|
|
49
|
-
this._core.setOption(e,
|
|
153
|
+
setOption(e, t) {
|
|
154
|
+
this._core.setOption(e, t);
|
|
50
155
|
}
|
|
51
156
|
/**
|
|
52
157
|
* @ignore
|
|
53
158
|
*/
|
|
54
|
-
render(e,
|
|
55
|
-
this._adaptor.render(e,
|
|
159
|
+
render(e, t) {
|
|
160
|
+
this._adaptor.render(e, t);
|
|
56
161
|
}
|
|
57
162
|
}
|
|
58
163
|
export {
|
|
59
|
-
|
|
164
|
+
g as default
|
|
60
165
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(n,s){typeof exports=="object"&&typeof module<"u"?module.exports=s(require("echarts")):typeof define=="function"&&define.amd?define(["echarts"],s):(n=typeof globalThis<"u"?globalThis:n||self,n.EChartsLayer=s(n.echarts))})(this,function(n){"use strict";const s="gl-layer-echarts";class a{id;dimensions=["x","y"];_map;_mapOffset=[0,0];constructor(e,t){this.id=e,this._map=t}create(e){e.eachSeries(t=>{t.get("coordinateSystem")===this.id&&(t.coordinateSystem=new a(this.id,this._map))})}dataToPoint(e){const t=this._map.project(e),i=this._mapOffset;return[t.x-i[0],t.y-i[1]]}pointToData(e){const t=this._mapOffset,i=this._map.unproject([e[0]+t[0],e[1]+t[1]]);return[i.lng,i.lat]}}class h{_container;_map;_ec;_coordSystemName;_ecOption;constructor(e){this._coordSystemName=s+"-"+Math.random().toString(16).substring(2),this._ecOption=e}onAdd(e){if(this._map=e,this._createLayerContainer(),!n.getCoordinateSystemDimensions(this._coordSystemName)){const t=new a(this._coordSystemName,this._map);n.registerCoordinateSystem(this._coordSystemName,t)}}onRemove(){this._ec?.dispose(),this._removeLayerContainer()}setOption(e,t){this._ecOption=e,this._ec?.setOption(e,t)}render(){if(this._container||this._createLayerContainer(),!this._ec){this._ec=n.init(this._container),this._prepareECharts(),this._ec.setOption(this._ecOption);return}if(this._map.isMoving()){this._ec.clear();return}this._ec.resize({width:this._map.getCanvas().width,height:this._map.getCanvas().height}),this._prepareECharts(),this._ec.setOption(this._ecOption)}_prepareECharts(){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(){this._container&&this._container.parentNode?.removeChild(this._container)}}function d(r){if(Array.isArray(r))return r;const e=r?.defaultProjectionData?.mainMatrix;if(e)return e;throw new Error("Unable to resolve projection matrix from render arguments.")}function c(r,e){let t;return{id:e.id,type:"custom",renderingMode:e.renderingMode??"2d",onAdd(i,o){t=i,r.onAdd(i,o)},onRemove(i,o){r.onRemove(i,o),t=void 0},render(i,o){if(!t)throw new Error("Layer adaptor render invoked before onAdd.");r.render({map:t,gl:i,matrix:(e.resolveMatrix??d)(o),rawArgs:o,prepareStencilMask:e.prepareStencilMask?()=>e.prepareStencilMask(t):void 0})}}}const p=c;class _{id;type;renderingMode;_core;_adaptor;constructor(e,t){this.id=e,this.type="custom",this.renderingMode="2d",this._core=new h(t),this._adaptor=p(this._core,{id:e,renderingMode:this.renderingMode})}onAdd(e,t){this._adaptor.onAdd(e,t)}onRemove(e,t){this._adaptor.onRemove(e,t)}setOption(e,t){this._core.setOption(e,t)}render(e,t){this._adaptor.render(e,t)}}return _});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naivemap/maplibre-gl-echarts-layer",
|
|
3
|
-
"version": "0.2.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A MapLibre GL JS layer to integrate Apache ECharts' Lines and Scatter charts.",
|
|
5
5
|
"main": "./dist/index.umd.js",
|
|
6
6
|
"module": "./dist/index.es.js",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
},
|
|
31
31
|
"sideEffects": false,
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@naivemap/echarts-layer-core": "0.2.0
|
|
34
|
-
"@naivemap/map-gl-layer-adaptor": "0.2.0
|
|
33
|
+
"@naivemap/echarts-layer-core": "0.2.0",
|
|
34
|
+
"@naivemap/map-gl-layer-adaptor": "0.2.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"echarts": "^5.0.0",
|