* @function Bounds.prototype.wrapDateLine * @description 将当前 bounds 移动到最大边界范围内部(所谓的内部是相交或者内部)。 * @example * var bounds = new Bounds(380,-40,400,-20); * var maxExtent = new Bounds(-180,-90,100,80); * //新的bounds * var newBounds = bounds.wrapDateLine(maxExtent); * @pa
(maxExtent, options)
| 596 | * 若落在右边,则向左移动,即给当前的bounds值加上负的最大范围的宽度。 |
| 597 | */ |
| 598 | wrapDateLine(maxExtent, options) { |
| 599 | options = options || {}; |
| 600 | |
| 601 | var leftTolerance = options.leftTolerance || 0; |
| 602 | var rightTolerance = options.rightTolerance || 0; |
| 603 | |
| 604 | var newBounds = this.clone(); |
| 605 | |
| 606 | if (maxExtent) { |
| 607 | var width = maxExtent.getWidth(); |
| 608 | //如果 newBounds 在 maxExtent 的左边,那么一直向右移动,直到相交或者包含为止,每次移动width |
| 609 | //shift right? |
| 610 | while (newBounds.left < maxExtent.left && |
| 611 | newBounds.right - rightTolerance <= maxExtent.left) { |
| 612 | newBounds = newBounds.add(width, 0); |
| 613 | } |
| 614 | //如果 newBounds 在 maxExtent 的右边,那么一直向左移动,直到相交或者包含为止,每次移动width |
| 615 | //shift left? |
| 616 | while (newBounds.left + leftTolerance >= maxExtent.right && |
| 617 | newBounds.right > maxExtent.right) { |
| 618 | newBounds = newBounds.add(-width, 0); |
| 619 | } |
| 620 | //如果和右边相交,左边又在内部,那么再次向左边移动一次 |
| 621 | // crosses right only? force left |
| 622 | var newLeft = newBounds.left + leftTolerance; |
| 623 | if (newLeft < maxExtent.right && newLeft > maxExtent.left && |
| 624 | newBounds.right - rightTolerance > maxExtent.right) { |
| 625 | newBounds = newBounds.add(-width, 0); |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | return newBounds; |
| 630 | } |
| 631 | |
| 632 | /** |
| 633 | * @function Bounds.prototype.toServerJSONObject |
no test coverage detected