zhanghua
2022-12-14 405eeb045cfecff07b80a33582033be6cc52ed33
src/components/map/index.vue
@@ -7,6 +7,15 @@
    data() {
        return {
            map: null,
    };
  },
  created() {
    debugger;
    if (!this.point) {
      this.point = { x: "119.27179890", y: "28.59027084" };
    }
    if (!this.zoom) {
      this.zoom = 15;
        }
    },
    mounted() {
@@ -17,13 +26,25 @@
        })
            .then((AMap) => {
                this.map = new AMap.Map("container");
                this.map.setZoomAndCenter(15,['119.27179890', '28.59027084']);
        this.map.setZoomAndCenter(this.zoom, [this.point.x, this.point.y]);
        if (this.mark) {
          // 创建一个 Marker 实例:
          var marker = new AMap.Marker({
            position: new AMap.LngLat(this.point.x, this.point.y), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
            title: this.mark.title,
          });
          // 将创建的点标记添加到已有的地图实例:
          this.map.add(marker);
        }
            })
            .catch((e) => {
                console.log(e);
            });
    }
}
  },
  props: ["point", "zoom", "mark"],
};
</script>
<style lang="scss" scoped>
#container {