Round center in viewState

This commit is contained in:
ahocevar
2018-08-09 17:22:49 +02:00
parent e5944682df
commit f3cd1d8dfd
2 changed files with 9 additions and 11 deletions
+2 -9
View File
@@ -1179,19 +1179,12 @@ class PluggableMap extends BaseObject {
for (let i = 0, ii = layerStatesArray.length; i < ii; ++i) { for (let i = 0, ii = layerStatesArray.length; i < ii; ++i) {
layerStates[getUid(layerStatesArray[i].layer)] = layerStatesArray[i]; layerStates[getUid(layerStatesArray[i].layer)] = layerStatesArray[i];
} }
viewState = view.getState(); viewState = view.getState(this.pixelRatio_);
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;
}
frameState = /** @type {module:ol/PluggableMap~FrameState} */ ({ frameState = /** @type {module:ol/PluggableMap~FrameState} */ ({
animate: false, animate: false,
coordinateToPixelTransform: this.coordinateToPixelTransform_, coordinateToPixelTransform: this.coordinateToPixelTransform_,
extent: extent, extent: extent,
focus: focus, focus: this.focus_ ? this.focus_ : viewState.center,
index: this.frameIndex_++, index: this.frameIndex_++,
layerStates: layerStates, layerStates: layerStates,
layerStatesArray: layerStatesArray, layerStatesArray: layerStatesArray,
+7 -2
View File
@@ -894,16 +894,21 @@ class View extends BaseObject {
} }
/** /**
* @param {number} pixelRatio Pixel ratio for center rounding.
* @return {module:ol/View~State} View state. * @return {module:ol/View~State} View state.
*/ */
getState() { getState(pixelRatio) {
const center = /** @type {module:ol/coordinate~Coordinate} */ (this.getCenter()); const center = /** @type {module:ol/coordinate~Coordinate} */ (this.getCenter());
const projection = this.getProjection(); const projection = this.getProjection();
const resolution = /** @type {number} */ (this.getResolution()); const resolution = /** @type {number} */ (this.getResolution());
const pixelResolution = resolution / pixelRatio;
const rotation = this.getRotation(); const rotation = this.getRotation();
return ( return (
/** @type {module:ol/View~State} */ ({ /** @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, projection: projection !== undefined ? projection : null,
resolution: resolution, resolution: resolution,
rotation: rotation, rotation: rotation,