高德地图实现来回切换卫星图

高德地图 默认初始化地图展示标准3d地图(这里添加蒙层)

    initMap () {
      this.mapObj = new AMap.Map('mapContainer', {
        features: ['bg', 'road', 'point', 'building'],
        showLabel: true,
        rotateEnable: false,
        pitchEnable: false,
        zoom: 17,
        pitch: 65,
        rotation: 45,
        viewMode: '3D', // 开启3D视图,默认为关闭
        zooms: [2, 20],
        center: [120.582112, 29.997117],
        // mapStyle: 'amap://styles/grey',
      });
    },

![在这里插入图片描述](https://img-blog.csdnimg.cn/67d0c6467bfe428285104a335ca4b749.png

希望通过点击切换卫星地图展示—点击事件

    changeMapStyle() {
      if (this.styleType === 'default') {
        this.initLoadMap();
      } else {
        this.layers.hide();
        this.styleType = 'default';
      }
      this.mapObj.remove(this.markerList);
      this.setMarker();
    },

在这里插入图片描述
关键代码 — 思路:通过卫星图层的展示隐藏功能实现

    initLoadMap() {
      this.styleType = 'Satellite';
      // 切换地图样式
      this.layers = new AMap.TileLayer.Satellite({ map: this.mapObj });
      this.layers && this.layers.show();
    },
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Vue切换高德地图层,可以通过以下步骤实现: 1. 在 Vue 的 `mounted` 钩子函数中初始化地: ```javascript mounted() { // 初始化地 this.map = new AMap.Map('map-container', { zoom: 10, center: [116.397428, 39.90923] }); } ``` 2. 在模板中添加地容器元素: ```html <template> <div id="map-container" style="height: 500px;"></div> </template> ``` 3. 添加一个切换层的按钮,绑定点击事件: ```html <template> <div> <div id="map-container" style="height: 500px;"></div> <button @click="switchLayer">切换层</button> </div> </template> ``` 4. 在 Vue 实例中添加 `switchLayer` 方法,用于切换层: ```javascript methods: { switchLayer() { // 获取当前地层 const currentLayer = this.map.getLayers()[0]; // 切换卫星层 if (currentLayer === this.satelliteLayer) { this.map.setLayers([this.roadNetLayer]); } else { // 切换到路网层 this.map.setLayers([this.satelliteLayer]); } } } ``` 5. 在 `mounted` 钩子函数中初始化卫星层和路网层,并将路网层设置为默认层: ```javascript mounted() { // 初始化地 this.map = new AMap.Map('map-container', { zoom: 10, center: [116.397428, 39.90923] }); // 初始化卫星层 this.satelliteLayer = new AMap.TileLayer.Satellite(); // 初始化路网层 this.roadNetLayer = new AMap.TileLayer({ tileSize: 256, zooms: [3, 18], getTileUrl: (x, y, z) => { return `https://webst01.is.autonavi.com/appmaptile?style=7&x=${x}&y=${y}&z=${z}`; } }); // 将路网层设置为默认层 this.map.setLayers([this.roadNetLayer]); } ``` 这样就可以在 Vue实现切换高德地图层了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值