1.首先使用MapDownloader下载地图瓦片。软件在百度网盘中。
链接:https://pan.baidu.com/s/1r-Nk-DMjuNIqqxa7_B-OoA
提取码:qwlw
在这里插入图片描述
点击打开在这里插入图片描述
存储方式选择磁盘,下载位置为D:\GisMap,如需修改,选择MapDownloader.exe.config文件进入修改。

我下载的是上海市的瓦片数据。
瓦片数据太大所以只选择下载了15级。瓦片地址需要放置到一个能访问到的地址,我选择放到本地nginx下。
2.通过https://webapi.amap.com/maps?v=2.0&key=高德key来下载高德地图源码,我试过下载1.4.4版本的源码,但走不通离线,1.4.4版本调用了很多外部的东西改动太大。下载完的js文件放到文件夹public中,并在index.html引入

 <script type="text/javascript" src="./mapv2n.js"></script>
  <script type="text/javascript" src="./mapsplugin.js"></script>

这两个源码通过上面的地址访问到后,查看F12后发现有两个js文件引入,所以将其下载下来放到本地.
3.此时可以打开页面查看接口中有哪些外部请求。这边碰到的有两张图片。

https://vdata.amap.com/style_icon/2.0/icon-biz-big.png
https://vdata.amap.com/style_icon/2.0/icon-normal-big.png

外部请求文件全部下载下来放到nginx下,使其能够访问到。将瓦片地址也全部放到nginx下。
4.修改下载来的maps.js文件。
搜索icon-biz-big和icon-normal-big.png将其全部改成自己配置的nginx文件地址。
5.页面代码

<template>
  <div style="height: 500px;">
    <div ref="wrapRef" id="" style="height: 500px;width:1200px"></div>
  </div>
</template>

<script>
import { AMapManager } from "vue-amap";
let amapManager = new AMapManager();
var AMapSelf;
export default {
  components: {},
  props: {},
  data: function () {
    const self = this;
    return {
      amapManager,
     
    };
  },
  watch: {},
  computed: {},
  created() {},
  mounted() {
    this.$nextTick(()=>{
      this.initMap();
    })
  },
  methods: {
    initMap(){
      const wrapEl = this.$refs.wrapRef;
      if (!wrapEl) return;
      AMapSelf = new AMap.Map(wrapEl, {
        resizeEnable: true,
        zoom: 10, // 初始化缩放级别
        viewMode: '3D',
        center: [121.59996, 31.197646], // 初始化中心点
        // 指定离线地图路径
        layers: [
          new AMap.TileLayer({
            visible: true,
            zIndex: 99,
            opacity: 1,
            getTileUrl: (a, b, c) => {
              //经纬度转换成本地瓦片所在路径
              let flag = '00000000';
              let zz = c;
              let z = 'L' + zz;
              let xx = a.toString(16);
              let x = 'C' + flag.substring(0, 8 - xx.length) + xx;
              let yy = b.toString(16);
              let y = 'R' + flag.substring(0, 8 - yy.length) + yy;
              return 'gaodemap/' + z + '/' + y + '/' + x + '.png';
            },
          }),
        ],
      });

      AMapSelf.setDefaultCursor('pointer');

      AMapSelf.on('click', (e) => {
        AMapSelf.clearMap();
        var marker = new AMap.Marker({
          position: new AMap.LngLat(e.lnglat.getLng(), e.lnglat.getLat()),
          icon: Icon,
          offset: new AMap.Pixel(-13, -30),
        });
        AMapSelf.add(marker);
        var text = '您在 [ ' + e.lnglat.getLng() + ',' + e.lnglat.getLat() + ' ] 的位置双击了地图';
        alert(text);
      });
 
    }
  },
};
</script>
<style lang="scss" scoped></style>

由于我写的瓦片地址为gaodemap下,为使其能访问到,将gaodemap通过vue代理到之前瓦片放置位置

   '^/gaodemap': {
                target: 'http://10.0.0.xxx:8030', //对应*
                changeOrigin: true,
                ws: false,
                secure: false,
                pathRewrite: {
                    '^/gaodemap': ''
                },
            },

到这里就可以实现地图离线功能。

GitHub 加速计划 / vu / vue
207.55 K
33.66 K
下载
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:3 个月前 )
73486cb5 * chore: fix link broken Signed-off-by: snoppy <michaleli@foxmail.com> * Update packages/template-compiler/README.md [skip ci] --------- Signed-off-by: snoppy <michaleli@foxmail.com> Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 5 个月前
e428d891 Updated Browser Compatibility reference. The previous currently returns HTTP 404. 6 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