diff --git a/src/components/MapBox.vue b/src/components/MapBox.vue index 4728f7d..d389de1 100644 --- a/src/components/MapBox.vue +++ b/src/components/MapBox.vue @@ -171,7 +171,7 @@ export default { // 地图比例 // this.map.addControl(new mapboxgl.ScaleControl(), 'top-right') // 全屏 - this.map.addControl(new mapboxgl.FullscreenControl(), 'top-right') + this.map.addControl(new CustomFullscreenControl(this.handleResize), 'top-right') // 跟随飞机 // this.map.addControl( // new mapboxgl.GeolocateControl({ @@ -561,6 +561,7 @@ export default { * @description:重置地图大小 */ handleResize () { + console.log('hi') if (this.map) { setTimeout(() => { this.map.resize() @@ -603,6 +604,19 @@ class CustomControl { this._map = undefined } } + +class CustomFullscreenControl extends mapboxgl.FullscreenControl { + constructor (handleResize) { + super() + this.handleResize = handleResize + } + + _onClickFullscreen () { + super._onClickFullscreen() // 调用原始的全屏切换行为 + this.handleResize() // 调用自定义的 handleResize 方法 + } +} +