Skip to content

Commit

Permalink
remove default zoom origin in Map.Anim, fix maptalks/issues#656 (#2335)
Browse files Browse the repository at this point in the history
* remove default zoom origin in Map.Anim, fix maptalks/issues#656

* fix lint

* fix spec
  • Loading branch information
fuzhenn authored May 24, 2024
1 parent a952f92 commit 034af24
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/map/Map.Anim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Map.include(/** @lends Map.prototype */{
this._stopAnim(this._animPlayer);
}
}
const zoomOrigin = view['around'] || new Point(this.width / 2, this.height / 2);
const zoomOrigin = view['around'] || null;
// let preView = this.getView();
const renderer = this._getRenderer(),
framer = function (fn) {
Expand Down
19 changes: 9 additions & 10 deletions src/map/Map.Zoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Map.include(/** @lends Map.prototype */{
delete this.cameraZenithDistance;
this._zooming = true;
this._startZoomVal = this.getZoom();
this._startZoomCoord = this._containerPointToPrj(origin);
this._startZoomCoord = origin && this._containerPointToPrj(origin);
/**
* zoomstart event
* @event Map#zoomstart
Expand All @@ -102,9 +102,9 @@ Map.include(/** @lends Map.prototype */{
const res = this.getResolution(nextZoom),
fromRes = this.getResolution(this._startZoomVal),
scale = fromRes / res / startScale,
startPoint = this.prjToContainerPoint(this._startZoomCoord, this._startZoomVal);
startPoint = this._startZoomCoord && this.prjToContainerPoint(this._startZoomCoord, this._startZoomVal);
const offset = this.getViewPoint();
if (!this.isRotating() && !startPoint.equals(origin) && scale !== 1) {
if (!this.isRotating() && startPoint && !startPoint.equals(origin) && scale !== 1) {
const pitch = this.getPitch();
// coordinate at origin changed, usually by map.setCenter
// add origin offset
Expand All @@ -115,14 +115,13 @@ Map.include(/** @lends Map.prototype */{
}
origin = origin.add(originOffset) as Point;
}
const originX = origin && origin.x || this.width / 2;
const originY = origin && origin.y || this.height / 2;
const matrix = {
'view': [scale, 0, 0, scale, (origin.x - offset.x) * (1 - scale), (origin.y - offset.y) * (1 - scale)]
'view': [scale, 0, 0, scale, (originX - offset.x) * (1 - scale), (originY - offset.y) * (1 - scale)]
};
const dpr = this.getDevicePixelRatio();
if (dpr !== 1) {
origin = origin.multi(dpr) as Point;
}
matrix['container'] = [scale, 0, 0, scale, origin.x * (1 - scale), origin.y * (1 - scale)];
matrix['container'] = [scale, 0, 0, scale, originX * dpr * (1 - scale), originY * dpr * (1 - scale)];
/**
* zooming event
* @event Map#zooming
Expand All @@ -132,7 +131,7 @@ Map.include(/** @lends Map.prototype */{
* @property {Number} from - zoom level zooming from
* @property {Number} to - zoom level zooming to
*/
this._fireEvent('zooming', { 'from': this._startZoomVal, 'to': nextZoom, 'origin': origin, 'matrix': matrix });
this._fireEvent('zooming', { 'from': this._startZoomVal, 'to': nextZoom, 'origin': new Point(originX, originY), 'matrix': matrix });
this._frameZoom = nextZoom;
},

Expand Down Expand Up @@ -163,7 +162,7 @@ Map.include(/** @lends Map.prototype */{
_zoomTo(nextZoom: number, origin?: Point) {
this._zoomLevel = nextZoom;
this._calcMatrices();
if (origin) {
if (origin && this._startZoomCoord) {
const p = this._containerPointToPoint(origin);
const offset = p._sub(this._prjToPoint(this._getPrjCenter()));
this._setPrjCoordAtOffsetToCenter(this._startZoomCoord, offset);
Expand Down
7 changes: 4 additions & 3 deletions src/map/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2146,14 +2146,15 @@ export class Map extends Handlerable(Eventable(Renderable(Class))) {
if (!this.centerAltitude && point.x === this.width / 2 && point.y === this.height / 2) {
return this;
}
const t = this._containerPointToPoint(point)._sub(this._prjToPoint(this._getPrjCenter()));
const pcenter = this._pointToPrj(this._prjToPoint(coordinate).sub(t));
const p = this._containerPointToPoint(point);
const t = p._sub(this._prjToPoint(this._getPrjCenter()));
const pcenter = this._pointToPrj(this._prjToPoint(coordinate)._sub(t));
this._setPrjCenter(pcenter);
return this;
}

_setPrjCoordAtOffsetToCenter(prjCoord: Coordinate, offset: Point) {
const pcenter = this._pointToPrj(this._prjToPoint(prjCoord).sub(offset));
const pcenter = this._pointToPrj(this._prjToPoint(prjCoord)._sub(offset));
this._setPrjCenter(pcenter);
return this;
}
Expand Down

0 comments on commit 034af24

Please sign in to comment.