vue + cesium初始化地图 + 鼠标经过地图(点、线等其他实体)样式
export function initMap(mapViewer) {
Cesium.Ion.defaultAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI0OTUzOGJhMy1iNzVjLTQwZjItYWYyNy03YjA4MjM0YWE2MWMiLCJpZCI6OTYwNDksImlhdCI6MTY1NDEzMTI3MH0.PfjYnGe-B8P3jVpaP-DrToNFT5CM1-Ukbn1VWA4wFAY";
let viewer = new Cesium.Viewer("cesium-con", mapViewer);
window.viewer = viewer;
//抗锯齿
if (Cesium.FeatureDetection.supportsImageRenderingPixelated()) {//判断是否支持图像渲染像素化处理
viewer.resolutionScale = window.devicePixelRatio;
}
viewer.scene.fxaa = true;
viewer.scene.postProcessStages.fxaa.enabled = true;
viewer.scene.globe.depthTestAgainstTerrain = false;
// viewer.scene.globe.depthTestAgainstTerrain = true;
viewer._cesiumWidget._creditContainer.style.display = "none"; // 去掉版权信息
viewer.scene.skyBox.show = false; //隐藏天空盒
viewer.scene.backgroundColor = new Cesium.Color(0.0, 0.0, 0.0, 0.0); //设置背景透明
viewer.scene.skyAtmosphere.show = false; //隐藏大气圈
viewer.scene.sun.show = false; //隐藏太阳
viewer.scene.moon.show = false; //隐藏月亮
// viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(
// Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK
// ); // 取消双击
// 初始化动画
// viewer.camera.setView({
// destination: Cesium.Cartesian3.fromDegrees(0, 0, 15000000),
// orientation: {
// heading: 0.2079384332084935,
// roll: 0.00031509431759868534,
// pitch: -1.0
// },
// duration: 3
// });
// viewer.imageryLayers.get(0).alpha = 0.01
// viewer.scene.globe.baseColor = Cesium.Color.fromCssColorString('#05285cb3')
// viewer._container.style.cursor = 'crosshair'
viewer.scene.screenSpaceCameraController.minimumZoomDistance = 650;//相机的高度的最小值
viewer.scene.screenSpaceCameraController.maximumZoomDistance = 22000000; //相机高度的最大值
infoToolPop = new InfoTool(viewer);
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas) // event事件处理程序
handler.setInputAction((e) => {
const currentMoveObj = viewer.scene.pick(e.endPosition)
if (currentMoveObj) {
// 鼠标滑过模型
viewer.enableCursorStyle = false
viewer._element.style.cursor = ''
document.documentElement.style.cursor = 'pointer'
// document.body.classList.add('draw-cursor') // 设置为自定义的图标
} else {
// 鼠标滑过场景
viewer.enableCursorStyle = true
document.documentElement.style.cursor = ''
// document.body.classList.remove('draw-cursor')
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
return viewer
}