diff --git a/src/ol/View.js b/src/ol/View.js index a9bcb0bd05..0200aaf99b 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -138,7 +138,7 @@ View.prototype.applyOptions_ = function(options) { properties[ViewProperty.CENTER] = options.center !== undefined ? options.center : null; - const resolutionConstraintInfo = View.createResolutionConstraint_( + const resolutionConstraintInfo = createResolutionConstraint( options); /** @@ -171,9 +171,9 @@ View.prototype.applyOptions_ = function(options) { */ this.minZoom_ = resolutionConstraintInfo.minZoom; - const centerConstraint = View.createCenterConstraint_(options); + const centerConstraint = createCenterConstraint(options); const resolutionConstraint = resolutionConstraintInfo.constraint; - const rotationConstraint = View.createRotationConstraint_(options); + const rotationConstraint = createRotationConstraint(options); /** * @private @@ -1088,25 +1088,23 @@ View.prototype.setZoom = function(zoom) { /** * @param {olx.ViewOptions} options View options. - * @private * @return {ol.CenterConstraintType} The constraint. */ -View.createCenterConstraint_ = function(options) { +export function createCenterConstraint(options) { if (options.extent !== undefined) { return CenterConstraint.createExtent(options.extent); } else { return CenterConstraint.none; } -}; +} /** - * @private * @param {olx.ViewOptions} options View options. * @return {{constraint: ol.ResolutionConstraintType, maxResolution: number, * minResolution: number, zoomFactor: number}} The constraint. */ -View.createResolutionConstraint_ = function(options) { +export function createResolutionConstraint(options) { let resolutionConstraint; let maxResolution; let minResolution; @@ -1180,15 +1178,14 @@ View.createResolutionConstraint_ = function(options) { } return {constraint: resolutionConstraint, maxResolution: maxResolution, minResolution: minResolution, minZoom: minZoom, zoomFactor: zoomFactor}; -}; +} /** - * @private * @param {olx.ViewOptions} options View options. * @return {ol.RotationConstraintType} Rotation constraint. */ -View.createRotationConstraint_ = function(options) { +export function createRotationConstraint(options) { const enableRotation = options.enableRotation !== undefined ? options.enableRotation : true; if (enableRotation) { @@ -1205,7 +1202,7 @@ View.createRotationConstraint_ = function(options) { } else { return RotationConstraint.disable; } -}; +} /** diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index a5584a3459..678a374ec1 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -1,5 +1,5 @@ import Map from '../../../src/ol/Map.js'; -import View from '../../../src/ol/View.js'; +import View, {createCenterConstraint, createResolutionConstraint, createRotationConstraint} from '../../../src/ol/View.js'; import ViewHint from '../../../src/ol/ViewHint.js'; import * as _ol_extent_ from '../../../src/ol/extent.js'; import Circle from '../../../src/ol/geom/Circle.js'; @@ -32,7 +32,7 @@ describe('ol.View', function() { describe('with no options', function() { it('gives a correct center constraint function', function() { const options = {}; - const fn = View.createCenterConstraint_(options); + const fn = createCenterConstraint(options); expect(fn([0, 0])).to.eql([0, 0]); expect(fn(undefined)).to.eql(undefined); expect(fn([42, -100])).to.eql([42, -100]); @@ -44,7 +44,7 @@ describe('ol.View', function() { const options = { extent: [0, 0, 1, 1] }; - const fn = View.createCenterConstraint_(options); + const fn = createCenterConstraint(options); expect(fn([0, 0])).to.eql([0, 0]); expect(fn([-10, 0])).to.eql([0, 0]); expect(fn([100, 100])).to.eql([1, 1]); @@ -58,7 +58,7 @@ describe('ol.View', function() { describe('with no options', function() { it('gives a correct resolution constraint function', function() { const options = {}; - const fn = View.createResolutionConstraint_(options).constraint; + const fn = createResolutionConstraint(options).constraint; expect(fn(156543.03392804097, 0, 0)) .to.roughlyEqual(156543.03392804097, 1e-9); expect(fn(78271.51696402048, 0, 0)) @@ -74,7 +74,7 @@ describe('ol.View', function() { maxZoom: 3, zoomFactor: 3 }; - const info = View.createResolutionConstraint_(options); + const info = createResolutionConstraint(options); const maxResolution = info.maxResolution; expect(maxResolution).to.eql(81); const minResolution = info.minResolution; @@ -94,7 +94,7 @@ describe('ol.View', function() { const options = { resolutions: [97, 76, 65, 54, 0.45] }; - const info = View.createResolutionConstraint_(options); + const info = createResolutionConstraint(options); const maxResolution = info.maxResolution; expect(maxResolution).to.eql(97); const minResolution = info.minResolution; @@ -112,7 +112,7 @@ describe('ol.View', function() { const defaultMaxRes = 156543.03392804097; function getConstraint(options) { - return View.createResolutionConstraint_(options).constraint; + return createResolutionConstraint(options).constraint; } it('works with only maxZoom', function() { @@ -179,7 +179,7 @@ describe('ol.View', function() { const defaultMaxRes = 156543.03392804097; function getConstraint(options) { - return View.createResolutionConstraint_(options).constraint; + return createResolutionConstraint(options).constraint; } it('works with only maxResolution', function() { @@ -248,7 +248,7 @@ describe('ol.View', function() { const defaultMaxRes = 156543.03392804097; function getConstraint(options) { - return View.createResolutionConstraint_(options).constraint; + return createResolutionConstraint(options).constraint; } it('respects maxResolution over minZoom', function() { @@ -292,7 +292,7 @@ describe('ol.View', function() { describe('create rotation constraint', function() { it('gives a correct rotation constraint function', function() { const options = {}; - const fn = View.createRotationConstraint_(options); + const fn = createRotationConstraint(options); expect(fn(0.01, 0)).to.eql(0); expect(fn(0.15, 0)).to.eql(0.15); });