Cesium 初始化

Cesium.Ion.defaultAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI4ZmI2Njk5Zi00NjdmLTRiMzctODZiYS1hYTQ0MGFhMjQxMGIiLCJpZCI6MzE2ODksInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1OTU4MzQzNzV9.ee2r1thnG3Ajot3BYpFXfNKUP8SUtWpYDx2na02mT0A";

Cesium.Camera.DEFAULT_VIEW_FACTOR = 1.5;

Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(90, -20, 110, 90);

/**
 * 创建Cesium Viewer实例。
 * @param { string } domId - 用于创建Cesium Viewer的DOM元素ID。
 * @returns { Cesium.Viewer } - 返回创建的Cesium Viewer实例。
 */
export function createViewer(domId, options = {}) {
    const imageryProvider = new Cesium.SingleTileImageryProvider({
        url: "data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==",
    });

    const contextOptions = {
        webgl: {
            alpha: true,
            depth: false,
            stencil: true,
            antialias: true,
            premultipliedAlpha: true,
            preserveDrawingBuffer: true,
            failIfMajorPerformanceCaveat: true,
        },
        allowTextureFilterAnisotropic: true,
    }

    const _options = {
        imageryProvider: imageryProvider,
        baseLayerPicker: false,
        animation: false,
        fullscreenButton: false,
        vrButton: false,
        geocoder: false,
        homeButton: false,
        infoBox: false,
        sceneModePicker: false,
        selectionIndicator: false,
        timeline: false,
        navigationHelpButton: false,
        navigationInstructionsInitiallyVisible: false,
        scene3DOnly: true,
        shouldAnimate: false,
        skyBox: false,
        skyAtmosphere: false,
        showRenderLoopErrors: false,
        contextOptions: contextOptions,

        ...options
    }

    const viewer = new Cesium.Viewer(domId, _options);

    viewer.imageryLayers.removeAll();

    viewer.cesiumWidget.creditContainer.style.display = "none";

    viewer.scene.backgroundColor = Cesium.Color.TRANSPARENT;

    viewer.scene.globe.baseColor = Cesium.Color.TRANSPARENT;

    return viewer;
}


export default createViewer;
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容