zhanghua
2023-04-03 91a2e0d1cdc2b4ad816d5ee450f159ef6cd57486
src/components/map/leafletMap.vue
@@ -9,6 +9,7 @@
    data() {
        return {
            map: null,
      marker: null,
            map_point: { x: "119.27179890", y: "28.59027084" },
            map_zoom: 15,
            mapUrl:
@@ -42,7 +43,7 @@
        };
    },
    mounted() {
        console.log('/* 创建地图实例 */')
    console.log("/* 创建地图实例 */");
        setTimeout(() => {
            this.createrMap();
        }, 100);
@@ -50,7 +51,6 @@
    methods: {
        /* 创建地图实例 */
        createrMap() {
            this.option.center = [eval(this.map_point.y), eval(this.map_point.x)];
            this.option.zoom = this.map_zoom;
            this.map = this.$map.createrMap("map-container", this.option);
@@ -71,22 +71,24 @@
            //   // // });
            // });
            this.locationMap();
        },
        locationMap() {
            debugger
            if (this.map_point && this.map_point.y) {
                this.map.setView([eval(this.map_point.y), eval(this.map_point.x)], this.map_zoom);
        this.map.setView(
          [eval(this.map_point.y), eval(this.map_point.x)],
          this.map_zoom
        );
            }
            if (this.mark && this.map) {
        if (this.marker) this.map.removeLayer(this.marker);
                // 创建一个 Marker 实例:
                var marker = L.marker([eval(this.map_point.y), eval(this.map_point.x)]).addTo(
                    this.map
                );
                let that = this
        this.marker = L.marker([
          eval(this.map_point.y),
          eval(this.map_point.x),
        ]).addTo(this.map);
        let that = this;
                // 将创建的点标记添加到已有的地图实例:
                marker.on("click", function (e) {
        this.marker.on("click", function (e) {
                    that.$emit("fatherMethod");
                });
            }