vue电子围栏多边形高德

<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  <style>
    html,
    body,
    #container {
      width: 100%;
      height: 100%;
    }

  </style>
  <title>多边形的绘制和编辑</title>
  <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
  <script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>
  <script src="https://webapi.amap.com/maps?v=1.4.15&key=39c15fa873ad158eb4f3a66964b817f7&plugin=AMap.PolyEditor">
  </script>
</head>

<body>
  <div id="container"></div>
  <div class="input-card" style="width: 120px">
    <button class="btn" onclick="polyEditor.open()" style="margin-bottom: 5px">开始编辑</button>
    <button class="btn" onclick="polyEditor.close()">结束编辑</button>
    <button class="btn" onclick="submit()" style="margin-top: 5px">保存</button>
  </div>
  <script type="text/javascript">
    var flag = false
    var polyEditor, path;
    var map = new AMap.Map("container", {
      center: [113.783745, 34.725365],
      zoom: 14
    });
   
    window.addEventListener("message", (e) => {
        if(flag)  return
        if(e){
           flag = true 
        }
      console.log(e, "接受到父页面的数据")
      path = e.data

      // 初始化
      var polygon = new AMap.Polygon({
        path: path,
        strokeColor: "#FF33FF",
        strokeWeight: 6,
        strokeOpacity: 0.2,
        fillOpacity: 0.4,
        fillColor: '#1791fc',
        zIndex: 50,
      })
      map.add(polygon)
      // 缩放地图到合适的视野级别
      map.setFitView([polygon])
      polyEditor = new AMap.PolyEditor(map, polygon)

      polyEditor.on('end', function (event) {
        path = event.target.De.path
        console.log(event.target)
        // event.target 即为编辑后的多边形对象
      })
    })

    function submit() {
      window.parent.postMessage(path, '*');
    }

  </script>
</body>

</html>
// 多边形绘制
    setEnclosure() {
      this.enclosureShow = true;
      setTimeout(() => {
        this.iframeWin = this.$refs.iframeMap.contentWindow;
        this.iframeWin.postMessage(this.path, "*");
      }, 300);
      setTimeout(() => {
        this.iframeWin.postMessage(this.path, "*");
      }, 2000);
      setTimeout(() => {
        this.iframeWin.postMessage(this.path, "*");
      }, 4000);
    },


<iframe
          width="100%"
          class="iframe-style"
          ref="iframeMap"
          frameborder="no"
          :src="mapUrl"
        ></iframe>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值