vue中使用高德地图隐藏不需要的板块

vue中使用高德地图隐藏不需要的板块

效果图:
在这里插入图片描述
直接在全局index中引入:

在更新版本后密钥和key都必须输入,不然会出现没有数据的情况

<script type="text/javascript">
      window._AMapSecurityConfig = {
        securityJsCode: '密钥值',  //密钥
      }
    </script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=key值&plugin=AMap.DistrictSearch"></script>
<template>
  <div
    id="container"
    style="position: relative; width: 100%; height: 500px"
  ></div>
</template>

<script>
export default {
  name: "Amap",
  data() {
    return {
      map: "",
    };
  },
  mounted() {
    this.initAMap();
  },
  methods: {
    initAMap() {
      let that = this;
      // this.MapLoader().then((AMap) => {
        that.map = new AMap.Map("container", {
          zoom: 9,
          center: [116.44923, 40.207714],
          pitch: 0,
          viewMode: "3D",
        });
        // 异步加载插件
        // AMap.ToolBar: 滑动工具条, AMap.Scale: 比例尺
        // 一次加载多个
        AMap.plugin("AMap.DistrictSearch",  ()=> {
          var district = new AMap.DistrictSearch({
            extensions: "all",
            subdistrict: 0,
            level: "district",
          });
          district.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),
            ]; // 使得遮盖填充反向
            console.log(result,9999)
            var holes = result.districtList[0].boundaries; // 得到该区域的边界坐标集合

            var pathArray = [outer];
            pathArray.push.apply(pathArray, holes);
            var polygon = new AMap.Polygon({
              pathL: pathArray,
              //线条颜色,使用16进制颜色代码赋值。默认值为#006600
              strokeColor: "#6e93f9",
              strokeWeight: 2,
              fillColor: "rgba(255,255,255)",
              fillOpacity: 1,
              strokeStyle: "dashed",
              strokeDasharray: [2, 2],
            });
            polygon.setPath(pathArray);
            that.map.add(polygon);
        
    },
  },
};
</script>

<style scoped>
/*隐藏高德地图logo,版本号*/
/deep/ .amap-logo {
  visibility: hidden;
}
/deep/ .amap-copyright {
  visibility: hidden;
}
</style>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值