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,53 @@
|
|
|
1
|
+
import { Viewer, Math, Cartesian3 } from "cesium";
|
|
2
|
+
import { ViewerOption } from "../type";
|
|
3
|
+
|
|
4
|
+
let defaultOption: Viewer.ConstructorOptions = {
|
|
5
|
+
animation: false,
|
|
6
|
+
baseLayerPicker: false, // 右上角的图层选择按钮
|
|
7
|
+
fullscreenButton: false, // 全屏按钮
|
|
8
|
+
vrButton: false,
|
|
9
|
+
geocoder: false, // 搜索框
|
|
10
|
+
homeButton: false,
|
|
11
|
+
infoBox: false, // 信息框是否显示
|
|
12
|
+
sceneModePicker: false, // 模式切换按钮
|
|
13
|
+
selectionIndicator: false, // 选择指示器是否显示
|
|
14
|
+
timeline: false, // 时间轴
|
|
15
|
+
navigationHelpButton: false, // 导航帮助按钮是否显示
|
|
16
|
+
navigationInstructionsInitiallyVisible: false,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function createViewer(
|
|
20
|
+
container: string | HTMLElement,
|
|
21
|
+
option?: ViewerOption
|
|
22
|
+
) {
|
|
23
|
+
let viewer = new Viewer(container, {
|
|
24
|
+
...defaultOption,
|
|
25
|
+
...option?.control,
|
|
26
|
+
sceneMode: option?.scene?.sceneMode,
|
|
27
|
+
baseLayer: undefined,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (option) {
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (option?.scene?.center) {
|
|
34
|
+
let centerPosition = Cartesian3.fromDegrees(
|
|
35
|
+
option?.scene.center?.lng,
|
|
36
|
+
option?.scene.center?.lat,
|
|
37
|
+
option?.scene.center?.alt
|
|
38
|
+
);
|
|
39
|
+
// 设置摄像机初始视角
|
|
40
|
+
viewer.camera.setView({
|
|
41
|
+
destination: centerPosition, // 经纬度 + 高度
|
|
42
|
+
orientation: {
|
|
43
|
+
heading: Math.toRadians(option?.scene?.center?.heading || 0), // 朝向角度
|
|
44
|
+
pitch: Math.toRadians(option?.scene?.center?.pitch || -90), // 俯仰角(负值向下)
|
|
45
|
+
roll: option?.scene?.center?.roll, // 滚动角度
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
viewer.creditDisplay.container.remove();
|
|
51
|
+
|
|
52
|
+
return viewer;
|
|
53
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Cartesian3,
|
|
3
|
+
BoundingSphere,
|
|
4
|
+
Cesium3DTileset,
|
|
5
|
+
Viewer,
|
|
6
|
+
Cartographic,
|
|
7
|
+
Math,
|
|
8
|
+
HeadingPitchRange,
|
|
9
|
+
} from "cesium";
|
|
10
|
+
import { FlyToOptionType, FlyToTargetType } from "../type";
|
|
11
|
+
|
|
12
|
+
export function goTo(
|
|
13
|
+
viewer: Viewer,
|
|
14
|
+
target:FlyToTargetType,
|
|
15
|
+
option?: FlyToOptionType
|
|
16
|
+
) {
|
|
17
|
+
let defaultFlyToOption = {
|
|
18
|
+
distence: 3000,
|
|
19
|
+
pitch: -90,
|
|
20
|
+
heading: 0,
|
|
21
|
+
roll: 0.0,
|
|
22
|
+
};
|
|
23
|
+
const camera = viewer.camera;
|
|
24
|
+
|
|
25
|
+
if (option) {
|
|
26
|
+
if (option.distence) {
|
|
27
|
+
defaultFlyToOption.distence = option.distence;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (option.pitch) {
|
|
31
|
+
defaultFlyToOption.pitch = option.pitch;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (option.heading) {
|
|
35
|
+
defaultFlyToOption.heading = option.heading;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (option.roll) {
|
|
39
|
+
defaultFlyToOption.roll = option.roll;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (target instanceof Cartesian3) {
|
|
44
|
+
// 如果目标是 Cartesian3 坐标
|
|
45
|
+
camera.flyTo({
|
|
46
|
+
destination: setHeight(target, defaultFlyToOption.distence),
|
|
47
|
+
orientation: {
|
|
48
|
+
heading: Math.toRadians(defaultFlyToOption.heading),
|
|
49
|
+
pitch: Math.toRadians(defaultFlyToOption.pitch),
|
|
50
|
+
roll: defaultFlyToOption.roll,
|
|
51
|
+
},
|
|
52
|
+
duration: 3, // 飞行时长,单位:秒
|
|
53
|
+
});
|
|
54
|
+
} else if (target instanceof Cesium3DTileset) {
|
|
55
|
+
camera.flyTo({
|
|
56
|
+
destination: setHeight(
|
|
57
|
+
target.boundingSphere.center,
|
|
58
|
+
defaultFlyToOption.distence
|
|
59
|
+
),
|
|
60
|
+
orientation: {
|
|
61
|
+
heading: Math.toRadians(defaultFlyToOption.heading),
|
|
62
|
+
pitch: Math.toRadians(defaultFlyToOption.pitch),
|
|
63
|
+
roll: defaultFlyToOption.roll,
|
|
64
|
+
},
|
|
65
|
+
duration: 3,
|
|
66
|
+
});
|
|
67
|
+
} else if (target instanceof BoundingSphere) {
|
|
68
|
+
// 如果目标是 BoundingSphere,直接飞向包围球
|
|
69
|
+
camera.flyToBoundingSphere(target, {
|
|
70
|
+
duration: 3,
|
|
71
|
+
offset: new HeadingPitchRange(
|
|
72
|
+
defaultFlyToOption.heading,
|
|
73
|
+
defaultFlyToOption.pitch,
|
|
74
|
+
defaultFlyToOption.distence
|
|
75
|
+
),
|
|
76
|
+
complete: () => {
|
|
77
|
+
console.log("飞行结束");
|
|
78
|
+
},
|
|
79
|
+
cancel: () => {
|
|
80
|
+
console.log("飞行被取消");
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
} else if (target.longitude && target.latitude) {
|
|
84
|
+
const { longitude, latitude, height } = target;
|
|
85
|
+
|
|
86
|
+
const destination = Cartesian3.fromDegrees(longitude, latitude, height);
|
|
87
|
+
|
|
88
|
+
camera.flyTo({
|
|
89
|
+
destination: setHeight(destination,defaultFlyToOption.distence),
|
|
90
|
+
duration: 3,
|
|
91
|
+
orientation: {
|
|
92
|
+
heading: Math.toRadians(defaultFlyToOption.heading),
|
|
93
|
+
pitch: Math.toRadians(defaultFlyToOption.pitch),
|
|
94
|
+
roll: defaultFlyToOption.roll,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function setHeight(position: Cartesian3, height: number) {
|
|
101
|
+
let carposition = Cartographic.fromCartesian(position);
|
|
102
|
+
carposition.height += height;
|
|
103
|
+
return Cartesian3.fromRadians(
|
|
104
|
+
carposition.longitude,
|
|
105
|
+
carposition.latitude,
|
|
106
|
+
carposition.height
|
|
107
|
+
);
|
|
108
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Cesium3DTileset, ShadowMode } from "cesium";
|
|
2
|
+
import CesiumAlphaViewer from "..";
|
|
3
|
+
import { ModelInfoOption } from "../type";
|
|
4
|
+
export async function load3DtilestModel(earthViewer:CesiumAlphaViewer,model: ModelInfoOption[]) {
|
|
5
|
+
if (!earthViewer.viewer) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
let tilestArr: Cesium3DTileset[] = [];
|
|
9
|
+
for (let item of model) {
|
|
10
|
+
// 加载模型
|
|
11
|
+
const tileset = await Cesium3DTileset.fromUrl(item.modelUrl, {
|
|
12
|
+
maximumScreenSpaceError: 32, // 增大屏幕空间误差
|
|
13
|
+
cullWithChildrenBounds: true, // 使用子边界裁剪
|
|
14
|
+
dynamicScreenSpaceError: false, // 禁用动态屏幕空间误差
|
|
15
|
+
skipLevelOfDetail: true, // 跳过LOD层级
|
|
16
|
+
baseScreenSpaceError: 512, // 基础屏幕空间误差
|
|
17
|
+
preloadWhenHidden: true, // 预加载隐藏瓦片
|
|
18
|
+
shadows: ShadowMode.DISABLED,
|
|
19
|
+
preloadFlightDestinations: true, // 预加载飞行目的地瓦片
|
|
20
|
+
preferLeaves: true, // 优先加载叶子节点
|
|
21
|
+
progressiveResolutionHeightFraction: 0.5, // 渐进式分辨率高度分数
|
|
22
|
+
dynamicScreenSpaceErrorDensity: 10, // 数值加大,能让周边加载变快 --- 用于调整动态屏幕空间误差的密度,类似于雾密度(默认0.00278)
|
|
23
|
+
dynamicScreenSpaceErrorFactor: 1, // 不知道起了什么作用没,反正放着吧先 --- 用于增加计算的动态屏幕空间误差的因素(默认4.0)
|
|
24
|
+
dynamicScreenSpaceErrorHeightFalloff: 0.25, // --- 密度开始下降的瓦片集高度的比率(默认0.25)
|
|
25
|
+
foveatedScreenSpaceError: true, // --- 优化选项。通过暂时提高屏幕边缘周围图块的屏幕空间错误,优先加载屏幕中心的图块。一旦Cesium3DTileset#foveatedConeSize加载确定的屏幕中心的所有图块,屏幕空间错误就会恢复正常。(默认true)
|
|
26
|
+
foveatedConeSize: 0.1, // --- 优化选项。当Cesium3DTileset#foveatedScreenSpaceError为 true 时使用来控制决定延迟哪些图块的锥体大小。立即加载此圆锥内的瓷砖。圆锥外的瓷砖可能会根据它们在圆锥外的距离及其屏幕空间误差而延迟。这是由Cesium3DTileset#foveatedInterpolationCallback和控制的Cesium3DTileset#foveatedMinimumScreenSpaceErrorRelaxation。将此设置为 0.0 意味着圆锥将是由相机位置及其视图方向形成的线。将此设置为 1.0 意味着锥体包含相机的整个视野,禁用效果(默认0.1)
|
|
27
|
+
foveatedMinimumScreenSpaceErrorRelaxation: 0.0, // --- 优化选项。当Cesium3DTileset#foveatedScreenSpaceError为 true 时使用以控制中央凹锥之外的图块的起始屏幕空间误差松弛。屏幕空间错误将从 tileset 值开始Cesium3DTileset#maximumScreenSpaceError根据提供的Cesium3DTileset#foveatedInterpolationCallback.(默认0.0)
|
|
28
|
+
cacheBytes: 10000000000,
|
|
29
|
+
backFaceCulling: false, // --- 是否剔除背面几何体。当为 true 时,背面剔除由 glTF 材质的 doubleSided 属性确定;如果为 false,则禁用背面剔除(默认true)
|
|
30
|
+
...item.modelOption,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
//贴地逻辑
|
|
34
|
+
// let boundingSphere = tileset.boundingSphere;
|
|
35
|
+
// let cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
|
|
36
|
+
// let claimPosition = this.viewer.scene.clampToHeight(boundingSphere.center)
|
|
37
|
+
// var heightOffset = 3000;
|
|
38
|
+
// var translation = Cesium.Matrix4.fromTranslation(new Cesium.Cartesian3(0, 0, heightOffset));
|
|
39
|
+
// tileset.modelMatrix = Cesium.Matrix4.multiply(tileset.modelMatrix, translation, new Cesium.Matrix4());
|
|
40
|
+
|
|
41
|
+
//@ts-ignore
|
|
42
|
+
tileset.name = item.modelName;
|
|
43
|
+
//@ts-ignore
|
|
44
|
+
tileset.url = item.modelUrl;
|
|
45
|
+
//@ts-ignore
|
|
46
|
+
tileset.uid = item.modelId || nanoid();
|
|
47
|
+
|
|
48
|
+
earthViewer.viewer?.scene.primitives.add(tileset);
|
|
49
|
+
|
|
50
|
+
tilestArr.push(tileset);
|
|
51
|
+
|
|
52
|
+
earthViewer.modelDatasource.push(tileset);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return tilestArr;
|
|
56
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { cloneDeep } from "lodash";
|
|
2
|
+
import CesiumAlphaViewer from "..";
|
|
3
|
+
import { LayerInfoOption } from "../type";
|
|
4
|
+
import { GeoJsonLayer } from "@/core/CesiumAlphaGeoJsonLayer";
|
|
5
|
+
|
|
6
|
+
export async function loadGeoJsonLayer(earthView:CesiumAlphaViewer,layerInfo:LayerInfoOption[]) {
|
|
7
|
+
let that = earthView;
|
|
8
|
+
let returnArr: any[] = [];
|
|
9
|
+
let promiseArray: Promise<any>[] = [];
|
|
10
|
+
for (let item of layerInfo) {
|
|
11
|
+
let option = cloneDeep(item.option);
|
|
12
|
+
let promise = GeoJsonLayer.load(item.url, option).then(
|
|
13
|
+
(layer: GeoJsonLayer) => {
|
|
14
|
+
earthView.layerDatasource.push(layer);
|
|
15
|
+
that.viewer?.scene.primitives.add(layer.primitiveCollection);
|
|
16
|
+
returnArr.push(layer);
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
promiseArray.push(promise);
|
|
20
|
+
}
|
|
21
|
+
await Promise.all(promiseArray);
|
|
22
|
+
|
|
23
|
+
earthView.viewer.scene.terrainProviderChanged.raiseEvent();
|
|
24
|
+
|
|
25
|
+
//排序
|
|
26
|
+
let sortArr = returnArr.sort((a: any, b: any) => {
|
|
27
|
+
return a.zIndex - b.zIndex;
|
|
28
|
+
});
|
|
29
|
+
sortArr.forEach((layer: GeoJsonLayer) => {
|
|
30
|
+
earthView.viewer?.scene.primitives.raiseToTop(layer.primitiveCollection);
|
|
31
|
+
});
|
|
32
|
+
return returnArr;
|
|
33
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Cesium3DTileset,
|
|
3
|
+
SceneMode,
|
|
4
|
+
GeocoderService,
|
|
5
|
+
ProviderViewModel,
|
|
6
|
+
UrlTemplateImageryProvider,
|
|
7
|
+
Resource,
|
|
8
|
+
Cartesian3,
|
|
9
|
+
BoundingSphere,
|
|
10
|
+
} from "cesium";
|
|
11
|
+
import { GeoJsonLayerType } from "../CesiumAlphaGeoJsonLayer/type";
|
|
12
|
+
|
|
13
|
+
export enum EarthMode {
|
|
14
|
+
SCENE3D = SceneMode.SCENE3D,
|
|
15
|
+
SCENE2D = SceneMode.SCENE2D,
|
|
16
|
+
COLUM_VIEW = SceneMode.COLUMBUS_VIEW,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 图层类型
|
|
21
|
+
*/
|
|
22
|
+
export enum ImageLayerType {
|
|
23
|
+
TXDT,
|
|
24
|
+
GDDT,
|
|
25
|
+
ARCGIS,
|
|
26
|
+
TDT,
|
|
27
|
+
CUSTOM,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 地形类型
|
|
32
|
+
*/
|
|
33
|
+
export enum TerrainType {
|
|
34
|
+
/**
|
|
35
|
+
* 无地形
|
|
36
|
+
*/
|
|
37
|
+
NONE = "none",
|
|
38
|
+
/**
|
|
39
|
+
* arcgis地形
|
|
40
|
+
*/
|
|
41
|
+
ARCGIS = "arcgis",
|
|
42
|
+
/**
|
|
43
|
+
* ION在线地形(cesium官方服务)
|
|
44
|
+
*/
|
|
45
|
+
ICON = "icon",
|
|
46
|
+
// /**
|
|
47
|
+
// * 自定义
|
|
48
|
+
// */
|
|
49
|
+
CUSTOM = "custom",
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type ViewerOption = {
|
|
53
|
+
control?: ControlOption;
|
|
54
|
+
scene?: SceneOption;
|
|
55
|
+
basemap?: BasemapOption;
|
|
56
|
+
terrain?: TerrainOption;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type SceneOption = {
|
|
60
|
+
center?: {
|
|
61
|
+
lng: number;
|
|
62
|
+
lat: number;
|
|
63
|
+
alt: number;
|
|
64
|
+
heading?: number;
|
|
65
|
+
pitch?: number;
|
|
66
|
+
roll?: number;
|
|
67
|
+
};
|
|
68
|
+
showSkyBox?: boolean;
|
|
69
|
+
skyBoxSource?: any;
|
|
70
|
+
showSun?: boolean;
|
|
71
|
+
ionToken?: string;
|
|
72
|
+
sceneMode?: SceneMode;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type ControlOption = {
|
|
76
|
+
homeButton?: boolean | any;
|
|
77
|
+
zoom?: any;
|
|
78
|
+
sceneModePicker?: boolean | any;
|
|
79
|
+
projectionPicker?: boolean | any;
|
|
80
|
+
fullscreenButton?: boolean | any;
|
|
81
|
+
fullscreenElement?: HTMLElement | string | any;
|
|
82
|
+
vrButton?: boolean | any;
|
|
83
|
+
geocoder?: boolean | GeocoderService[] | any;
|
|
84
|
+
navigationHelpButton?: boolean | any;
|
|
85
|
+
navigationInstructionsInitiallyVisible?: boolean | any;
|
|
86
|
+
baseLayerPicker?: boolean | any;
|
|
87
|
+
imageryProviderViewModels?: ProviderViewModel[];
|
|
88
|
+
selectedImageryProviderViewModel?: ProviderViewModel;
|
|
89
|
+
terrainProviderViewModels?: ProviderViewModel[];
|
|
90
|
+
selectedTerrainProviderViewModel?: ProviderViewModel;
|
|
91
|
+
compass?: any;
|
|
92
|
+
showPopup?: boolean;
|
|
93
|
+
animation?: boolean;
|
|
94
|
+
timeline?: boolean;
|
|
95
|
+
infoBox?: boolean;
|
|
96
|
+
selectionIndicator?: boolean;
|
|
97
|
+
showRenderLoopErrors?: boolean;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export type BasemapOption = {
|
|
101
|
+
type?: ImageLayerType;
|
|
102
|
+
other?: UrlTemplateImageryProvider.ConstructorOptions;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export type TerrainOption = {
|
|
106
|
+
type?: TerrainType;
|
|
107
|
+
url?: string | Resource;
|
|
108
|
+
show?: boolean;
|
|
109
|
+
requestVertexNormals?: boolean;
|
|
110
|
+
requestWaterMask?: boolean;
|
|
111
|
+
requestMetadata?: boolean;
|
|
112
|
+
clip?: boolean;
|
|
113
|
+
flat?: boolean;
|
|
114
|
+
uplift?: boolean;
|
|
115
|
+
flood?: boolean;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export type FlyToOptionType = {
|
|
119
|
+
distence?: number;
|
|
120
|
+
roll?: number;
|
|
121
|
+
pitch?: number;
|
|
122
|
+
heading?: number;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export type FlyToTargetType =
|
|
126
|
+
| Cartesian3
|
|
127
|
+
| BoundingSphere
|
|
128
|
+
| Cesium3DTileset
|
|
129
|
+
| { longitude: number; latitude: number; height?: number };
|
|
130
|
+
|
|
131
|
+
export type ModelInfoOption = {
|
|
132
|
+
modelUrl: string;
|
|
133
|
+
modelName: string;
|
|
134
|
+
modelId: string;
|
|
135
|
+
modelOption?: Cesium3DTileset.ConstructorOptions;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export type LayerInfoOption = {
|
|
139
|
+
url: string;
|
|
140
|
+
option: GeoJsonLayerType.GeoJsonLayerOptions;
|
|
141
|
+
};
|
package/src/index.ts
ADDED