diff --git a/src/core/mapHelper.js b/src/core/mapHelper.js index f76d01b..643f67f 100644 --- a/src/core/mapHelper.js +++ b/src/core/mapHelper.js @@ -1,8 +1,7 @@ /** - * 地图助手(最小集) - * maptalks@1.12.x 使用 checkSize 刷新容器尺寸 + * 地图助手(Mapbox) + * replace/restore 移动 #map 容器后必须 resize() */ - class MapHelper { _map = null _originParent = null @@ -20,17 +19,17 @@ class MapHelper { if (!this._map) return if (is3D) { - this._map.setPitch(45) - this._map.setBearing(0) - this._map.config('dragRotate', true) - this._map.config('dragPitch', true) + this._map.easeTo({ pitch: 45, bearing: 0, duration: 0 }) + this._map.dragRotate.enable() + this._map.touchZoomRotate.enableRotation() + if (this._map.dragPitch) this._map.dragPitch.enable() } if (is2D) { - this._map.setPitch(0) - this._map.setBearing(0) - this._map.config('dragRotate', false) - this._map.config('dragPitch', false) + this._map.easeTo({ pitch: 0, bearing: 0, duration: 0 }) + this._map.dragRotate.disable() + this._map.touchZoomRotate.disableRotation() + if (this._map.dragPitch) this._map.dragPitch.disable() } } @@ -39,14 +38,15 @@ class MapHelper { const el = this._map.getContainer() this._originParent = this._originParent || el.parentNode + const c = this._map.getCenter() this._savedView = { - center: this._map.getCenter(), + center: [c.lng, c.lat], zoom: this._map.getZoom(), pitch: this._map.getPitch(), bearing: this._map.getBearing(), } newParent.appendChild(el) - this._map.checkSize() + this._map.resize() } restoreMapContainer() { @@ -56,13 +56,15 @@ class MapHelper { this._originParent.appendChild(el) if (this._savedView) { - this._map.setCenter(this._savedView.center) - this._map.setZoom(this._savedView.zoom) - this._map.setPitch(this._savedView.pitch) - this._map.setBearing(this._savedView.bearing) + this._map.jumpTo({ + center: this._savedView.center, + zoom: this._savedView.zoom, + pitch: this._savedView.pitch, + bearing: this._savedView.bearing, + }) } - this._map.checkSize() + this._map.resize() this._originParent = null this._savedView = null } diff --git a/src/layout/MapLayer.vue b/src/layout/MapLayer.vue index 977b602..f1a7b62 100644 --- a/src/layout/MapLayer.vue +++ b/src/layout/MapLayer.vue @@ -1,33 +1,29 @@