@krazyphish/earth-plugins 1.0.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/HISTORY.md ADDED
@@ -0,0 +1,7 @@
1
+ ## @krazyphish/earth-react
2
+
3
+ ### 版本更新历史记录
4
+
5
+ #### Version 0.1.0
6
+
7
+ 1. 新增ECharts插件,将ECharts视图坐标和Cesium整合
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2025] [KrazyPhish]
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 ADDED
@@ -0,0 +1,35 @@
1
+ ## @krazyphish/earth-plugins
2
+
3
+ Plugins for module [@krazyphish/earth](https://www.npmjs.com/package/@krazyphish/earth).
4
+
5
+ ### Before start
6
+
7
+ Before start using this module, install packages blow manually: [@krazyphish/earth](https://www.npmjs.com/package/@krazyphish/earth).
8
+
9
+ Then install this module:
10
+
11
+ ```shell
12
+ npm install @krazyphish/earth-plugins
13
+ ```
14
+
15
+ ### Get started
16
+
17
+ To use plugin echarts overlay:
18
+
19
+ ```ts
20
+ // in your map module, when initializing the cesium viewer
21
+ import { type Earth, createEarth } from "@krazyphish/earth"
22
+ import { registerEChartsOverlay, EChartsOverlay } from "@krazyphish/earth-plugins"
23
+
24
+ const earth: Earth = createEarth()
25
+
26
+ // register echarts overlay, to syncronize the coordinate with cesium viewer
27
+ registerEChartsOverlay(earth)
28
+
29
+ // then create the echarts overlay
30
+ const overlay = new EChartsOverlay(earth, {
31
+ option: {
32
+ /** your echarts option */
33
+ },
34
+ })
35
+ ```
@@ -0,0 +1 @@
1
+ "use strict";const e=require("echarts"),t=require("@krazyphish/earth"),r=require("cesium");function __decorate(e,t,r,i){var s,a=arguments.length,o=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,i);else for(var n=e.length-1;n>=0;n--)(s=e[n])&&(o=(a<3?s(o):a>3?s(t,r,o):s(t,r))||o);return a>3&&o&&Object.defineProperty(t,r,o),o}function __classPrivateFieldGet(e,t,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(e):i?i.value:t.get(e)}function __classPrivateFieldSet(e,t,r,i,s){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?s.call(e,r):s?s.value=r:t.set(e,r),r}"function"==typeof SuppressedError&&SuppressedError;const enumerable=e=>(...t)=>{const[r,i,s]=t;if(s)return s.enumerable=e,s.configurable=!1,s;Object.defineProperty(r,i,{configurable:!1,enumerable:e,writable:!0})},generate=e=>(t,r)=>{const i="string"==typeof r?r:r.toString(),s=`_${i}`;Object.defineProperty(t,s,{configurable:!1,enumerable:!1,writable:!0,value:e}),Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get(){return"string"==typeof r?this[`_${r}`]:this[s]},set(){throw Error(`Cannot assign to '${i}', because it is a read-only property.`)}})};var i,s,a,o;exports.EChartsOverlay=class EChartsOverlay{constructor(e,r){var n;i.add(this),s.set(this,void 0),a.set(this,void 0),this._id=null!==(n=r.id)&&void 0!==n?n:t.Utils.uuid(),__classPrivateFieldSet(this,s,e.viewer,"f"),__classPrivateFieldSet(this,a,e.scene,"f"),this._overlay=__classPrivateFieldGet(this,i,"m",o).call(this),r.option&&this.update(r.option)}update(e){this._overlay&&this._overlay.setOption(e)}getViewer(){return __classPrivateFieldGet(this,s,"f")}getOverlay(){return this._overlay}show(){this._container&&(this._container.style.visibility="visible")}hide(){this._container&&(this._container.style.visibility="hidden")}destroy(){this._isDestroyed||(this._isDestroyed=!0,this._container&&(__classPrivateFieldGet(this,s,"f").container.removeChild(this._container),this._container=void 0),this._overlay&&(this._overlay.dispose(),this._overlay=void 0))}},s=new WeakMap,a=new WeakMap,i=new WeakSet,o=function _EChartsOverlay_createChartOverlay(){__classPrivateFieldGet(this,a,"f").canvas.setAttribute("tabIndex","0");const t=document.createElement("div");return t.style.position="absolute",t.style.top="0px",t.style.left="0px",t.style.width=`${__classPrivateFieldGet(this,a,"f").canvas.width}px`,t.style.height=`${__classPrivateFieldGet(this,a,"f").canvas.height}px`,t.style.pointerEvents="none",t.setAttribute("id",this._id),t.setAttribute("class","echarts-overlay"),__classPrivateFieldGet(this,s,"f").container.appendChild(t),this._container=t,e.init(t)},__decorate([generate(!1)],exports.EChartsOverlay.prototype,"isDestroyed",void 0),__decorate([generate()],exports.EChartsOverlay.prototype,"id",void 0),__decorate([enumerable(!1)],exports.EChartsOverlay.prototype,"_container",void 0),__decorate([enumerable(!1)],exports.EChartsOverlay.prototype,"_overlay",void 0),exports.EChartsOverlay=__decorate([e=>{const t=new Map;return new Proxy(e,{construct:(e,r)=>{let i;return t.has(r[0].id)&&(console.warn(`Instance of '${e.name}' can only be constructed once for each earth, unless the previous has been destroyed.`),i=t.get(r[0].id)),i&&!i._isDestroyed||(i=Reflect.construct(e,r),t.set(r[0].id,i)),i}})}],exports.EChartsOverlay);exports.registerEChartsOverlay=t=>{e.extendComponentModel({type:"GLMap",defaultOption:{roam:!1}}),e.extendComponentView({type:"GLMap",init(e,r){this.api=r,t._scene.postRender.addEventListener(this.moveHandler,this)},moveHandler(){this.api.dispatchAction({type:"GLMapRoam"})},render(){},dispose(){t._scene.postRender.removeEventListener(this.moveHandler,this)}});class EarthCoordinateSystem{constructor(e,t){this.dimensions=["lng","lat"],this.mapOffset=[0,0],this.scene=e,this.api=t}static create(e,r){let i;e.eachComponent("GLMap",e=>{i=new EarthCoordinateSystem(t._scene,r),i.setMapOffset(e.__mapOffset||[0,0]),e.coordinateSystem=i}),e.eachSeries(e=>{"GLMap"===e.get("coordinateSystem")&&(e.coordinateSystem=i)})}setMapOffset(e){this.mapOffset=[...e]}getEarthMap(){return this.scene}dataToPoint(e){const t=r.Math.toRadians(80),i=r.Cartesian3.fromDegrees(e[0],e[1]);if(!i)return[void 0,void 0];const s=this.scene.cartesianToCanvasCoordinates(i);return s?this.scene.mode===r.SceneMode.SCENE3D&&r.Cartesian3.angleBetween(this.scene.camera.position,i)>t?[void 0,void 0]:[s.x-this.mapOffset[0],s.y-this.mapOffset[1]]:[void 0,void 0]}pointToData(e){const t=new r.Cartesian2(e[0]+this.mapOffset[0],e[1]+this.mapOffset[1]),i=this.scene.pickPosition(t);if(!i)return[void 0,void 0];const s=r.Cartographic.fromCartesian(i);return[s.longitude,s.latitude]}getViewRect(){return new e.graphic.BoundingRect(0,0,this.api.getWidth(),this.api.getHeight())}getRoamTransform(){return e.matrix.create()}}EarthCoordinateSystem.dimensions=["lng","lat"],e.registerCoordinateSystem("GLMap",EarthCoordinateSystem),e.registerAction({type:"GLMapRoam",event:"GLMapRoam",update:"updateLayout"},()=>{})};
@@ -0,0 +1,68 @@
1
+ import type { Earth } from "@krazyphish/earth"
2
+ import type { Viewer } from "cesium"
3
+ import type { EChartsOption } from "echarts"
4
+
5
+ declare module "@krazyphish/earth-plugins" {
6
+ export const registerEChartsOverlay: (earth: Earth) => void
7
+ export namespace EChartsOverlay {
8
+ /**
9
+ * @property [id] ID
10
+ * @property [option] {@link EChartsOption} Echarts设置
11
+ */
12
+ export type ConstructorOptions = { id?: string; option?: EChartsOption }
13
+ }
14
+
15
+ /**
16
+ * @description Echarts插件图层
17
+ * @param earth {@link Earth} 地球实例
18
+ * @param options {@link EChartsOverlay.ConstructorOptions} 参数
19
+ * @example
20
+ * ```
21
+ * const earth = createEarth()
22
+ * const option: EChartsOption = {
23
+ * // your echarts option
24
+ * }
25
+ * const overlay = new EchartsOverlay(earth, { option })
26
+ * //when update option
27
+ * overlay.update(option)
28
+ * ```
29
+ */
30
+ export class EChartsOverlay {
31
+ constructor(earth: Earth, options?: EChartsOverlay.ConstructorOptions)
32
+ /**
33
+ * @description ID
34
+ */
35
+ readonly id: string
36
+ /**
37
+ * @description 销毁状态
38
+ */
39
+ readonly isDestroyed: boolean
40
+ /**
41
+ * @description 加载Echarts设置
42
+ * @param option {@link EChartsOption} Echarts设置
43
+ */
44
+ update(option: EChartsOption): void
45
+ /**
46
+ * @description 获取视图
47
+ * @returns 视图
48
+ */
49
+ getViewer(): Viewer
50
+ /**
51
+ * @description 获取Echarts实例
52
+ * @returns Echarts实例
53
+ */
54
+ getOverlay(): void
55
+ /**
56
+ * @description 显示
57
+ */
58
+ show(): void
59
+ /**
60
+ * @description 隐藏
61
+ */
62
+ hide(): void
63
+ /**
64
+ * @description 销毁
65
+ */
66
+ destroy(): void
67
+ }
68
+ }
@@ -0,0 +1 @@
1
+ import{init as e,extendComponentModel as t,extendComponentView as i,registerCoordinateSystem as r,registerAction as s,graphic as o,matrix as a}from"echarts";import{Utils as n}from"@krazyphish/earth";import{Math as c,Cartesian3 as d,SceneMode as l,Cartesian2 as h,Cartographic as p}from"cesium";function __decorate(e,t,i,r){var s,o=arguments.length,a=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,r);else for(var n=e.length-1;n>=0;n--)(s=e[n])&&(a=(o<3?s(a):o>3?s(t,i,a):s(t,i))||a);return o>3&&a&&Object.defineProperty(t,i,a),a}function __classPrivateFieldGet(e,t,i,r){if("a"===i&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?r:"a"===i?r.call(e):r?r.value:t.get(e)}function __classPrivateFieldSet(e,t,i,r,s){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?s.call(e,i):s?s.value=i:t.set(e,i),i}"function"==typeof SuppressedError&&SuppressedError;const enumerable=e=>(...t)=>{const[i,r,s]=t;if(s)return s.enumerable=e,s.configurable=!1,s;Object.defineProperty(i,r,{configurable:!1,enumerable:e,writable:!0})},generate=e=>(t,i)=>{const r="string"==typeof i?i:i.toString(),s=`_${r}`;Object.defineProperty(t,s,{configurable:!1,enumerable:!1,writable:!0,value:e}),Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get(){return"string"==typeof i?this[`_${i}`]:this[s]},set(){throw Error(`Cannot assign to '${r}', because it is a read-only property.`)}})};var f,v,y,u;let _=class EChartsOverlay{constructor(e,t){var i;f.add(this),v.set(this,void 0),y.set(this,void 0),this._id=null!==(i=t.id)&&void 0!==i?i:n.uuid(),__classPrivateFieldSet(this,v,e.viewer,"f"),__classPrivateFieldSet(this,y,e.scene,"f"),this._overlay=__classPrivateFieldGet(this,f,"m",u).call(this),t.option&&this.update(t.option)}update(e){this._overlay&&this._overlay.setOption(e)}getViewer(){return __classPrivateFieldGet(this,v,"f")}getOverlay(){return this._overlay}show(){this._container&&(this._container.style.visibility="visible")}hide(){this._container&&(this._container.style.visibility="hidden")}destroy(){this._isDestroyed||(this._isDestroyed=!0,this._container&&(__classPrivateFieldGet(this,v,"f").container.removeChild(this._container),this._container=void 0),this._overlay&&(this._overlay.dispose(),this._overlay=void 0))}};v=new WeakMap,y=new WeakMap,f=new WeakSet,u=function _EChartsOverlay_createChartOverlay(){__classPrivateFieldGet(this,y,"f").canvas.setAttribute("tabIndex","0");const t=document.createElement("div");return t.style.position="absolute",t.style.top="0px",t.style.left="0px",t.style.width=`${__classPrivateFieldGet(this,y,"f").canvas.width}px`,t.style.height=`${__classPrivateFieldGet(this,y,"f").canvas.height}px`,t.style.pointerEvents="none",t.setAttribute("id",this._id),t.setAttribute("class","echarts-overlay"),__classPrivateFieldGet(this,v,"f").container.appendChild(t),this._container=t,e(t)},__decorate([generate(!1)],_.prototype,"isDestroyed",void 0),__decorate([generate()],_.prototype,"id",void 0),__decorate([enumerable(!1)],_.prototype,"_container",void 0),__decorate([enumerable(!1)],_.prototype,"_overlay",void 0),_=__decorate([e=>{const t=new Map;return new Proxy(e,{construct:(e,i)=>{let r;return t.has(i[0].id)&&(console.warn(`Instance of '${e.name}' can only be constructed once for each earth, unless the previous has been destroyed.`),r=t.get(i[0].id)),r&&!r._isDestroyed||(r=Reflect.construct(e,i),t.set(i[0].id,r)),r}})}],_);const registerEChartsOverlay=e=>{t({type:"GLMap",defaultOption:{roam:!1}}),i({type:"GLMap",init(t,i){this.api=i,e._scene.postRender.addEventListener(this.moveHandler,this)},moveHandler(){this.api.dispatchAction({type:"GLMapRoam"})},render(){},dispose(){e._scene.postRender.removeEventListener(this.moveHandler,this)}});class EarthCoordinateSystem{constructor(e,t){this.dimensions=["lng","lat"],this.mapOffset=[0,0],this.scene=e,this.api=t}static create(t,i){let r;t.eachComponent("GLMap",t=>{r=new EarthCoordinateSystem(e._scene,i),r.setMapOffset(t.__mapOffset||[0,0]),t.coordinateSystem=r}),t.eachSeries(e=>{"GLMap"===e.get("coordinateSystem")&&(e.coordinateSystem=r)})}setMapOffset(e){this.mapOffset=[...e]}getEarthMap(){return this.scene}dataToPoint(e){const t=c.toRadians(80),i=d.fromDegrees(e[0],e[1]);if(!i)return[void 0,void 0];const r=this.scene.cartesianToCanvasCoordinates(i);return r?this.scene.mode===l.SCENE3D&&d.angleBetween(this.scene.camera.position,i)>t?[void 0,void 0]:[r.x-this.mapOffset[0],r.y-this.mapOffset[1]]:[void 0,void 0]}pointToData(e){const t=new h(e[0]+this.mapOffset[0],e[1]+this.mapOffset[1]),i=this.scene.pickPosition(t);if(!i)return[void 0,void 0];const r=p.fromCartesian(i);return[r.longitude,r.latitude]}getViewRect(){return new o.BoundingRect(0,0,this.api.getWidth(),this.api.getHeight())}getRoamTransform(){return a.create()}}EarthCoordinateSystem.dimensions=["lng","lat"],r("GLMap",EarthCoordinateSystem),s({type:"GLMapRoam",event:"GLMapRoam",update:"updateLayout"},()=>{})};export{_ as EChartsOverlay,registerEChartsOverlay};
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@krazyphish/earth-plugins",
3
+ "author": "KrazyPhish",
4
+ "version": "1.0.0",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs.js",
7
+ "module": "./dist/index.es.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.es.js",
13
+ "require": "./dist/index.cjs.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "HISTORY.md",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "sideEffects": false,
23
+ "license": "MIT",
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "peerDependencies": {
28
+ "echarts": "^5.5.0",
29
+ "@krazyphish/earth": "1.0.0 *"
30
+ },
31
+ "dependencies": {
32
+ "develop-utils": "1.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@rollup/plugin-commonjs": "^28.0.2",
36
+ "@rollup/plugin-node-resolve": "^15.3.1",
37
+ "@rollup/plugin-terser": "^0.4.4",
38
+ "@rollup/plugin-typescript": "^11.1.6",
39
+ "@tsconfig/node20": "^20.1.4",
40
+ "@types/node": "^20.14.15",
41
+ "cesium": "^1.130.1",
42
+ "echarts": "^5.5.0",
43
+ "rimraf": "^6.0.1",
44
+ "rollup": "^4.44.1",
45
+ "ts-loader": "^9.5.1",
46
+ "ts-node": "^10.9.2",
47
+ "typescript": "^5.8.3",
48
+ "@krazyphish/earth": "1.0.0",
49
+ "build-utils": "1.0.0"
50
+ },
51
+ "scripts": {
52
+ "build": "pnpm release && pnpm type",
53
+ "clean": "rimraf -rf dist/",
54
+ "release": "pnpm clean && rollup -c rollup.config.ts --bundleConfigAsCjs",
55
+ "type": "ts-node ./scripts/build.ts"
56
+ }
57
+ }