cesium自定义弹框

token记得换成您自己的!!! 

申请cesium的token 官网【Cesium: The Platform for 3D Geospatial

pickEllipsoid在加载地形的情况下有一定误差,地形凹凸程度越大,误差越大。 

 pickPosition在depthTestAgainstTerrain = false时只能在3DTile上获取准确位置,当depthTestAgainstTerrain = true时, 在3DTile和底图上均能获取准确位置

viewer.scene.globe.depthTestAgainstTerrain = true; // 开启地形深度检测

// pickEllipsoid在加载地形的情况下有一定误差,地形凹凸程度越大,误差越大。
// pickPosition在depthTestAgainstTerrain = false时只能在3DTile上获取准确位置,当depthTestAgainstTerrain = true时,
// 在3DTile和底图上均能获取准确位置
<template>

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

  <!-- <div id="infoboxs" :style="qnameclass" class="qnamebox">{{ qname }}</div> -->
  <!-- <div class="btnbox">
    <div class="btnboxel">
      <el-button class="btnel" v-for="item in pointData2" :key="item.modelId" @click="showBubble(item)">{{ item.name
        }}</el-button>
    </div>
  </div> -->


</template>
<script setup lang='ts'>
import * as Cesium from "cesium";
import $ from 'jquery'
import { fa } from "element-plus/es/locales.mjs";
import { onMounted, reactive, ref, computed, nextTick } from "vue";
import { it } from "node:test";
// 地图实例
let viewer: any;

let tileset; //设置一个变量来存放通过3DTiles创建的模型
let handler
let selectedFeature
const selected = {
  feature: undefined,
  originalColor: new Cesium.Color(),
};
let qname = ref()
let qnameclass = reactive({
  top: '',
  left: '',
})

let valshow


let infos: any = reactive({
  pups: []
})
let infoBox1 = ref()
 
onMounted(() => {

  // 初始化Cesium并创建viewer
  Cesium.Ion.defaultAccessToken =
    "换成自己的token";
  viewer = new Cesium.Viewer("cesiumContainer", {
    infoBox: true, // 禁用沙箱,解决控制台报错
    selectionIndicator: false, //选择指示器
    timeline: false, // 时间轴
    animation: false, // 动画小组件
    // geocoder: false, // 地理编码(搜索)组件
    homeButton: false, // 首页,点击之后将视图跳转到默认视角
    sceneModePicker: false, // 投影方式,切换2D、3D 和 Columbus View (CV) 模式。
    baseLayerPicker: false, // 底图组件,选择三维数字地球的底图(imagery and terrain)。
    navigationHelpButton: false, // 帮助按钮
    fullscreenButton: false, // 全屏按钮

    imageryProvider: new Cesium.ArcGisMapServerImageryProvider({
      url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
      // enablePickFeatures: false,
    }),
    // terrainProvider: new Cesium.CesiumTerrainProvider({
    //   url: "http://data.marsgis.cn/terrain",
    // }),
    scene3DOnly: true, // 每个几何实例将只能以3D渲染以节省GPU内存
    sceneMode: 3, // 初始场景模式 1 2D模式 2 2D循环模式 3 3D模式  Cesium.SceneMode
  });
  viewer.imageryLayers.addImageryProvider(
    new Cesium.WebMapTileServiceImageryProvider({
      url: "http://t0.tianditu.gov.cn/cia_w/wmts?tk=2d58d1852b0b28db058bbe353a22b91b",
      layer: "cia",
      style: "default",
      tileMatrixSetID: "w",
      format: "tiles",
      maximumLevel: 18,
    })
  );
  viewer._cesiumWidget._creditContainer.style.display = "none"; //隐藏logo版权
  viewer.scene.globe.depthTestAgainstTerrain = true; // 开启地形深度检测
  let destination = Cesium.Cartesian3.fromDegrees(117.598276295, 24.21475226, 80); // 北京天安门广场的经纬度坐标及高度
  viewer.camera.flyTo({
    destination: destination,
    duration: 2, // 飞行动画持续时间(单位:秒)
    orientation: {
      heading: Cesium.Math.toRadians(-25), // 方向 y 左右摇头
      pitch: Cesium.Math.toRadians(-20), // 倾斜角度 x  上下点头  -90看地面  0看前方  90看天上
      roll: 0, //z 歪头看
    }
  });
  handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
  // getasdM()
  //   const layer = viewer.imageryLayers.get(0);
  // viewer.scene.globe.baseColor = new Cesium.Color(0.0, 0.0, 0.0, 0); // 把地球背景色透明
  // layer.alpha = 0.8;
  // viewer.scene.globe.translucency.backFaceAlpha = 0.5; // 应用于地球背面的恒定半透明度
  // viewer.scene.globe.translucency.enabled = true; // 开启地表透明


  // window._viewer=viewer


  getRightClick()

});




