From f3cd1d8dfde1ba538c20ce4eee39a675d9a42027 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 9 Aug 2018 17:22:49 +0200 Subject: [PATCH] Round center in viewState --- src/ol/PluggableMap.js | 11 ++--------- src/ol/View.js | 9 +++++++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/ol/PluggableMap.js b/src/ol/PluggableMap.js index ffddf09188..7f70ddf671 100644 --- a/src/ol/PluggableMap.js +++ b/src/ol/PluggableMap.js @@ -1179,19 +1179,12 @@ class PluggableMap extends BaseObject { for (let i = 0, ii = layerStatesArray.length; i < ii; ++i) { layerStates[getUid(layerStatesArray[i].layer)] = layerStatesArray[i]; } - viewState = view.getState(); - let focus = this.focus_; - if (!focus) { - focus = viewState.center; - const pixelResolution = viewState.resolution / this.pixelRatio_; - focus[0] = Math.round(focus[0] / pixelResolution) * pixelResolution; - focus[1] = Math.round(focus[1] / pixelResolution) * pixelResolution; - } + viewState = view.getState(this.pixelRatio_); frameState = /** @type {module:ol/PluggableMap~FrameState} */ ({ animate: false, coordinateToPixelTransform: this.coordinateToPixelTransform_, extent: extent, - focus: focus, + focus: this.focus_ ? this.focus_ : viewState.center, index: this.frameIndex_++, layerStates: layerStates, layerStatesArray: layerStatesArray, diff --git a/src/ol/View.js b/src/ol/View.js index 6583af494d..bfa03058a8 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -894,16 +894,21 @@ class View extends BaseObject { } /** + * @param {number} pixelRatio Pixel ratio for center rounding. * @return {module:ol/View~State} View state. */ - getState() { + getState(pixelRatio) { const center = /** @type {module:ol/coordinate~Coordinate} */ (this.getCenter()); const projection = this.getProjection(); const resolution = /** @type {number} */ (this.getResolution()); + const pixelResolution = resolution / pixelRatio; const rotation = this.getRotation(); return ( /** @type {module:ol/View~State} */ ({ - center: center.slice(), + center: [ + Math.round(center[0] / pixelResolution) * pixelResolution, + Math.round(center[1] / pixelResolution) * pixelResolution + ], projection: projection !== undefined ? projection : null, resolution: resolution, rotation: rotation,