cesium-alpha-earth 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/dist/index.js +214371 -0
- package/index.html +16 -0
- package/package.json +29 -0
- package/src/core/CesiumAlphaGeoJsonLayer/index.ts +815 -0
- package/src/core/CesiumAlphaGeoJsonLayer/method/geojson-util.ts +374 -0
- package/src/core/CesiumAlphaGeoJsonLayer/type.ts +108 -0
- package/src/core/CesiumAlphaViewer/index.ts +106 -0
- package/src/core/CesiumAlphaViewer/method/clusterFun.ts +116 -0
- package/src/core/CesiumAlphaViewer/method/createViewer.ts +53 -0
- package/src/core/CesiumAlphaViewer/method/goTo.ts +108 -0
- package/src/core/CesiumAlphaViewer/method/load3DtilestModel.ts +56 -0
- package/src/core/CesiumAlphaViewer/method/loadGeoJsonLayer.ts +33 -0
- package/src/core/CesiumAlphaViewer/type.ts +141 -0
- package/src/index.ts +10 -0
- package/src/util/PrimitiveCuster/index.js +1000 -0
- package/src/util/getPositionCenters/getPositionCenter.ts +25 -0
- package/src/util/parseColor/index.ts +39 -0
- package/tsconfig.json +28 -0
- package/types/core/CesiumAlphaViewer/index.d.ts +7 -0
- package/types/core/CesiumAlphaViewer/method/createViewer.d.ts +3 -0
- package/types/core/CesiumAlphaViewer/method/goTo.d.ts +3 -0
- package/types/core/CesiumAlphaViewer/type.d.ts +77 -0
- package/types/index.d.ts +2 -0
- package/viewTest/App.vue +38 -0
- package/viewTest/main.ts +10 -0
- package/viewTest/style/style.scss +4 -0
- package/vite.config.ts +69 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import centroid from '@turf/centroid';
|
|
2
|
+
import { polygon as tfpolygon } from '@turf/helpers';
|
|
3
|
+
import { Cartesian3, BoundingSphere, Ellipsoid } from 'cesium';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 计算一组多边形坐标的质心
|
|
7
|
+
* @param positions 坐标串
|
|
8
|
+
*/
|
|
9
|
+
export function getPositionsCenter(
|
|
10
|
+
positions: Cartesian3[],
|
|
11
|
+
height?: number,
|
|
12
|
+
) {
|
|
13
|
+
const polygon = tfpolygon([positions.map((item) => [item.x, item.y])]);
|
|
14
|
+
const polyCenter = BoundingSphere.fromPoints(positions).center;
|
|
15
|
+
const polyCentroid = centroid(polygon);
|
|
16
|
+
const center = new Cartesian3(
|
|
17
|
+
polyCentroid.geometry.coordinates[0],
|
|
18
|
+
polyCentroid.geometry.coordinates[1],
|
|
19
|
+
polyCenter.z,
|
|
20
|
+
);
|
|
21
|
+
return {
|
|
22
|
+
cartesian3: Ellipsoid.WGS84.scaleToGeodeticSurface(center),
|
|
23
|
+
height,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as Cesium from 'cesium';
|
|
2
|
+
/**
|
|
3
|
+
* 公共的颜色解析方法,将 RGB、RGBA 和 HEX 转换为 Cesium.Color 实例
|
|
4
|
+
* @param color - 颜色字符串,支持 RGB, RGBA, HEX
|
|
5
|
+
* @returns Cesium.Color 实例
|
|
6
|
+
*/
|
|
7
|
+
export function parseColorToCesium(color: string | undefined): Cesium.Color | undefined {
|
|
8
|
+
if (!color) {
|
|
9
|
+
return
|
|
10
|
+
}
|
|
11
|
+
const hexPattern = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;
|
|
12
|
+
const rgbPattern = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/;
|
|
13
|
+
const rgbaPattern = /^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(0(\.\d+)?|1(\.0)?)\)$/;
|
|
14
|
+
|
|
15
|
+
let result: Cesium.Color | undefined = undefined;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
// 处理 HEX 颜色格式
|
|
20
|
+
if (hexPattern.test(color)) {
|
|
21
|
+
const hex = color.slice(1);
|
|
22
|
+
const r = parseInt(hex.length === 3 ? hex[0] + hex[0] : hex.slice(0, 2), 16);
|
|
23
|
+
const g = parseInt(hex.length === 3 ? hex[1] + hex[1] : hex.slice(2, 4), 16);
|
|
24
|
+
const b = parseInt(hex.length === 3 ? hex[2] + hex[2] : hex.slice(4, 6), 16);
|
|
25
|
+
result = new Cesium.Color(r / 255, g / 255, b / 255, 1);
|
|
26
|
+
}
|
|
27
|
+
// 处理 RGB 颜色格式
|
|
28
|
+
else if (rgbPattern.test(color)) {
|
|
29
|
+
const [, r, g, b] = color.match(rgbPattern)!.map(Number);
|
|
30
|
+
result = new Cesium.Color(r / 255, g / 255, b / 255, 1);
|
|
31
|
+
}
|
|
32
|
+
// 处理 RGBA 颜色格式
|
|
33
|
+
else if (rgbaPattern.test(color)) {
|
|
34
|
+
const [, r, g, b, a] = color.match(rgbaPattern)!.map(Number);
|
|
35
|
+
result = new Cesium.Color(r / 255, g / 255, b / 255, a);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return result;
|
|
39
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": [
|
|
4
|
+
"ES2015"
|
|
5
|
+
],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"outDir": "types",
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"target": "es2015",
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"emitDeclarationOnly": true,
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"baseUrl": "./", // 确保 Base URL 是项目根目录
|
|
16
|
+
"paths": {
|
|
17
|
+
"@/*": [
|
|
18
|
+
"src/*"
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
"include": [
|
|
23
|
+
"src/**/*.ts",
|
|
24
|
+
"src/**/*.d.ts",
|
|
25
|
+
"src/**/*.tsx",
|
|
26
|
+
"src/**/*.vue"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Viewer } from "cesium";
|
|
2
|
+
import { ViewerOption, FlyToOptionType, FlyToTargetType } from "./type";
|
|
3
|
+
export default class CesiumAlphaViewer {
|
|
4
|
+
viewer: Viewer;
|
|
5
|
+
constructor(container: string | HTMLElement, option?: ViewerOption);
|
|
6
|
+
goTo(target: FlyToTargetType, flyToOption?: FlyToOptionType): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Cesium3DTileset, SceneMode, GeocoderService, ProviderViewModel, UrlTemplateImageryProvider, Resource, Cartesian3, BoundingSphere } from "cesium";
|
|
2
|
+
/**
|
|
3
|
+
* 图层类型
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 地形类型
|
|
7
|
+
*/
|
|
8
|
+
export type ViewerOption = {
|
|
9
|
+
control?: ControlOption;
|
|
10
|
+
scene?: SceneOption;
|
|
11
|
+
basemap?: BasemapOption;
|
|
12
|
+
terrain?: TerrainOption;
|
|
13
|
+
};
|
|
14
|
+
export type SceneOption = {
|
|
15
|
+
center?: {
|
|
16
|
+
lng: number;
|
|
17
|
+
lat: number;
|
|
18
|
+
alt: number;
|
|
19
|
+
heading?: number;
|
|
20
|
+
pitch?: number;
|
|
21
|
+
roll?: number;
|
|
22
|
+
};
|
|
23
|
+
showSkyBox?: boolean;
|
|
24
|
+
skyBoxSource?: any;
|
|
25
|
+
showSun?: boolean;
|
|
26
|
+
ionToken?: string;
|
|
27
|
+
sceneMode?: SceneMode;
|
|
28
|
+
};
|
|
29
|
+
export type ControlOption = {
|
|
30
|
+
homeButton?: boolean | any;
|
|
31
|
+
zoom?: any;
|
|
32
|
+
sceneModePicker?: boolean | any;
|
|
33
|
+
projectionPicker?: boolean | any;
|
|
34
|
+
fullscreenButton?: boolean | any;
|
|
35
|
+
fullscreenElement?: HTMLElement | string | any;
|
|
36
|
+
vrButton?: boolean | any;
|
|
37
|
+
geocoder?: boolean | GeocoderService[] | any;
|
|
38
|
+
navigationHelpButton?: boolean | any;
|
|
39
|
+
navigationInstructionsInitiallyVisible?: boolean | any;
|
|
40
|
+
baseLayerPicker?: boolean | any;
|
|
41
|
+
imageryProviderViewModels?: ProviderViewModel[];
|
|
42
|
+
selectedImageryProviderViewModel?: ProviderViewModel;
|
|
43
|
+
terrainProviderViewModels?: ProviderViewModel[];
|
|
44
|
+
selectedTerrainProviderViewModel?: ProviderViewModel;
|
|
45
|
+
compass?: any;
|
|
46
|
+
showPopup?: boolean;
|
|
47
|
+
animation?: boolean;
|
|
48
|
+
timeline?: boolean;
|
|
49
|
+
infoBox?: boolean;
|
|
50
|
+
selectionIndicator?: boolean;
|
|
51
|
+
showRenderLoopErrors?: boolean;
|
|
52
|
+
};
|
|
53
|
+
export type BasemapOption = {
|
|
54
|
+
other?: UrlTemplateImageryProvider.ConstructorOptions;
|
|
55
|
+
};
|
|
56
|
+
export type TerrainOption = {
|
|
57
|
+
url?: string | Resource;
|
|
58
|
+
show?: boolean;
|
|
59
|
+
requestVertexNormals?: boolean;
|
|
60
|
+
requestWaterMask?: boolean;
|
|
61
|
+
requestMetadata?: boolean;
|
|
62
|
+
clip?: boolean;
|
|
63
|
+
flat?: boolean;
|
|
64
|
+
uplift?: boolean;
|
|
65
|
+
flood?: boolean;
|
|
66
|
+
};
|
|
67
|
+
export type FlyToOptionType = {
|
|
68
|
+
distence?: number;
|
|
69
|
+
roll?: number;
|
|
70
|
+
pitch?: number;
|
|
71
|
+
heading?: number;
|
|
72
|
+
};
|
|
73
|
+
export type FlyToTargetType = Cartesian3 | BoundingSphere | Cesium3DTileset | {
|
|
74
|
+
longitude: number;
|
|
75
|
+
latitude: number;
|
|
76
|
+
height?: number;
|
|
77
|
+
};
|
package/types/index.d.ts
ADDED
package/viewTest/App.vue
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="appContainer" id="cesiumContainer"></div>
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
import { onMounted } from "vue";
|
|
7
|
+
import * as Cesium from "cesium"
|
|
8
|
+
import {CesiumAlphaViewer} from "../src/index"
|
|
9
|
+
onMounted(() => {
|
|
10
|
+
let viewer = new CesiumAlphaViewer("cesiumContainer", {
|
|
11
|
+
scene: {
|
|
12
|
+
center: {
|
|
13
|
+
lng: 81.28382,
|
|
14
|
+
lat: 41.813928,
|
|
15
|
+
alt: 1500,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const gridImageryProvider = new Cesium.GridImageryProvider({
|
|
22
|
+
cells: 4,
|
|
23
|
+
glowWidth: 2,
|
|
24
|
+
color: Cesium.Color.fromCssColorString('#fff'),
|
|
25
|
+
backgroundColor: Cesium.Color.fromCssColorString('rgb(232, 227, 218)')
|
|
26
|
+
})
|
|
27
|
+
const gridImageryLayer = new Cesium.ImageryLayer(gridImageryProvider)
|
|
28
|
+
viewer.viewer.scene.imageryLayers.add(gridImageryLayer)
|
|
29
|
+
});
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<style lang="scss" scoped>
|
|
33
|
+
.appContainer {
|
|
34
|
+
width: 100vw;
|
|
35
|
+
height: 100vh;
|
|
36
|
+
}
|
|
37
|
+
</style>
|
|
38
|
+
|
package/viewTest/main.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createApp } from 'vue'
|
|
2
|
+
import AppView from './App.vue'
|
|
3
|
+
import 'element-plus/dist/index.css'
|
|
4
|
+
import "./style/style.scss"
|
|
5
|
+
import "cesium/Build/Cesium/Widgets/widgets.css";
|
|
6
|
+
//@ts-ignore
|
|
7
|
+
window.CESIUM_BASE_URL = '/node_modules/cesium/Build/Cesium/';
|
|
8
|
+
let app = createApp(AppView)
|
|
9
|
+
app.mount('#app')
|
|
10
|
+
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { defineConfig } from "vite";
|
|
2
|
+
import vue from "@vitejs/plugin-vue";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import typescript from "rollup-plugin-typescript2";
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
server: {
|
|
7
|
+
port: 9999,
|
|
8
|
+
proxy: {
|
|
9
|
+
"/feature": {
|
|
10
|
+
target: "http://192.168.0.240:6080",
|
|
11
|
+
changeOrigin: true, // 是否改变请求头中的 Origin
|
|
12
|
+
rewrite: (path) => path.replace(/^\/api/, ""), // 重写路径
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
plugins: [
|
|
17
|
+
vue(),
|
|
18
|
+
],
|
|
19
|
+
resolve: {
|
|
20
|
+
alias: {
|
|
21
|
+
"@": path.resolve(__dirname, "src"), // 将 @ 指向 src 目录
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
build: {
|
|
25
|
+
minify: false,
|
|
26
|
+
emptyOutDir: false,
|
|
27
|
+
lib: {
|
|
28
|
+
entry: "./src/index.ts",
|
|
29
|
+
formats: ["es"],
|
|
30
|
+
},
|
|
31
|
+
rollupOptions: {
|
|
32
|
+
external: ["vue"],
|
|
33
|
+
output: {
|
|
34
|
+
// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
|
|
35
|
+
globals: {
|
|
36
|
+
vue: "Vue",
|
|
37
|
+
},
|
|
38
|
+
entryFileNames: `[name].js`,
|
|
39
|
+
plugins: [
|
|
40
|
+
// {
|
|
41
|
+
// name: 'log-js-files', // 插件名称
|
|
42
|
+
// generateBundle(options, bundle) {
|
|
43
|
+
// // 遍历生成的文件
|
|
44
|
+
// for (const fileName in bundle) {
|
|
45
|
+
// const chunk = bundle[fileName];
|
|
46
|
+
// // 检查是否为 JS 文件
|
|
47
|
+
// if (chunk.type === 'chunk' && fileName.endsWith('.js')) {
|
|
48
|
+
// const jsContent = chunk.code;
|
|
49
|
+
// let text = JavaScriptObfuscator.obfuscate(jsContent, {
|
|
50
|
+
// compact: true,
|
|
51
|
+
// controlFlowFlattening: false,
|
|
52
|
+
// deadCodeInjection: false,
|
|
53
|
+
// debugProtection: false,
|
|
54
|
+
// identifierNamesGenerator: 'hexadecimal',
|
|
55
|
+
// stringArray: true,
|
|
56
|
+
// stringArrayThreshold: 0.2,
|
|
57
|
+
// selfDefending: false,
|
|
58
|
+
// })
|
|
59
|
+
// chunk.code = text.getObfuscatedCode()
|
|
60
|
+
// }
|
|
61
|
+
// }
|
|
62
|
+
// },
|
|
63
|
+
// },
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
outDir: "./dist", // 打包输出目录
|
|
68
|
+
},
|
|
69
|
+
});
|