vue中基于高德地图,获取省级地图(以安徽为例)

效果图展示
在这里插入图片描述

<template>
  <div>
    <div id="mapId" class="rescure-map"></div>
  </div>
</template>

在这里插入图片描述
import AMap from ‘AMap’

 mounted() {
      var that = this
      that.initMap()
  },
 methods: {
      // 初始化地图
      initMap() {
        var that = this
        const mapConfig = {
          zoom: 10 ,// 地图显示的缩放级别
          mapStyle: 'amap://styles/darkblue', //地图背景样式
          showIndoorMap: false
        }
        // maps是容器的id名
        that.map = new AMap.Map('mapId', mapConfig)
        that.map.setMapStyle('amap://styles/db630f877ac1565889e6ec8576250978') // 自定义地图样式,不显示村庄和乡镇
        AMap.plugin('AMap.DistrictSearch', function () {
          var districtSearch = new AMap.DistrictSearch({
            extensions: 'all',
            subdistrict: 0
          })
          // 搜索所有省/直辖市信息  --下边的安徽省,可根据需要换成其他省、市或区县的地名
          districtSearch.search('安徽省', function(status, result) {
            // 外多边形坐标数组和内多边形坐标数组
            var outer = [
              new AMap.LngLat(-360, 90, true),
              new AMap.LngLat(-360, -90, true),
              new AMap.LngLat(360, -90, true),
              new AMap.LngLat(360, 90, true)
            ]
            var holes = result.districtList[0].boundaries

            var pathArray = [outer]
            pathArray.push.apply(pathArray, holes)
            var polygon = new AMap.Polygon({
              pathL: pathArray,
              // strokeColor: '#f00',
              strokeWeight: 1,
              fillColor: '#000001',
              fillOpacity: 1
            })
            polygon.setPath(pathArray)
            that.map.add(polygon)
          })
        })

      }
    }
<style>
  /* 隐藏地图水印 */
  .amap-logo {
    right: 0 !important;
    left: auto !important;
    display: none!important;
  }
  .amap-copyright {
    right: 0px !important;
    left: auto !important;
    visibility: hidden;
    display: none!important;
  }
</style>
<style scoped>
  .rescure-map{
    height: calc(100vh - 111px);
  }
</style>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值