123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <template>
- <!-- <div class='Map' @click="cutVr('fd720_WoDGV0K2r',13)"> -->
- <div class="Map">
- <div id="mars3dContainer" class="mars3d-container"></div>
- </div>
- </template>
- <script>
- //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
- //例如:import 《组件名称》 from '《组件路径》';
- //引入cesium基础库
- // import "mars3d-cesium/Build/Cesium/Widgets/widgets.css";
- // import * as Cesium from "mars3d-cesium";
- //导入mars3d主库
- import "mars3d/dist/mars3d.css";
- import * as mars3d from "mars3d";
- export default {
- //import引入的组件需要注入到对象中才能使用
- components: {},
- data() {
- //这里存放数据
- return {
- // 地图实例
- // map: null,
- };
- },
- //监听属性 类似于data概念
- computed: {},
- //监控data中的数据变化
- watch: {},
- //方法集合
- methods: {
- // 初始化地图
- async initMap() {
- // 读取 config.json 配置文件
- const json = await mars3d.Util.fetchJson({ url: "config/config.json" });
- console.log("读取 config.json 配置文件完成", json); // 打印测试信息
- // 创建三维地球场景
- const mapOptions = json.map3d;
- let map = new mars3d.Map("mars3dContainer", mapOptions);
- // 打印测试信息
- // console.log("mars3d的Map主对象构造完成", this.map);
- // console.log("其中Cesium原生的Cesium.Viewer为", this.map.viewer);
- return map;
- },
- // 倾斜模型加载
- loadModel(_map) {
- const modelLayer = new mars3d.layer.TilesetLayer({
- name: "雨花台模型",
- url: "https://testgis.4dage.com/yuhuatai1021-qp/tileset.json",
- maximumMemoryUsage: 2048,
- position: { alt: -290 },
- preloadFlightDestinations: true,
- flyTo: false,
- });
- _map.addLayer(modelLayer);
- },
- drawLabel(_layer) {
- const graphic = new mars3d.graphic.DivGraphic({
- position: [118.775298, 31.999126, 80.5],
- style: {
- html: `<div
- style="
- width: 316px;
- height: 174px;
- display: flex;
- justify-content: center;
- align-items: flex-start;
- cursor:pointer;
- "
- >
- <div
- style="
- position: absolute;
- margin-left: 25px;
- width: 190px;
- height: 70px;
- line-height: 70px;
- text-align: center;
- color: #fff;
- font-size: 20px;
- font-weight: bold;
- "
- >
- 雨花台烈士纪念馆
- </div>
- <div><img src="/YHT/Qjkk/MapBs.png"/></div>
- </div>`,
- horizontalOrigin: mars3d.Cesium.HorizontalOrigin.CENTER,
- verticalOrigin: mars3d.Cesium.VerticalOrigin.BOTTOM,
- // distanceDisplayCondition: new mars3d.Cesium.DistanceDisplayCondition(0, 30000), // 按视距距离显示
- // scaleByDistance: new mars3d.Cesium.NearFarScalar(100, 1, 1000, 0.5),
- scale: 0.1,
- clampToGround: false,
- },
- });
- graphic.on(mars3d.EventType.click, () => {
- this.cutVr("fd720_WoDGV0K2r", 13);
- });
- _layer.addGraphic(graphic);
- },
- cutVr(code, index) {
- this.$emit("mapCutVr", code, index);
- },
- },
- //生命周期 - 创建完成(可以访问当前this实例)
- created() {},
- //生命周期 - 挂载完成(可以访问DOM元素)
- mounted() {
- // 初始化地图实例
- this.initMap().then(
- (map) => {
- // 加载模型
- this.loadModel(map);
- // 加载标签
- let graphicLayer = new mars3d.layer.GraphicLayer();
- map.addLayer(graphicLayer);
- this.drawLabel(graphicLayer);
- map.setCameraView({
- lat: 31.99314,
- lng: 118.776577,
- alt: 656,
- heading: 350,
- pitch: -43,
- });
- },
- (error) => {
- console.log("地图初始化失败", error);
- }
- );
- },
- beforeCreate() {}, //生命周期 - 创建之前
- beforeMount() {}, //生命周期 - 挂载之前
- beforeUpdate() {}, //生命周期 - 更新之前
- updated() {}, //生命周期 - 更新之后
- beforeDestroy() {}, //生命周期 - 销毁之前
- destroyed() {}, //生命周期 - 销毁完成
- activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
- };
- </script>
- <style lang='less' scoped>
- .Map {
- position: absolute;
- top: 0;
- left: 0;
- z-index: 98;
- width: 100%;
- height: 100%;
- // background-color: aqua;
- }
- #mars3dContainer {
- width: 100%;
- height: 100%;
- position: absolute;
- top: 0px;
- left: 0px;
- }
- /deep/.mars3d-locationbar {
- background-color: #000 !important;
- z-index: 0 !important;
- }
- </style>
|