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