// 每帧都要更新标签位置
function getBubble() {
  viewer.scene.postRender.addEventListener(() => {
    // console.log("气泡",infos.pups)
    infos.pups.forEach((item: any) => {


      let worldcoodinate = Cesium.Cartesian3.fromRadians(item.position.longitude, item.position.latitude, item.position.height)
      //  let  screenpops=Cesium.SceneTransforms.wgs84ToWindowCoordinates(viewer.scene,worldcoodinate)
      let screenpops = Cesium.SceneTransforms.wgs84ToWindowCoordinates(viewer.scene, worldcoodinate)
      let pupdiv: any = document.getElementById(item.id)

      if (pupdiv && screenpops) {
        //  let infoBox1= new Cesium.InfoBox(document.getElementById(item.id))
        pupdiv.style.top = screenpops.y - 80 + 'px'
        pupdiv.style.left = screenpops.x + 'px'
        let pupdivA: any = document.getElementById(item.id + 'A')
        console.log("pupdivA.height:", pupdivA.style.height)
        //  pupdivA.style.top = screenpops.y-80+25 + 'px'
        //  pupdivA.style.left = screenpops.x-20+ 'px'
        // pupdiv.style.sheet.addRule('#'+'::after', 'content: "";position:absolute; width: 0;height: 0; top: 25px;left: -35px;border-top: 10px solid transparent;border-bottom: 10px solid transparent;border-right: 35px solid #42b983; transform: skewY(-50deg)');
      }

    })
  })
}

// 右击事件
function getRightClick() {
  handler.setInputAction(function (event) {
    // 此处点击模型
    // const pickedObject = viewer.scene.pick(event.position);
    let windowpos = viewer.camera.getPickRay(event.position)


    // 判断是否点击地球
    if (windowpos) {
      // pickEllipsoid在加载地形的情况下有一定误差,地形凹凸程度越大,误差越大。
      // pickPosition在depthTestAgainstTerrain = false时只能在3DTile上获取准确位置,当depthTestAgainstTerrain = true时,
      // 在3DTile和底图上均能获取准确位置

      // let cartesian2 = viewer.camera.pickEllipsoid(event.position, viewer.scene.globe.ellipsoid);
      var cartesian2 = viewer.scene.pickPosition(event.position)
      //  console.log("cartesian",cartesian)
      let carto2 = viewer.scene.globe.ellipsoid.cartesianToCartographic(cartesian2)



      // if (Cesium.defined(pickedObject)) {
      //   console.log("右击事件");
      //   const id = pickedObject.getProperty("id");
      //   const name = pickedObject.getProperty("name");
      //   let params = { id: buildUUID(), position: carto2, modelId: id, name }
      //   ceastPup(params)
      //   // const entity = pickedObject.id;
      //   // if (Cesium.defined(entity)) {
      //   //   console.log("右击事件", entity);
      //   // }
      // }
      //  const id = pickedObject.getProperty("id");
      //   const name = pickedObject.getProperty("name");
      var randomNumber = Math.floor(Math.random() * 10+1);
      let params = { id: buildUUID(), position: carto2, modelId: buildUUID(), name: getRandomChineseWord(randomNumber) }
      ceastPup(params)
    }

  }, Cesium.ScreenSpaceEventType.RIGHT_CLICK)
}
function getRandomChineseWord(num) {
  let arr: any = []
  for (var i = 0; i < num; i++) {
    var _rsl = "";
    // 40869 - 19968  40870 - 19968
    var _randomUniCode = Math.floor(Math.random() * (40870 - 19968) + 19968).toString(16);
    eval("_rsl=" + '"\\u' + _randomUniCode + '"');
    arr.push(_rsl)
  }
  let chinese = arr.join("")
  return chinese;
}


