@naivemap/mapbox-gl-echarts-layer 0.1.1 → 0.1.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,6 +1,6 @@
1
1
  # mapbox-gl-echarts-layer
2
2
 
3
- [demo](https://huanglii.github.io/mapbox-gl-js-cookbook/example/echarts-scatter.html)
3
+ [全国主要城市空气质量 - 百度地图](https://huanglii.github.io/mapbox-gl-js-cookbook/example/echarts-scatter.html)
4
4
 
5
5
  ```bash
6
6
  npm i @naivemap/mapbox-gl-echarts-layer
@@ -38,6 +38,7 @@ class EchartsLayer {
38
38
  this._createLayerContainer();
39
39
  }
40
40
  onRemove() {
41
+ this._ec.dispose();
41
42
  this._removeLayerContainer();
42
43
  }
43
44
  setOption(option) {
@@ -52,9 +53,17 @@ class EchartsLayer {
52
53
  if (!this._ec) {
53
54
  this._ec = echarts.init(this._container);
54
55
  this._prepareECharts();
55
- this._ec.setOption(this._ecOptions, false);
56
+ this._ec.setOption(this._ecOptions);
56
57
  } else {
57
- this._ec.resize();
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._ecOptions);
66
+ }
58
67
  }
59
68
  }
60
69
  _prepareECharts() {
@@ -1 +1 @@
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});
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._ecOptions=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._ecOptions)):(this._ec=o.init(this._container),this._prepareECharts(),this._ec.setOption(this._ecOptions))}_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 c});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naivemap/mapbox-gl-echarts-layer",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "mapbox-gl-echarts-layer",
5
5
  "files": [
6
6
  "dist"
@@ -23,7 +23,7 @@
23
23
  "repository": "https://github.com/naivemap/mapbox-gl-echarts-layer",
24
24
  "keywords": ["mapbox-gl", "echarts"],
25
25
  "license": "MIT",
26
- "peerDependencies": {
26
+ "dependencies": {
27
27
  "echarts": "^5.3.0"
28
28
  },
29
29
  "devDependencies": {
@@ -31,7 +31,6 @@
31
31
  "@types/node": "^17.0.15",
32
32
  "@typescript-eslint/eslint-plugin": "^5.10.2",
33
33
  "@typescript-eslint/parser": "^5.10.2",
34
- "echarts": "^5.3.0",
35
34
  "eslint": "^8.8.0",
36
35
  "eslint-config-prettier": "^8.3.0",
37
36
  "eslint-plugin-prettier": "^4.0.0",
@@ -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
- }