Cesium 鹰眼地图

本文介绍了如何在Vue项目中使用Cesium实现鹰眼地图功能,选择了Leaflet作为2D地图库,并针对高德地图的坐标偏移问题,采用coordtransform进行地理坐标纠偏。同时提到了在双击鹰眼图时可能出现的偏移问题。
摘要由CSDN通过智能技术生成

如图

    

 

鹰眼地图其实就是一个小地图,可以放在视窗的任何位置。这里选择2D地图,地图可以用常见的leaflet或者openlayer,此处示例选用leaflet,也借鉴了其他文章。

此处小地图使用高德地图,由于地图坐标偏移问题,本文对地图联动进行了偏移更改,选用了coordtransform进行了地理坐标纠偏

//安装

npm i leaflet 
npm i coordtransform

​

下面是vue代码

<template>
  <div id="overview" class="overview"></div>
  <div class="yydt-wz">鹰眼地图</div>
</template>
<script lang="ts" setup>
import { CesiumOverviewMapControl } from './CesiumOverviewMapControl'
import * as L from 'leaflet'

const data = reactive({
  overviewCtr: ''
})

const initMap = () => {
  // 加载鹰眼地图
  var url = 'http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}'
  var layer = new L.TileLayer(url, {
    minZoom: 0,
    maxZoom: 20
  })
  var container = document.getElementById('overview')
  var options = {
    container: container,
    toggleDisplay: true,
    width: 281,
    height: 153,
    position: 'topright',
    aimingRectOptions: {
      color: '#ff1100',
      weight: 2
    },
    shadowRectOptions: {
      color: '#0000AA',
      weight: 1,
      opacity: 0,
      fillOpacity: 0
    }
  }
  data.overviewCtr = new CesiumOverviewMapControl(viewer, layer, options)
}

onMounted(async () => {
  initMap()
})
</script>

<style lang="scss" scoped>
.overview {
  position: absolute;
  z-index: 999;
  right: 85px;
  bottom: 37px;

  width: 281px;
  height: 153px;

 

  border: 1px solid gainsboro;
}
.yydt-wz {
  position: absolute;
  z-index: 1000;
  right: 85px;
  bottom: 37px;

  width: 281px;
  height: 32px;

  text-align: center;

  color: #ffffff;
  background-color: rgba($color: #000000, $alpha: 0.4);

  font-family: 'Source Han Sans CN';
  font-size: 16px;
  font-weight: 500;
  line-height: 32px;
}
</style>

下面是CesiumOverviewMapControl.ts代码

// 引入
import * as L from 'leaflet'
import coordtransform from 'coordtransform';

export const CesiumOverviewMapControl = function () {
  this.init.apply(this, arguments)
}

CesiumOverviewMapControl.prototype = {
  _container: null,
  _miniMap: null,
  _viewerMoving: false,
  _miniMapMoving: false,
  _userToggledDisplay: false,
  _minimized: false,
  viewer: null,
  tileLayer: null,
  options: {
    po
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值