@gausslib/gauss-core 0.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.
@@ -0,0 +1,43 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Cesium</title>
6
+ <link rel="stylesheet" href="https://cesium.com/downloads/cesiumjs/releases/1.109/Build/Cesium/Widgets/widgets.css">
7
+ <script>window.CESIUM_BASE_URL='../public/cesium';</script>
8
+ <style>
9
+ #cesiumContainer { width: 100%; height: 100vh; }
10
+ .controls { position: absolute; top: 10px; left: 10px; background: rgba(0,0,0,0.7); padding: 10px; border-radius: 5px; z-index: 100; }
11
+ button { margin: 5px; padding: 8px 12px; background: #3498db; color: white; border: none; border-radius: 4px; cursor: pointer; }
12
+ button:hover { background: #2980b9; }
13
+ </style>
14
+ </head>
15
+ <body>
16
+ <div id="cesiumContainer"></div>
17
+ <div class="controls">
18
+ <button onclick="flyToBeijing()">飞向北京</button>
19
+ </div>
20
+
21
+ <script type="module">
22
+ import * as Gauss from '../dist/gauss-core.js'
23
+ // 初始化 Cesium
24
+ const viewer = new Gauss.Viewer('cesiumContainer', {
25
+ debug: true,
26
+ });
27
+
28
+
29
+ function flyToBeijing() {
30
+ viewer.flyTo({
31
+ longitude: 116.4074,
32
+ latitude: 39.9042,
33
+ height: 1500000
34
+ });
35
+ }
36
+
37
+ // 监听鼠标移动事件
38
+ // viewer.on('mouseMove', (data) => {
39
+ // console.log(`坐标: ${data.longitude.toFixed(4)}, ${data.latitude.toFixed(4)}`);
40
+ // });
41
+ </script>
42
+ </body>
43
+ </html>
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@gausslib/gauss-core",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "scripts": {
6
+ "dev": "vite",
7
+ "build": "tsc && vite build",
8
+ "preview": "vite preview"
9
+ },
10
+ "devDependencies": {
11
+ "typescript": "~5.9.3",
12
+ "vite": "^7.2.4"
13
+ },
14
+ "dependencies": {
15
+ "@turf/turf": "^7.3.1",
16
+ "cesium": "^1.136.0",
17
+ "fs-extra": "^11.3.3"
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @Author: jc
3
+ * @Date: 2025/12/27 16:50
4
+ * @Description:
5
+ */
6
+ import { Viewer } from 'cesium';
7
+
8
+ export const defaultViewerOptions: Partial<Viewer.ConstructorOptions> = {
9
+ animation: false, // 不显示动画控件
10
+ timeline: false, // 不显示时间线
11
+ baseLayerPicker: false, // 不显示图层选择器
12
+ geocoder: false, // 不显示搜索控件
13
+ sceneModePicker: false, // 不显示场景模式切换
14
+ homeButton: false, // 不显示 home 按钮
15
+ fullscreenButton: false, // 不显示全屏按钮
16
+ navigationHelpButton: false,// 不显示帮助按钮
17
+ infoBox: false, // 不显示信息框
18
+ selectionIndicator: false // 不显示选择指示器
19
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @Author: jc
3
+ * @Date: 2025/12/28 13:40
4
+ * @Description:
5
+ */
6
+ export * from './viewer';
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @Author: jc
3
+ * @Date: 2025/12/27 16:38
4
+ * @Description: Cesium Viewer 封装类
5
+ */
6
+ import * as Cesium from 'cesium';
7
+ import { defaultViewerOptions } from '@/core/config/viewerOptions';
8
+
9
+ export class Viewer {
10
+ private viewer: Cesium.Viewer;
11
+
12
+ constructor(container: string | HTMLElement, options?: Cesium.Viewer.ConstructorOptions) {
13
+ this.viewer = new Cesium.Viewer(container, {
14
+ ...defaultViewerOptions,
15
+ ...options
16
+ });
17
+ }
18
+
19
+ /**
20
+ * 销毁 Viewer
21
+ */
22
+ destroy() {
23
+ if (this.viewer) {
24
+ this.viewer.destroy();
25
+ }
26
+ }
27
+ }
28
+
29
+
package/src/index.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @Author: jc
3
+ * @Date: 2025/12/27 16:09
4
+ * @Description:
5
+ */
6
+ export const version = '0.1.0';
7
+
8
+ import * as Cesium from 'cesium';
9
+ import * as turf from '@turf/turf';
10
+
11
+ export { Cesium, turf };
12
+
13
+ export * from './core'
package/tsconfig.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
+ "types": ["vite/client"],
8
+ "skipLibCheck": true,
9
+ "baseUrl": ".",
10
+ "paths": {
11
+ "@/*": ["src/*"]
12
+ },
13
+
14
+ /* Bundler mode */
15
+ "moduleResolution": "bundler",
16
+ "allowImportingTsExtensions": true,
17
+ "verbatimModuleSyntax": true,
18
+ "moduleDetection": "force",
19
+ "noEmit": true,
20
+
21
+ /* Linting */
22
+ "strict": true,
23
+ "noUnusedLocals": true,
24
+ "noUnusedParameters": true,
25
+ "erasableSyntaxOnly": true,
26
+ "noFallthroughCasesInSwitch": true,
27
+ "noUncheckedSideEffectImports": true
28
+ },
29
+ "include": ["src"]
30
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @Author: jc
3
+ * @Date: 2025/12/28 22:46
4
+ * @Description:
5
+ */
6
+ import fs from 'fs-extra'
7
+ import path from 'path'
8
+ import { Plugin } from 'vite'
9
+ import { createRequire } from 'node:module'
10
+
11
+ export function copyCesiumPlugin(targetDir = 'public/cesium'): Plugin {
12
+ return {
13
+ name: 'copy-cesium',
14
+ async closeBundle() {
15
+ await copyCesium()
16
+ },
17
+ transformIndexHtml(html) {
18
+ const baseUrl = '/' + targetDir.replace(/^public\/?/, '')
19
+ const script = `<script>window.CESIUM_BASE_URL='${baseUrl}';</script>`
20
+ return html.replace(/<head>/, `<head>\n ${script}`)
21
+ }
22
+ }
23
+
24
+ async function copyCesium() {
25
+ try {
26
+ const require = createRequire(import.meta.url)
27
+ const cesiumRoot = path.dirname(
28
+ require.resolve('cesium/package.json', { paths: [process.cwd()] })
29
+ )
30
+ const cesiumBuild = path.join(cesiumRoot, 'Build/Cesium')
31
+
32
+ if (!fs.existsSync(cesiumBuild)) {
33
+ console.error('[Gauss] 未找到 Cesium Build 目录')
34
+ return
35
+ }
36
+
37
+ const dest = path.resolve(process.cwd(), targetDir)
38
+ await fs.copy(cesiumBuild, dest, { overwrite: true })
39
+ console.log(`[Gauss] Cesium 资源已拷贝到 ${dest}`)
40
+ } catch (err) {
41
+ console.error('[Gauss] 拷贝 Cesium 资源失败', err)
42
+ }
43
+ }
44
+ }
45
+
46
+
package/vite.config.ts ADDED
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @Author: jc
3
+ * @Date: 2025/12/27 16:08
4
+ * @Description:
5
+ */
6
+ import { defineConfig } from 'vite';
7
+ import path from 'path';
8
+ import { copyCesiumPlugin } from './vite/plugins/copyCesiumPlugin'
9
+
10
+ export default defineConfig({
11
+ resolve: {
12
+ alias: {
13
+ '@': path.resolve(__dirname, 'src')
14
+ }
15
+ },
16
+ build: {
17
+ lib: {
18
+ entry: path.resolve(__dirname, 'src/index.ts'),
19
+ name: 'Gauss',
20
+ fileName: 'gauss-core',
21
+ formats: ['es', 'umd']
22
+ },
23
+ rollupOptions: {
24
+ output: {
25
+ globals: {
26
+ }
27
+ }
28
+ }
29
+ },
30
+ plugins: [copyCesiumPlugin()]
31
+ });