From 9fa1e63438828075ec7a93003cfd43aabbc849d9 Mon Sep 17 00:00:00 2001 From: shijing Date: Mon, 18 Mar 2024 11:43:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E4=BD=8D=E7=BD=AE=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/bigScreen/cesiumtest.vue | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/views/bigScreen/cesiumtest.vue b/src/views/bigScreen/cesiumtest.vue index 8fa98445..d7d24a4f 100644 --- a/src/views/bigScreen/cesiumtest.vue +++ b/src/views/bigScreen/cesiumtest.vue @@ -374,21 +374,23 @@ export default { var url = "factory.glb"; var height = 0; viewer.entities.removeAll() //加载之前先清楚所有entity - var position = Cesium.Cartesian3.fromDegrees(87.62594666147378, 42.975362631477815, height) - var heading = Cesium.Math.toRadians(310) //135度转弧度 + var position = Cesium.Cartesian3.fromDegrees(88.644, 42.7229, height) + var heading = Cesium.Math.toRadians(191) //310度转弧度 var pitch = Cesium.Math.toRadians(0); var roll = Cesium.Math.toRadians(0); var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll) var orientation = Cesium.Transforms.headingPitchRollQuaternion( position,hpr ) + var modelScale = 30.0; // 假设模型原始单位是厘米,需要转换为米 var modelEntity = viewer.entities.add({ name: 'photon', position: position, orientation: orientation, model: { uri: url,//注意entitits.add方式加载gltf文件时,这里是uri,不是url,并且这种方式只能加载.glb格式的文件 - scale: 1.0,//缩放比例 + scale: modelScale,//缩放比例 + modelMatrix: Cesium.Transforms.eastNorthUpToFixedFrame(position), minimumPixelSize: 256,//最小像素大小,可以避免太小看不见 maximumScale: 20000,//模型的最大比例尺大小。minimumPixelSize的上限 incrementallyLoadTextures: true,//加载模型后纹理是否可以继续流入 @@ -396,15 +398,18 @@ export default { heightReference: Cesium.HeightReference.NONE }, }) - viewer.trackedEntity = modelEntity; // 聚焦模型 - viewer.zoomTo(modelEntity, new Cesium.HeadingPitchRange(-4.2, -0.5, 30)); + viewer.trackedEntity = modelEntity; // 聚焦模型 + //设置相机位置 + viewer.zoomTo(modelEntity, new Cesium.HeadingPitchRange(-3.1, -0.6, 900)); that.getEquipmentList(); // 监听鼠标左键点击事件 var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas); handler.setInputAction(function (click) { var feature = viewer.scene.pick(click.position); - that.objItem = feature.id._attrs; - that.getInfo(feature.id._id); + if (feature.id._attrs) { + that.objItem = feature.id._attrs; + that.getInfo(feature.id._id); + } if (Cesium.defined(feature)) { // 判断点击位置是否有模型被选中 var pickedPosition = viewer.scene.pickPosition(click.position); @@ -423,7 +428,6 @@ export default { } }, Cesium.ScreenSpaceEventType.LEFT_CLICK); - }, methods: { getChartTime() { @@ -522,7 +526,7 @@ export default { let imgUrl = that.getItemIcon(item.cate_code) let lon = parseFloat(item.coordinates.longitude); let lat = parseFloat(item.coordinates.latitude); - let height = parseInt(item.coordinates.height) + 0.5; + let height = parseInt(item.coordinates.height) + 15; let type = item.cate_code; let arrs = { name:item.name, lon: lon, lat:lat, height:height, id:item.id, type: type }; let config = { show: true, fontSize: '16px', fillColor: '#ffffff', fillWidth: 1, pixelOffsetX: 10, pixelOffsetY: -30, image: imgUrl, imgWidth: 50, imgHeight: 50, textDistance: 550000, imgDistance: 550000 };