当前位置:网站首页>【cesium】加载并定位 3D Tileset
【cesium】加载并定位 3D Tileset
2022-08-05 04:46:00 【顾鸟】
一. 介绍
首页加载 3D Tileset 模型,然后通过转换坐标并定位到指定位置。
二. 效果

三. 实现
// index.vue
<template>
<div class="viewer">
<vc-viewer @ready="ready">
<vc-layer-imagery>
<vc-provider-imagery-tianditu
protocol="http"
map-style="img_w"
token="436ce7e50d27eede2f2929307e6b33c0"
:projectionTransforms="projectionTransforms"
></vc-provider-imagery-tianditu>
</vc-layer-imagery>
</vc-viewer>
</div>
</template>
<script>
import {
update3dtilesMaxtrix } from "../utils";
export default {
data() {
return {
mapStyle: "6",
ltype: "0",
projectionTransforms: {
from: "WGS84", to: "GCJ02" }
};
},
methods: {
// 地图初始化
ready(cesiumInstance) {
const {
Cesium, viewer } = cesiumInstance;
window.$cesiumInstance = cesiumInstance;
window.Cesium = Cesium;
window.viewer = viewer;
this.loadTile();
},
// 加载 3dtiles 模型
loadTile() {
const {
Cesium, viewer } = window.$cesiumInstance;
const scene = viewer.scene; // 创建场景
// 向集合添加一个原语。
const tileset = scene.primitives.add(
new Cesium.Cesium3DTileset({
url: "http://192.168.0.1/sppmodel/1/tileset.json", // 还可以是json、http链接等,使用自己的地址
dynamicScreenSpaceError: true,
cullWithChildrenBounds: false,
skipLevels: 0,
maximumScreenSpaceError: 0
})
);
tileset.readyPromise
.then(function (tileset) {
// 坐标转换和定位
let params = {
tx: 117.227267, //模型中心X轴坐标(经度,单位:十进制度)
ty: 31.820567, //模型中心Y轴坐标(纬度,单位:十进制度)
tz: 0, //模型中心Z轴坐标(高程,单位:米)
rx: 0, //X轴(经度)方向旋转角度(单位:度)
ry: 0, //Y轴(纬度)方向旋转角度(单位:度)
rz: 0, //Z轴(高程)方向旋转角度(单位:度)
};
update3dtilesMaxtrix(tileset, params);
const default_headingPitchRange = new Cesium.HeadingPitchRange(0.3, -0.2, tileset.boundingSphere.radius * 2.0);
viewer.flyTo(tileset, {
offset: default_headingPitchRange, });
})
.catch(function (error) {
console.log(error);
});
},
},
};
</script>
<style>
.viewer {
width: 100%;
height: 100%;
}
</style>
// update3dtilesMaxtrix.js
// let params = {
// tx: 120.257, //模型中心X轴坐标(经度,单位:十进制度)
// ty: 31.226, //模型中心Y轴坐标(纬度,单位:十进制度)
// tz: 2800, //模型中心Z轴坐标(高程,单位:米)
// rx: 0, //X轴(经度)方向旋转角度(单位:度)
// ry: 0, //Y轴(纬度)方向旋转角度(单位:度)
// rz: -1 //Z轴(高程)方向旋转角度(单位:度)
// };
export const update3dtilesMaxtrix = function (tileset, params) {
//旋转
let Cesium = window.Cesium
let mx = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(params.rx));
let my = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(params.ry));
let mz = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(params.rz));
let rotationX = Cesium.Matrix4.fromRotationTranslation(mx);
let rotationY = Cesium.Matrix4.fromRotationTranslation(my);
let rotationZ = Cesium.Matrix4.fromRotationTranslation(mz);
//平移
let position = Cesium.Cartesian3.fromDegrees(params.tx, params.ty, params.tz);
let m = Cesium.Transforms.eastNorthUpToFixedFrame(position);
let scale = Cesium.Matrix4.fromUniformScale(0.85);
// //缩放
Cesium.Matrix4.multiply(m, scale, m);
//旋转、平移矩阵相乘
Cesium.Matrix4.multiply(m, rotationX, m);
Cesium.Matrix4.multiply(m, rotationY, m);
Cesium.Matrix4.multiply(m, rotationZ, m);
//赋值给tileset
tileset._root.transform = m;
// return m;
}
边栏推荐
- The production method of the powered small sailboat is simple, the production method of the electric small sailboat
- The most comprehensive exam questions for software testing engineers in 2022
- 炎炎夏日教你利用小米智能家居配件+树莓派4接入Apple HomeKit
- upload upload pictures to Tencent cloud, how to upload pictures
- [Surveying] Quick Summary - Excerpt from Gaoshu Gang
- bytebuffer put flip compact clear 方法演示
- mutillidae download and installation
- In the WebView page of the UI automation test App, the processing method when the search bar has no search button
- 一篇博客通关Redis技术栈
- Application status of digital twin technology in power system
猜你喜欢
随机推荐
【8.4】代码源 - 【数学】【历法】【删库】【不朴素的数列(Bonus)】
Please write the SparkSQL statement
Shell(4) Conditional Control Statement
多列属性column元素的可见性:display、visibility、opacity、垂直对齐方式:vertical-align、z-index 越大越显示在上层
国学*周易*梅花易数 代码实现效果展示 - 梅花心易
AUTOCAD - dimension association
【 8.4 】 source code - [math] [calendar] [delete library 】 【 is not a simple sequence (Bonus) 】
[8.2] Code Source - [Currency System] [Coins] [New Year's Questions (Data Enhanced Edition)] [Three Stages]
Day019 方法重写与相关类的介绍
不看后悔,appium自动化环境完美搭建
DEJA_VU3D - Cesium功能集 之 059-腾讯地图纠偏
How to deal with DNS hijacking?
[8.1] Code Source - [The Second Largest Number Sum] [Stone Game III] [Balanced Binary Tree]
A 35-year-old software testing engineer with a monthly salary of less than 2W, resigns and is afraid of not finding a job, what should he do?
Error creating bean with name ‘configDataContextRefresher‘ defined in class path resource
Cron(Crontab)--use/tutorial/example
[CISCN2019 华东南赛区]Web11
dedecms dream weaving tag tag does not support capital letters fix
算法---一和零(Kotlin)
Paparazzi: Surface Editing by way of Multi-View Image Processing




![[SWPU2019]Web1](/img/06/36e69a2d7d5475a6749a7d81edf50f.png)
![[Geek Challenge 2019]FinalSQL](/img/e4/0c8225ef7c5e7e5bdbaac2ef6fc867.png)



