Skip to content

Commit

Permalink
Add center arg to setAngle, center/offset to rotateTo, close #258
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed May 7, 2014
1 parent 4c2e429 commit b6be343
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and `options` has `padding`, `offset`, `speed` and `curve` properties.
- Changed `map.panTo` to accept `latlng[, options]` as arguments, where `options` has `duration`, `easing` and `offset` properties.
- Changed `map.zoomTo` to accept `zoom[, options]` as arguments, where `options` has `duration`, `easing`, `offset` and `center` properties.
- Changed `map.scaleTo` to accept `scale[, options]` as arguments, where `options` has `duration`, `easing`, `offset` and `center` properties.
- Changed `map.rotateTo` to accept `angle[, options]` as arguments, where `options` has `duration`, `easing` and `easing` properties.
- Changed `map.rotateTo` to accept `angle[, options]` as arguments, where `options` has `duration`, `easing`, `offset` and `center` properties.
- Changed `map.resetNorth` to accept optional `options` as argument, which has `duration` and `easing` properties.
- Changed `map.zoomPanTo` to accept `latlng[, zoom, options]` as arguments,
where `options` has `speed`, `curve` and `offset` properties.
Expand All @@ -24,6 +24,7 @@ where `options` has `speed`, `curve` and `offset` properties.
they'll be calculated using the options above.
- Zoom value used in styles now gets adjusted based on latitude. Disabled by `adjustZoom: false` in map options.
Adjustment starts at 0% at zoom 6 and reaches 100% at zoom 9, configured by `minAdjustZoom` and `maxAdjustZoom` options.
- Added `Map` `setAngle` second argument, `center`.
- Improved `Map` `container` option to also be accepted as string (which is an element id) in addition to DOM element.
- Added `LatLngBounds` geometry type.
- Added `Map` `numWorkers` option (7 by default).
Expand Down
10 changes: 8 additions & 2 deletions js/ui/easings.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ util.extend(exports, {
center: mapCenter.add(offset)
}, options);

options.center = Point.convert(options.center);

var easing = this._updateEasing(options.duration, zoom, options.easing),
startZoom = this.transform.zoom;

Expand Down Expand Up @@ -129,17 +131,21 @@ util.extend(exports, {
rotateTo: function(angle, options) {
this.stop();

var mapCenter = this.transform.centerPoint,
offset = Point.convert(options && options.offset || [0, 0]);

options = util.extend({
duration: 500,
easing: util.ease
easing: util.ease,
center: mapCenter.add(offset)
}, options);

var start = this.transform.angle;
this.rotating = true;

this._stopFn = util.timed(function(t) {
if (t === 1) { this.rotating = false; }
this.setAngle(util.interp(start, angle, options.easing(t)));
this.setAngle(util.interp(start, angle, options.easing(t)), options.center);
}, options.duration, this);

return this;
Expand Down
12 changes: 11 additions & 1 deletion js/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,22 @@ util.extend(Map.prototype, {
},

// Set the map's rotation given a center to rotate around and an angle in radians.
setAngle: function(angle) {
setAngle: function(angle, center) {
// Confine the angle to within [-π,π]
while (angle > Math.PI) angle -= Math.PI * 2;
while (angle < -Math.PI) angle += Math.PI * 2;

center = Point.convert(center);
var origin = center && center.sub(this.transform.centerPoint);

if (center) {
this.transform.panBy(origin);
}
this.transform.angle = angle;
if (center) {
this.transform.panBy(origin.mult(-1));
}

this.update();

return this
Expand Down

0 comments on commit b6be343

Please sign in to comment.