vue cesium 加载倾斜摄影数据并在上面添加自定义标注【转】

在main.js引入

import Cesium from ‘cesium/Cesium‘
import ‘../node_modules/cesium/Build/Cesium/Widgets/widgets.css‘

Vue.prototype.Cesium = Cesium;

<br>// 以下是组件内容<br><br><br><br><template>

    <div class="cesium-wrap">

        <div id="cesiumContainer"></div>

        <el-form ref="form" :model="form" label-width="80px" class="cesiumForm" v-if="showForm" size="mini">

            <el-form-item label="id">

                <el-select v-model="form.id" placeholder="请选择" @change="changeLing">

                    <el-option v-for="item in lingList" :key="‘ling‘ + item.id" :label="item.name" :value="item.id"></el-option>

                </el-select>

            </el-form-item>

            <el-form-item label="名称"><el-input v-model="form.name"></el-input></el-form-item>

            <el-form-item>

                <el-button type="primary" @click="onSubmit()">提交</el-button>

                <el-button @click="handleClose">取消</el-button>

                <el-button @click="deleHandle">删除</el-button>

            </el-form-item>

        </el-form>

    </div>

</template>

<script>

export default {

    data() {

        return {

            terrainUrl: ‘http://172.0.0.1:8888/terrain2/‘,

            imageryUrl: ‘http://172.0.0.1:8888/image/{z}/{x}/{y}.jpg‘,

            orgPos: { lon: 99.79602474, lat: 26.45798084, height: 300000 }, //7286.13}

            viewer: null//

            terrainProvider: ‘‘// 添加地形图数据

            imageryProvider: ‘‘// 图形数据

            form: {

                id: ‘‘,

                name: ‘‘,

                jd: ‘‘,

                wd: ‘‘,

                height: ‘‘

            },

            showForm: false,

            img: ‘/static/images/mark.png‘,

            lingList: []

        };

    },

    created() {

        this.queryMingTombsHandler();

    },

    mounted() {

        this.initViewer();

    },

    watch: {},

    methods: {

        // 获取数据

        queryMingTombsHandler() {

            this.lingList = [];

            this.$commonHttp(请求地址).then(res => {

                if (res.code == this.$codeState.OKCODE) {

                    let data = res.data;

                    this.lingList = data;

                    this.lingList.forEach(item => {

                        if (item.height) {

                            this.addEntities(item);

                        }

                    });

                    console.log(‘lingList‘this.lingList);

                }

            });

        },

        // 选择

        changeLing(val) {

            this.lingList.forEach(item => {

                if (item.id == val) {

                    this.form.name = item.name;

                    console.log(‘this.form‘this.form);

                }

            });

        },

        onSubmit() {

            this.$commonHttp(请求地址, {

                id: this.form.id,

                jd: this.form.jd,

                wd: this.form.wd,

                height: this.form.height

            }).then(res => {

                if (res.code == this.$codeState.OKCODE) {

                    this.addEntities(this.form);

                    this.showForm = false;

                    this.clearFromHandler();

                }

            });

        },

        handleClose() {

            this.showForm = false;

        },

        deleHandle() {

            this.$commonHttp(请求地址, {

                id: this.form.id

            }).then(res => {

                if (res.code == this.$codeState.OKCODE) {

                    this.showForm = false;

                    this.clearFromHandler();

                }

            });

        },

        // 将屏幕坐标转为经纬度

        lonLan(position) {

            let viewer = this.viewer;

            let Cesium = this.Cesium;

            var position1, cartographic1, lon, lat, height;

            let lonLanHei = {

                lon: ‘‘,

                lat: ‘‘,

                height: ‘‘

            };

            let ray = viewer.scene.camera.getPickRay(position);

            position1 = viewer.scene.globe.pick(ray, viewer.scene);

            cartographic1 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position1);

            let feature = viewer.scene.pick(position);

            if (feature == undefined) {

                lon = Cesium.Math.toDegrees(cartographic1.longitude);

                lat = Cesium.Math.toDegrees(cartographic1.latitude);

                height = cartographic1.height;

            else {

                let cartesian = viewer.scene.pickPosition(position);

                if (Cesium.defined(cartesian)) {

                    let cartographic = Cesium.Cartographic.fromCartesian(cartesian);

                    lon = Cesium.Math.toDegrees(cartographic.longitude);

                    lat = Cesium.Math.toDegrees(cartographic.latitude);

                    height = cartographic.height; //模型高度 } };//

                }

            }

            lonLanHei.lat = lat;

            lonLanHei.lon = lon;

            lonLanHei.height = height;

            return lonLanHei;

        },

        clearFromHandler() {

            this.form.id = ‘‘;

            this.form.jd = ‘‘;

            this.form.wd = ‘‘;

            this.form.name = ‘‘;

            this.form.height = ‘‘;

        },

        initViewer() {

            //添加地形图数据

            // this.terrainProvider = new this.Cesium.CesiumTerrainProvider({

            //   url: this.terrainUrl

            // });

            // 添加图片数据

            // this.imageryProvider = new this.Cesium.UrlTemplateImageryProvider({

            //   url: this.imageryUrl,

            //   tilingScheme: new this.Cesium.WebMercatorTilingScheme(),

            //   maximumLevel: 19

            // });

            let terrainModels = this.Cesium.createDefaultTerrainProviderViewModels();

            // 初始化

            this.viewer = new this.Cesium.Viewer(‘cesiumContainer‘, {

                // terrainProvider: this.terrainProvider,

                // imageryProvider: this.imageryProvider,

                infoBox: false//是否显示信息框--点击mark时,true有会

                geocoder: false// 查找位置,查到后会将镜头对准找到的地址

                homeButton: false// 视角返回初始位置

                sceneModePicker: false// 旋转视角的模式,有三种3D,2D,哥伦布视图

                //baseLayerPicker: false, // 图层选择器,选择要显示的地图服务和地形服务。

                navigationHelpButton: false// 导航帮助按钮,显示默认的地图控制帮助。

                fullscreenButton: true// 全屏按钮

                animation: false// 动画,控制试图动画的播放速度

                timeline: false// 时间线,指示当前时间,并允许用户跳到特定的时间。

                selectionIndicator: false// 禁止entity选中

                vrButton: true,

                scene3DOnly: false,

                sceneMode: 3

                //terrainProviderViewModels: terrainModels,

                //selectedTerrainProviderViewModel: terrainModels[1] // Select STK high-res terrain

            });

            this.viewer.scene.globe.depthTestAgainstTerrain = false;

            // cesium的label的清晰度

            this.viewer.scene.postProcessStages.fxaa.enabled = false;

            // 加载倾斜摄影数据

            this.loadTilesetHandler();

            // this.initCamera();

            //去掉地图标志

            this.viewer._cesiumWidget._creditContainer.style.display = ‘none‘;

            this.initMark();

        },

        // 加载倾斜摄影数据

        loadTilesetHandler() {

            let tileset = this.viewer.scene.primitives.add(

                new this.Cesium.Cesium3DTileset({

                    url: ‘http://172.18.49.225:65432/qxsy/tileset.json‘ //

                })

            );

            tileset.readyPromise

                .then(() => {

                    this.viewer.scene.primitives.lowerToBottom(tileset);

                    let boundingSphere = tileset.boundingSphere;

                    this.viewer.camera.viewBoundingSphere(boundingSphere, new this.Cesium.HeadingPitchRange(0.0, -0.5, boundingSphere.radius));

                    this.viewer.camera.lookAtTransform(this.Cesium.Matrix4.IDENTITY);

                })

                .otherwise(function(Aerror) {

                    throw error;

                });

        },

        initCamera() {

            let self = this;

            this.viewer.scene.camera.flyTo({

                destination: this.Cesium.Cartesian3.fromDegrees(this.orgPos.lon, this.orgPos.lat, this.orgPos.height), // 设置位置

                orientation: {

                    heading: this.Cesium.Math.toRadians(0.0), // 方向

                    pitch: this.Cesium.Math.toRadians(-90), // 倾斜角度

                    roll: this.Cesium.Math.toRadians(0)

                },

                complete: () => {

                    // 到达位置后执行的回调函数

                    this.viewer.scene.camera.flyTo({

                        destination: self.Cesium.Cartesian3.fromDegrees(self.orgPos.lon, self.orgPos.lat, self.orgPos.height),

                        orientation: {

                            heading: self.Cesium.Math.toRadians(0.0),

                            pitch: self.Cesium.Math.toRadians(-30),

                            roll: self.Cesium.Math.toRadians(0)

                        },

                        complete: () => {},

                        duration: 3

                    });

                },

                duration: 5 // 设置飞行持续时间,默认会根据距离来计算

            });

        },

        initMark() {

            const viewer = this.viewer;

            const Cesium = this.Cesium;

            // 左击进入360全景

            viewer.screenSpaceEventHandler.setInputAction(e => {

                viewer.selectedEntity = this.pickEntity(viewer, e.position);

                if (!viewer.selectedEntity) {

                    let obj = this.lonLan(e.position);

                    this.form.jd = obj.lon;

                    this.form.wd = obj.lat;

                    this.form.height = obj.height;

                    this.showForm = true;

                else {

                    this.$parent.detailInfo(viewer.selectedEntity._id);

                    console.log(‘进入360全景‘, viewer.selectedEntity._id);

                }

            }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

            // 双击entity,会放大视图,entity居中显示,且鼠标左键失去移动功能,鼠标滚轮失去作用

            this.viewer.screenSpaceEventHandler.setInputAction(() => {}, this.Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);

        },

        //双击操作

        pickAndTrackObject(e) {},

        // 设置广告牌label

        addEntities(item) {

            const viewer = this.viewer;

            const Cesium = this.Cesium;

            // label显示清晰度

            viewer.scene.postProcessStages.fxaa.enabled = false;

            let wyoming = viewer.entities.add({

                id: item.id,

                name: item.name,

                position: Cesium.Cartesian3.fromDegrees(Number(item.jd), Number(item.wd), Number(item.height) + 10),

                //立广告牌

                billboard: {

                    image: this.img,

                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,

                    show: true// default

                    width: 50, // default: undefined

                    height: 55

                },

                //字体标签样式

                label: {

                    text: item.name,

                    font:‘normal 32px MicroSoft YaHei‘,

                    scale:0.5,

                    color: Cesium.Color.WHITE,

                    style: Cesium.LabelStyle.FILL_AND_OUTLINE,

                    showBackground: true,

                    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,

                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,

                    // distanceDisplayCondition: new Cesium.DistanceDisplayCondition(10.0, 8000.0),

                    // disableDepthTestDistance: 100.0,

                    pixelOffset: new Cesium.Cartesian2(40, -20) // 调整偏移位置

                }

            });

        },

        // 拾取实体

        pickEntity(viewer, position) {

            const Cesium = this.Cesium;

            let picked = viewer.scene.pick(position);

            if (picked) {

                let id = Cesium.defaultValue(picked.id, picked.primitive.id);

                if (id instanceof Cesium.Entity) {

                    return id;

                }

            }

            return undefined;

        }

    }

};

</script>

<style scoped lang="less">

.cesium-wrap {

    width: 100%;

    height: 100%;

    display: inline-block;

}

#cesiumContainer {

    width: 100%;

    height: 100%;

    position: absolute;

    margin: 0;

    padding: 0;

    overflow: hidden;

}

.cesiumForm {

    width: 300px;

    position: absolute;

    left: 50%;

    top: 50%;

    z-index: 10;

    #ccc;

    padding: 10px;

    transform: translate(-50%, -50%);

}

</style>

  原文 https://www.cnblogs.com/langqq/p/10873708.html

原文地址:https://www.cnblogs.com/mazhenyu/p/12550885.html

时间: 2024-11-09 07:40:37

vue cesium 加载倾斜摄影数据并在上面添加自定义标注【转】的相关文章

Cesium加载各类数据总结

接触到的加载数据类型:源地图.shp.Geojson.png.wms.地形底图 1.Cesium加载各类源地图(在线的影像服务) #此类加载的本质在于 new Cesium.ImageryProvider() Api defination:“Provides imagery to be displayed on the surface of an ellipsoid. This type describes an interface and is not intended to be insta

cesium 加载倾斜摄影模型(这里有一坑)

代码如下: 1 // Construct the default list of terrain sources. 2 var terrainModels = Cesium.createDefaultTerrainProviderViewModels(); 3 4 // Construct the viewer with just what we need for this base application 5 var viewer = new Cesium.Viewer('cesiumCont

cesium加载DEM数据

参考:https://www.jianshu.com/p/62d6f03f44e3 1.目前一般都是win7-64位系统,从tif数据转成terrain,最好在win7-32位系统上安装后做转换:尝试在win7-64位电脑上安装32位的python,arcmap被装坏掉 2.IIS上发布terrain数据 首先需要解决跨域问题,做cors配置: 其次需要在数据目录下放web.config,内容如下: <?xml version="1.0" encoding="UTF-8

ceisum_加载倾斜摄影模型

osgb转换为3Dtiles格式(使用工具转换) 然后加载到cesium中(加载代码见下,可以控制模型高度) var offset = function(height,tileset) { console.log(height); height = Number(height); if (isNaN(height)) { return; } var cartographic = Cesium.Cartographic.fromCartesian(tileset.boundingSphere.ce

Vue动态加载异步组件

背景: 目前我们项目都是按组件划分的,然后各个组件之间封装成产品.目前都是采用iframe直接嵌套页面.项目中我们还是会碰到一些通用的组件跟业务之间有通信,这种情况下iframe并不是最好的选择,iframe存在跨域的问题,当然是postMessage还是可以通信的,但也并非是最好的.目前有这么一个场景:门户需要制作通用的首页和数据概览页面,首页和数据概览页面通过小部件来自由拼接.业务组件在制作的时候只需要提供各个模块小部件的url就可以了,可是如果小部件之间还存在联系呢?那么iframe是不好

ext combobox动态加载数据库数据

前台: var provinceStore = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: basePath + "/stationManage/station_getProvinceJSON.action" }), reader: new Ext.data.JsonReader( { root: "" }, ["PROVINCEID", "PROVINCENAME

JQuery跨域加载JSON数据或HTML。

前提:有时候需要在网页上,加载另一个网站上的数据.或者加载另一个网站上的一个页面.Js的Ajax请求不具备跨域功能,可以使用JQuery来实现. 网页端JS代码: $(function () { $.ajax({ type: "get", async: false, url: "http://localhost:13964/getpage.ashx?callback=?",//服务端URL,该URL返回一段JS数据.如需返回HTML,只需把HTML组织成JSON即可

hive加载json数据解决方案

hive官方并不支持json格式的数据加载,默认支持csv格式文件加载,如何在不依赖外部jar包的情况下实现json数据格式解析,本编博客着重介绍此问题解决方案 首先创建元数据表: create EXTERNAL table access_log (content string) row format delimited fields terminated by '\t' STORED AS INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInpu

SQLLoader8(加载的数据中有换行符处理方法)

SQLLDR加载的数据中有换行符处理方法1.创建测试表: CREATE TABLE MANAGER( MGRNO NUMBER, MNAME VARCHAR2(30), JOB VARCHAR2(30), REMARK VARCHAR2(1000) ); 2.创建控制文件我们可以通过控制文件,在数据加载前处理remark列的数据,将用户指定的"\n"字符替换为chr(10),即标准换行符,创建控制文件如下: LOAD DATA INFILE 'D:\testSqlLoader\ldr_