// 创建气泡
function ceastPup(param: any) {
  let object: any = infos.pups.find(item => { return item.id == param.id })

  if (!object) {

    object = new Object()
    object.id = param.id
    object.position = param.position
    infos.pups.push(object)
    let divmark = `<div id='${param.id}'  style="position:absolute;width:340px;background-color:#42b983;border-radius:5px;color:#fff; 
    " >
      <div id='${param.id}A' style=" position: absolute;
            width: 10px;
            height: 40px;
            top: 35px;
            left: -20px;
            border-top: 0px solid transparent;
            border-bottom: 50px solid transparent;
            border-right: 12px solid #42b983;
            border-left: 10px solid transparent;
            transform: skewY(-50deg);"></div>
          <div style="margin-left:20px;margin-top:10px;margin-bottom:10px;margin-right:10px">
            <span>Id:${param.modelId}</span>
          <span>${param.name}</span></div>
      </div>`
    // let divmark = "<div id='"+ param.id +"'  style='position:absolute;width:200px;height:50px;background-color:#42b983;border-radius:5px;' ></div>"

    //  console.log("divmark",divmark)
    // var style = document.createElement("style");
    // document.head.appendChild(style);
    // let sheet: any = style.sheet;
    // console.log("sheet",sheet)
    // // //兼容IE浏览器
    // sheet.addRule('#'+param.id+'::after', 'content: "";position:absolute; width: 0;height: 0; top: 25px;left: -35px;border-top: 10px solid transparent;border-bottom: 10px solid transparent;border-right: 35px solid #42b983; transform: skewY(-50deg)');

    //       $('<style>#'+param.id+'::after{content: "";position:absolute; width: 0;height: 0; top: 25px;left: -35px;border-top: 10px solid transparent;border-bottom: 10px solid transparent;border-right: 35px solid #42b983; transform: skewY(-50deg);}</style>').appendTo('head');


    $('#' + viewer._container.id).append(divmark)

    getBubble()
  }


}





// 随机数字
const buildUUID = () => {
  const hexList: string[] = [];
  for (let i = 0; i <= 15; i++) {
    hexList[i] = i.toString(16);
  }
  let uuid = "";
  for (let i = 1; i <= 36; i++) {
    if (i === 9 || i === 14 || i === 19 || i === 24) {
      uuid += "-";
    } else if (i === 15) {
      uuid += 4;
    } else if (i === 20) {
      uuid += hexList[(Math.random() * 4) | 8];
    } else {
      uuid += hexList[(Math.random() * 16) | 0];
    }
  }
  return uuid.replace(/-/g, "");
};







// 加载模型
const getasdM = () => {

  try {
    tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
      url: '../../public/asd/tileset.json',
      // type: "3dtiles",

      maximumScreenSpaceError: 2, //最大的屏幕空间误差
      show: true,
      modelMatrix: Cesium.Matrix4.fromArray([0.9920306777526413, 0.035672572522648105, 0.12084122627336652, 0, -0.0052179803729043295, 0.9698924230752208, -0.24347784363696146, 0, -0.12588847079245385, 0.24090694309399502, 0.9623491765937375, 0, -1232.2319169966504, 2358.065217874944, 6764.694671697915, 1]),
    }))
    viewer.flyTo(tileset)

    // viewer.extend(Cesium.viewerCesium3DTilesInspectorMixin); // 开启3D Tiles检测器





  } catch (error) {
    console.log(`Error loading tileset: ${error}`);
  }


}





</script>
<style lang="scss" scoped>
/*--------------------------消息框Start---------------------------*/
.messBox {
  display: none;
  color: rgb(255, 255, 255);
}

.popup {
  position: absolute;
  z-index: 100;
}

.closeButton {
  position: absolute;
  top: 0;
  right: 0;
  padding: 4px 4px 0 0;
  text-align: center;
  font: 25px/25px Tahoma, Verdana, sans-serif;
  color: rgb(255, 255, 255);
  text-decoration: none;
  font-weight: bold;
  background: transparent;
}

.contentWrapper {
  max-height: 500px;
  overflow-y: auto;
  min-height: 180px;
  width: 300px;
  padding: 1px;
  text-align: left;
  border-radius: 5px;
  background-color: #729ea5;
}

.content {
  margin: 5px 20px;
  line-height: 1.4;
}

.content div {
  text-align: center;
  font-size: 18px;
}

.content table {
  margin-top: 15px;
}

.content table tr {
  height: 25px;
}

/*--------------------------消息框END---------------------------*/
</style>
<style scoped>
.mesaggebox {
  /* position: absolute;
  left: 50%;
  top: 50%; */
}

