|
1 | 1 | import { Animation, Player } from '../core/Animation';
|
2 | 2 | import Coordinate from '../geo/Coordinate';
|
3 | 3 | import Point from '../geo/Point';
|
4 |
| -import Map from './Map'; |
| 4 | +import { Map, MapViewType } from './Map'; |
5 | 5 | import { isNil, isFunction, hasOwn, extend, clamp } from '../core/util';
|
6 | 6 |
|
7 | 7 |
|
@@ -36,6 +36,40 @@ declare module "./Map" {
|
36 | 36 | // return true;
|
37 | 37 | // }
|
38 | 38 |
|
| 39 | +function needValidateView(view: MapViewType, map: Map) { |
| 40 | + const bearing = view.bearing; |
| 41 | + const currentBearing = map.getBearing(); |
| 42 | + //当bearing溢出半角时,且线型变化时不经过0时,例如:[currentBearing=170,bearing=220],[currentBearing=-170,bearing=-220] |
| 43 | + if (currentBearing >= 0 && bearing > 180) { |
| 44 | + return false; |
| 45 | + } |
| 46 | + if (currentBearing <= 0 && bearing < -180) { |
| 47 | + return false; |
| 48 | + } |
| 49 | + return true; |
| 50 | +} |
| 51 | +//反向旋转,bearing的变化正常为 [a,b],开启reverse后变化就反向了,例如 [170,-170] reverse后为 [170,190] |
| 52 | +function reverseBearing(view: MapViewType, map: Map) { |
| 53 | + const bearing = view.bearing; |
| 54 | + const currentBearing = map.getBearing(); |
| 55 | + //such as [170,-170] |
| 56 | + if (currentBearing >= 0 && bearing < 0) { |
| 57 | + view.bearing = 180 + (180 - Math.abs(bearing)); |
| 58 | + } |
| 59 | + //such as [-170,170] |
| 60 | + if (currentBearing <= 0 && bearing > 0) { |
| 61 | + view.bearing = -180 - (180 - Math.abs(bearing)); |
| 62 | + } |
| 63 | + |
| 64 | + if (currentBearing >= 0 && bearing > 0) { |
| 65 | + view.bearing = -180 - (180 - Math.abs(bearing)); |
| 66 | + } |
| 67 | + |
| 68 | + if (currentBearing <= 0 && bearing < 0) { |
| 69 | + view.bearing = 180 + (180 - Math.abs(bearing)); |
| 70 | + } |
| 71 | +} |
| 72 | + |
39 | 73 | Map.include(/** @lends Map.prototype */{
|
40 | 74 |
|
41 | 75 | /**
|
@@ -63,12 +97,18 @@ Map.include(/** @lends Map.prototype */{
|
63 | 97 | */
|
64 | 98 | animateTo(view, options = {}, step) {
|
65 | 99 | view = extend({}, this.getView(), view);
|
66 |
| - this._validateView(view); |
| 100 | + view.bearing = view.bearing % 360; |
67 | 101 | // this._stopAnim(this._animPlayer);
|
68 | 102 | if (isFunction(options)) {
|
69 | 103 | step = options;
|
70 | 104 | options = {};
|
71 | 105 | }
|
| 106 | + if ((options as any).counterclockwise) { |
| 107 | + reverseBearing(view, this); |
| 108 | + } |
| 109 | + if (needValidateView(view, this)) { |
| 110 | + this._validateView(view); |
| 111 | + } |
72 | 112 | const projection = this.getProjection(),
|
73 | 113 | currView = this.getView(),
|
74 | 114 | props = {};
|
@@ -228,7 +268,13 @@ Map.include(/** @lends Map.prototype */{
|
228 | 268 | // Where applicable, local variable documentation begins with the associated variable or
|
229 | 269 | // function in van Wijk (2003).
|
230 | 270 | view = extend({}, this.getView(), view);
|
231 |
| - this._validateView(view); |
| 271 | + view.bearing = view.bearing % 360; |
| 272 | + if ((options as any).counterclockwise) { |
| 273 | + reverseBearing(view, this); |
| 274 | + } |
| 275 | + if (needValidateView(view, this)) { |
| 276 | + this._validateView(view); |
| 277 | + } |
232 | 278 |
|
233 | 279 | if (this._animPlayer) {
|
234 | 280 | if (this._isInternalAnimation) {
|
|
0 commit comments