@vuemap/vue-amap高德vue组件库常用技巧(四)

@vuemap/vue-amap是基于高德JSAPI2.0、Loca2.0封装的vue组件库,支持vue2、vue3版本。首页地址:vue-amap.guyixi.cn/

在上一个分享中,主要讲解了单信息框与多信息框的使用的使用情况,这一次分享着重讲怎么在高德地图中加载第三方瓦片的使用技巧。

对于瓦片加载,日常使用时会碰到两种坐标系,一个是基于WGS84生成的瓦片、另一个是基于火星坐标系生成的瓦片。高德地图本身只支持火星坐标系的瓦片,但高德提供了GlCustomLayer对象,可以自定义实现加载其他坐标系瓦片的能力,因此,基于GlCustomLayer我实现了一个瓦片纠偏插件,用于加载BD09(百度使用的坐标系,基于火星坐标系再次加密)和WGS84坐标系的瓦片数据。插件地址

火星坐标系瓦片加载

火星坐标系的瓦片加载是最简单,直接使用el-amap-layer-tile即可加载瓦片。 示例代码如下:

html 复制代码
<template>
  <div class="map-page-container">
    <el-amap
      :center="center"
      :zoom="zoom"
    >
      <el-amap-layer-tile
        :tile-url="'https://wprd0{1,2,3,4}.is.autonavi.com/appmaptile?x=[x]&y=[y]&z=[z]&size=1&scl=1&style=8&ltype=11'"
        :visible="visible"
      />
    </el-amap>
  </div>
  <div class="toolbar">
    <button @click="switchVisible()">
      {{ visible? '隐藏' : '显示' }}
    </button>
  </div>
</template>

<script lang="ts" setup>
import {ref} from "vue";
import {ElAmap, ElAmapLayerTile} from "@vuemap/vue-amap";

const zoom = ref(12);
const center = ref([121.59996, 31.197646]);


const visible = ref(true)
const switchVisible = () => {
  visible.value = !visible.value;
}

</script>

<style>
</style>

效果图:

加载其他坐标系瓦片

当需要加载其他坐标系瓦片时我们就需要使用el-amap-layer-custom-xyz图层来进行瓦片纠偏。 模拟的示例如下:

html 复制代码
<template>
  <div class="map-page-container">
    <el-amap
      :show-label="false"
      :center="center"
      :zoom="zoom"
      :pitch="60"
      view-mode="3D"
    >
      <el-amap-layer-custom-xyz
        url="https://maponline{s}.bdimg.com/starpic/?qt=satepc&u=x={x};y={y};z={z};v=009;type=sate&fm=46"
        :subdomains="subdomains"
        proj="bd09"
        tileType="bd09"
        :visible="visible"
      />
    </el-amap>
  </div>
  <div class="toolbar">
    <button @click="switchVisible()">
      {{ visible ? '隐藏' : '显示' }}
    </button>
  </div>
</template>

<script lang="ts" setup>
import {ref} from "vue";
import {ElAmap, ElAmapLayerCustomXyz} from "@vuemap/vue-amap";

const center = ref([116.335036, 39.900082])
const zoom = ref(8)
const visible = ref(true)
const subdomains = ref(["1", "2", "3"])

const switchVisible = () => {
  visible.value = !visible.value;
}

</script>

<style>
</style>

效果图 根据文档调整参数还可以实现掩膜,瓦片增加海拔实现瓦片浮空效果。

相关推荐
全栈测试笔记14 分钟前
异步函数与异步生成器
linux·服务器·前端·数据库·python
EndingCoder31 分钟前
配置 tsconfig.json:高级选项
linux·前端·ubuntu·typescript·json
木风小助理36 分钟前
JavaStreamAPI的性能审视,优雅语法背后的隐形成本与优化实践
java·前端·数据库
white-persist2 小时前
轻松抓包微信小程序:Proxifier+Burp Suite教程
前端·网络·安全·网络安全·微信小程序·小程序·notepad++
敲敲了个代码3 小时前
多标签页强提醒不重复打扰:从“弹框轰炸”到“共享待处理队列”的实战
java·前端·javascript·面试·架构
不想上班只想要钱3 小时前
动态类名在 <swiper-slide 的复制项中没有起作用的解决方法
前端·vue.js
weixin_395448913 小时前
tidl_import_mul_rmfsd_psd_u8_3x480x544_bise_raw_dynamic.txt
java·服务器·前端
Jinuss4 小时前
源码分析之React中updateContainerImpl方法更新容器
前端·react.js·前端框架
Mr Xu_4 小时前
Vue + Element Plus 实现前端导出 Excel 功能详解
前端·javascript·vue.js
仰泳之鹅5 小时前
【杂谈】使用Edge浏览器下载文件显示“Microsoft Defender SmartScreen 已阻止此不安全文件”的解决方法
前端·edge