当前位置: 首页 > wzjs >正文

优质手机网站建设哪家好精准网络推广

优质手机网站建设哪家好,精准网络推广,无锡网站建设和,模板做网站本文是vuets实现的,想要转为react,只需要修改以下几部分内容 1. 将 reactive 定义的数据直接改写为 let定义 2. 将 watch 监听的内容改成对应的监听写法 3. 将 ref 定义的字段改写为对应的写法 该模块实现的功能: 通过点击鹰眼图的某一位置&#xf…
本文是vue+ts实现的,想要转为react,只需要修改以下几部分内容

1. 将 reactive 定义的数据直接改写为 let定义

2. 将 watch 监听的内容改成对应的监听写法

3. 将 ref 定义的字段改写为对应的写法

该模块实现的功能

通过点击鹰眼图的某一位置,对应主地图切换到对应的经纬度位置

在主地图中拖拽,鹰眼图中的点也跟着变化

实现鹰眼图的原理

1. 要获取左上角和右下角的经纬度,用来确定当前区域的一个范围。

2. 要通过点击鹰眼图,将坐标转换为主地图中的经纬度。通过公式计算

3. 在主地图中拖拽,将经纬度转换为鹰眼图中的坐标,来实现点的对应

1.获取主地图区域的左上角,右下角的经纬度

经纬度是WGS84格式


const coord1 = reactive({latitude: 29.67098,longitude: 106.48518,
});
const coord2 = reactive({latitude: 29.66891,longitude: 106.48912,
});

2.计算经纬度的差值,算一下差值是几比几,决定鹰眼图的大小

// 差值
const difference = reactive({longitude: Math.abs(coord1.longitude - coord2.longitude),latitude: Math.abs(coord1.latitude - coord2.latitude),
});

3. 创建鹰眼图,鹰眼图的宽高要根据经纬度的宽高比来决定

<div id="eye"><div class="dot" id="move-dot"></div>
</div>

4. 坐标转经纬度,经纬度转坐标有一个公式

公式解释:

我们用的经纬度是左上角的经纬度,因为eye的div左上角对应的是坐标系的(0,0)

求的主地图的经度 = eye点击的x坐标 * (经度的差值 / eye的高度) + 左上角的经度

5. 监听eye的点击函数

onMounted(() => {// createMainCesium(); // 1.创建主地图,省略handlerMoveDot(); // 2.定义鼠标移动事件
});// 创建点击函数
function handlerMoveDot() {const eyeBox = document.getElementById("eye");const dot = document.getElementById("move-dot");if (eyeBox && dot) {eyeBox.addEventListener("click", (e) => {moveX.value = e.offsetX;moveY.value = e.offsetY;dot.style.left = moveX.value + "px";dot.style.top = moveY.value + "px";});}
}// dot的变化更新主地图的经纬度
watch([moveX, moveY], () => {const longitude =moveX.value * (difference.longitude / 164) + coord1.longitude;const latitude = coord1.latitude - moveY.value * (difference.latitude / 173);const position = Cesium.Cartesian3.fromDegrees(longitude, latitude, 500);viewerRef.value.camera.flyTo({destination: position,duration: 2.0,// 相机的角度,自行调整,不需要先注释orientation: {heading: 2 * Math.PI,pitch: -1 * (Math.PI / 6),roll: 2 * Math.PI,},});
});

 截至目前为止,实现了坐标转经纬度

接下来,实现 经纬度转坐标

1. 页面一进来,计算主地图左上角、右下角的经纬度中心,来显示在鹰眼图对应的位置

这段代码放到渲染完viewer之后

 const cartographic = getCartographicCenter();dotInitPosition(cartographic);
// 初始化页面是找经纬度的中心
function getCartographicCenter() {const centerLongitude = (coord1.longitude + coord2.longitude) / 2;const centerLatitude = (coord1.latitude + coord2.latitude) / 2;return {longitude: centerLongitude,latitude: centerLatitude,};
}// 笛卡尔坐标转换屏幕坐标,用作dot的初始位置
function dotInitPosition(cartesian: ScreenPosition) {let x, y;x = (cartesian.longitude - coord1.longitude) * (164 / difference.longitude);y = (coord1.latitude - cartesian.latitude) * (173 / difference.latitude);const dot = document.getElementById("move-dot");if (dot) {dot.style.left = x + "px";dot.style.top = y + "px";}
}

2. 监听在主地图上移动的函数

onMounted(() => {handlerMoveView(); // 3.定义地图的鼠标移动事件
});// 监听地图的移动事件
function handlerMoveView() {const viewer = viewerRef.value;const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);handler.setInputAction((e) => {// 这里如果获取不到值,百度一下,换其他方式拿经纬度 const ray = viewer.camera.getPickRay(e.position);if (ray?.origin) {const cartographic = Cesium.Ellipsoid.WGS84.cartesianToCartographic(ray?.origin,);const longitude = Cesium.Math.toDegrees(cartographic.longitude);const latitude = Cesium.Math.toDegrees(cartographic.latitude);// 计算公式还用初始化的那个就行dotInitPosition({ longitude, latitude });}}, Cesium.ScreenSpaceEventType.LEFT_UP);
}

http://www.dtcms.com/wzjs/471992.html

相关文章:

  • 免费培训学校网站源码逆冬黑帽seo培训
  • 多用户商城系统哪家好鸡西网站seo
  • 怎么做一个网站线上培训机构
  • 网站建设的关键问题小红书代运营
  • wordpress切换 音乐给你一个网站seo如何做
  • 京东商城官方旗舰店专业seo网络营销公司
  • 做那网站好网络营销教案ppt
  • 自做闪图网站推广衣服的软文
  • 婚纱摄影网站开题报告苏州网站建设
  • 网站建设方案设计今日热点事件
  • 微信小程序游戏制作平台广州seo网络营销培训
  • 沈阳品牌设计公司南昌seo搜索优化
  • 做网站二级页面的如何创建网站站点
  • 在网站建设中什么用于搭建页面结构网站关键词收录查询
  • 网站模板定制今日国内重大新闻
  • 短视频网站php源码免费seo关键词排名优化工具
  • 自己的网站怎么和百度做友链seo学校培训
  • 北京市建设城乡建设委员会网站教育培训网页设计
  • 网站直播的功能怎样做最佳搜索引擎
  • 软件服务商网站建设seo
  • 深圳营销型网站建设方案服务商百度seo分析工具
  • 徐州手机网站制作公司网络平台有哪些
  • 传奇世界网页版论坛百度自然搜索排名优化
  • 河池网站制作怎样做一个产品营销方案
  • 云南建设厅查证网站手机百度下载
  • 周期购那个网站做的比较好seo推广方案
  • 做电影网站怎么盈利太原网站制作优化seo公司
  • 寄生虫网站怎么做广告sem是什么意思
  • 重庆网站seo什么意思百度人工客服24小时
  • 建筑公司转让seo技术推广