/* .row-4{
            margin: 40px auto;
            width: 200px;
            height: 50px;
            color: #fff;
            line-height: 50px;
            text-align: center;
            position: relative;
            background: teal;
            border-radius: 5px;
        }
        .row-4::after{
            content: '';
            position: absolute;
            width: 0;
            height: 0;
             top: 25px;
            right: -20px;
            border-top: 10px solid transparent;
            border-bottom: 10px solid transparent;
            border-left: 20px solid teal;
            transform: skewY(50deg);
         
        } */
.btnbox {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 400px;

  .btnboxel {
    display: flex;
    flex-wrap: wrap;
  }

  .btnel {
    margin-top: 10px;
    margin-bottom: 10px;
    width: 110px;
    /* background: blue; */
  }
}

.qnamebox {
  position: absolute;
  border: 1px solid #ccc;
  background: #4cb872;
  border-radius: 5px;
  padding: 10px;
  color: #fff;
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/761474.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

3-数据提取方法1(json)(6节课学会爬虫)

3-数据提取方法1&#xff08;json&#xff09;&#xff08;6节课学会爬虫&#xff09; 1&#xff0c;Json2&#xff0c;哪里会返回json的数据&#xff08;值得尝试的操作&#xff09;3&#xff0c;Json字符串转换成字典或python类型进行数据提取&#xff08;1&#xff09;Json.…

人脸特征68点识别 C++

1、加载一张图片 main函数&#xff1a; cv::Mat img cv::imread("5.jpg");vector<Point2f> points_vec dectectFace68(img);2、人脸68特征识别函数 在这里vector<Point2f> dectectFace68(Mat src) {vector<Point2f> points_vec;int* pResults …

从0到1搭建微服务框架

目录 1.技术栈&#xff1a; 2.模块介绍: 3.关键代码讲解 3.1基础公共模块(common)依赖&#xff1a; 3.3授权模块(auth)依赖: 3.4授权模块核心配置类(AuthrizatonConfig): 3.4 SecurityConfig.java 3.5 bootstrap的核心配置文件(其他服务配置类似这个)&#xff1a; 3.6n…

视频编解码从H.264到H.266:浅析GB28181安防视频汇聚EasyCVR视频压缩技术

随着信息技术的飞速发展&#xff0c;视频编解码技术也在不断革新&#xff0c;以适应高清、超高清甚至8K视频时代的到来。视频编解码技术作为数字多媒体领域的核心技术之一&#xff0c;也在不断地演进和革新。从早期的H.261到现在的H.265、H.266&#xff0c;每一次技术的升级都极…

便携式气象站:科技助力,气象观测的新选择

在气象观测领域&#xff0c;便携式气象站不仅安装方便、操作简单&#xff0c;而且功能齐全、性能稳定&#xff0c;为气象观测带来了极大的便利。 首先&#xff0c;便携式气象站的便携性&#xff0c;与传统的气象站相比&#xff0c;它不需要复杂的安装过程和固定的设备基础&…

收银系统源码-千呼新零售2.0【移动管理端】

千呼新零售2.0系统是零售行业连锁店一体化收银系统&#xff0c;包括线下收银线上商城连锁店管理ERP管理商品管理供应商管理会员营销等功能为一体&#xff0c;线上线下数据全部打通。 适用于商超、便利店、水果、生鲜、母婴、服装、零食、百货、宠物等连锁店使用。 详细介绍请…

昂首资本实例使用价格行为策略,交易翻倍一点都不难

交易翻倍难吗&#xff1f;当Anzo Capital昂首资本使用价格行为策略进行交易时&#xff0c;发现一点都不难&#xff0c;以下是使用价格行为策略的实例分享&#xff1a; 1. 在初次交易信号出现时&#xff0c;推荐在1.00429价位入场&#xff0c;将止损设于1.04399&#xff0c;止盈…

微信小程序的在线客服系统源码 附带完整的源代码包以及搭建部署教程

系统概述 微信小程序的在线客服系统源码是一套专门为微信小程序开发的客服解决方案。它通过与微信小程序的紧密集成&#xff0c;为用户提供了便捷、高效的客服沟通渠道。该系统源码采用先进的技术架构&#xff0c;具备良好的稳定性和扩展性&#xff0c;能够满足不同规模企业的…

【数据结构】C语言实现二叉树的基本操作——二叉树的层次遍历、求深度、求结点数……

C语言实现二叉树的基本操作 导读一、层次遍历1.1 算法思路1.2 算法实现1.2.1 存储结构的选择1.2.2 函数的三要素1.2.3 函数的实现 1.3 小结 二、求二叉树的深度2.1 层序遍历2.2 分治思想——递归 三、 求二叉树的结点数3.1 求二叉树的结点总数3.1.1 层序遍历3.1.2 分治思想——…

Cherno 游戏引擎笔记 (45~60)

有几个部分的笔记以图片形式呈现&#xff08;如果没找到文本可以查看是否遗漏了图片笔记&#xff09; My Github REPO(GitHub - JJJJJJJustin/Nut: The game_engine which learned from Cherno) 源码笔记&#xff0c;希望帮到你 :-} ---Shader Library&#xff08;着色器库&…

[机器学习]-4 Transformer介绍和ChatGPT本质

Transformer Transformer是由Vaswani等人在2017年提出的一种深度学习模型架构&#xff0c;最初用于自然语言处理&#xff08;NLP&#xff09;任务&#xff0c;特别是机器翻译。Transformer通过自注意机制和完全基于注意力的架构&#xff0c;核心思想是通过注意力来捕捉输入序列…

什么是接口测试,我们如何实现接口测试?

1. 什么是接口测试 顾名思义&#xff0c;接口测试是对系统或组件之间的接口进行测试&#xff0c;主要是校验数据的交换&#xff0c;传递和控制管理过程&#xff0c;以及相互逻辑依赖关系。其中接口协议分为HTTP,WebService,Dubbo,Thrift,Socket等类型&#xff0c;测试类型又主…

oracle plsql如何debug触发器

进入测试窗口 Test Window 写以下代码 declarebegininsert into tableA values();end; 如果tableA有insert触发器&#xff0c;插入数据的时候&#xff0c;就能进入触发器的代码里面

【区块链+基础设施】区块链服务网络 BSN | FISCO BCOS应用案例

BSN&#xff08;Blockchain-based Service Network&#xff0c;区块链服务网络&#xff09;是一个跨云服务、跨门户、跨底层框架&#xff0c;用于部 署和运行各类区块链应用的全球性基础设施网络&#xff0c;旨在为开发者提供低成本和技术互通的区块链一站式服务。 2019 年 12…

Android LayoutInflater 深度解析

在 Android 开发中&#xff0c;LayoutInflater 是一个非常重要的工具。它允许我们从 XML 布局文件中动态地创建 View 对象&#xff0c;从而使得 UI 的创建和管理更加灵活。本文将深入解析 android.view.LayoutInflater&#xff0c;包括它的基本用法、常见问题以及高级用法。 什…

stm32学习笔记---DMA直接存储器存取(代码部分)DMA数据转运/DMA+AD多通道

目录 第一个代码&#xff1a;DMA数据转运 扩展知识 DMA的配置步骤 DMA的库函数 DMA_DeInit DMA初始化和DMA结构体初始化函数 DMA_Cmd DMA_ITConfig DMA_SetCurrDataCounter DMA_GetCurrDataCounter 四个获取标志位状态函数 代码实现 MyDMA.c 第一步&#xff0c;开…

网站提示不安全怎么办

当您访问一个网站时&#xff0c;如果浏览器提示该网站不安全&#xff0c;这通常意味着以下几个问题之一&#xff0c;以及相应的解决办法&#xff1a; 一、未启用HTTPS协议&#xff1a; 解决方法&#xff1a;确保网站启用了HTTPS协议。这意味着您需要为您的网站部署一个有效的…

鸿蒙:this传递参数到子组件中无法实现

this指代当前组件的某个变量&#xff0c;当把这个变量当作参数传递给子组件时&#xff0c;子组件中没有这个变量&#xff0c;属于使用不了这个变量 解决方法&#xff1a;在变量后面加.bind(this)将当前组件的变量一起绑定过去

电脑ip地址在哪里看?3个方法全解析,找到地址不迷路

ip地址&#xff0c;就像网络世界中的身份证&#xff0c;是每个设备在网络上的唯一标识。无论是浏览网页、在线聊天还是远程办公&#xff0c;都离不开它的指引。那么&#xff0c;电脑ip地址在哪里看&#xff1f;别担心&#xff0c;本文将带你踏上寻找ip地址的冒险之旅&#xff0…

#HDC2024 心得分享#主题演讲学习-加入鸿蒙生态正当时

一、主题演讲学习心得 通过本次主题演讲的聆听与学习&#xff0c;我们在猜出中和不太确定的相关内容纷纷呈现。比如鸿蒙内核与HarmonyOS Next获得行业内最高等级的安全认证&#xff1b;盘古大模型、小艺智能体、意图理解与分发框架等构筑的AI、AIGC能力对HarmonyOS Next及原生…
最新文章