From e1aa0ecffbabd618c71e4ad94370fb8dffe6ee1c Mon Sep 17 00:00:00 2001 From: zhanghua <314079846@qq.com> Date: 星期日, 21 一月 2024 20:54:49 +0800 Subject: [PATCH] 优化 --- src/components/map/leafletMap.vue | 28 +++++++++++++++++----------- 1 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/components/map/leafletMap.vue b/src/components/map/leafletMap.vue index d53bd34..96e2b42 100644 --- a/src/components/map/leafletMap.vue +++ b/src/components/map/leafletMap.vue @@ -9,10 +9,11 @@ data() { return { map: null, + marker: null, map_point: { x: "119.27179890", y: "28.59027084" }, map_zoom: 15, mapUrl: - "http://117.139.13.157:41005/tilermap/rest/services/mapserver/baidu-image-db/{z}/{x}/{y}", + "http://172.28.194.179:41005/tilermap/rest/services/mapserver/baidu-image-db/{z}/{x}/{y}", // mapUrls: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', // mapUrls: "http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}", option: { @@ -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,18 +71,24 @@ // // // }); // }); this.locationMap(); - }, locationMap() { - if (this.mark && this.map) { - // 鍒涘缓涓�涓� Marker 瀹炰緥锛� - var marker = L.marker([eval(this.map_point.y), eval(this.map_point.x)]).addTo( - this.map + if (this.map_point && this.map_point.y) { + this.map.setView( + [eval(this.map_point.y), eval(this.map_point.x)], + this.map_zoom ); - let that = this + } + if (this.mark && this.map) { + if (this.marker) this.map.removeLayer(this.marker); + // 鍒涘缓涓�涓� Marker 瀹炰緥锛� + 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) { - console.log("666"); + this.marker.on("click", function (e) { that.$emit("fatherMethod"); }); } -- Gitblit v1.8.0