vue高德地图自动补齐和覆盖物经纬度map

<template>
  <div>
    <el-input id="tipinput" type="text" v-model="address"></el-input>
    <div id="container"></div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      address: "",
      info: [],
      points: "",
    };
  },
  methods: {},
  mounted() {
    var auto = new AMap.Autocomplete({
      input: "tipinput",
    });
    AMap.event.addListener(auto, "select", (e) => {
      this.info[0] = e.poi.location.lng;
      this.info[1] = e.poi.location.lat;
      console.log(this.info);

      var map = new AMap.Map("container", {
        center: this.info,
        zoom: 14,
      });
      var marker = new AMap.Marker({
        icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
        position: this.info,
      });
      map.add(marker);
      var path = [
        [this.info[0] - 0.0005, this.info[1] + 0.0003],
        [this.info[0] - 0.0005, this.info[1] - 0.0003],
        [this.info[0] + 0.0005, this.info[1] - 0.0003],
        [this.info[0] + 0.0005, this.info[1] + 0.0003],
      ];
      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, marker]);
      var polyEditor = new AMap.PolyEditor(map, polygon);
      polyEditor.on("adjust", function (event) {
        this.points = event.target.w.path;
        this.points = this.points.map((item) => {
          return [item.lng, item.lat];
        });
        console.log(JSON.stringify(this.points));
      });
      polyEditor.open();
    });
  },
};
</script>
<style lang="scss" scoped>
#container {
  height: 500px;
  width: 500px;
}
</style>

在index.html中引入

  • 注意下面&plugin=AMap.Autocomplete&plugin=AMap.PolyEditor不要拆成两个键值对后用两个script标签引入,这样会报错
  • (keyvalue就是key)
<script type="text/javascript"
    src="https://webapi.amap.com/maps?v=1.4.15&key=keyvalue&plugin=AMap.Autocomplete&plugin=AMap.PolyEditor"></script>
  <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
  <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>

效果图:
在这里插入图片描述
上图中的巨型可以拖动,然后获取经纬度数据,这些数据作为下次编辑时的初始化数据

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值