Populate view's object properties
This commit is contained in:
@@ -416,10 +416,11 @@ class View extends BaseObject {
|
|||||||
* @param {ViewOptions} options View options.
|
* @param {ViewOptions} options View options.
|
||||||
*/
|
*/
|
||||||
applyOptions_(options) {
|
applyOptions_(options) {
|
||||||
/**
|
const properties = assign({}, options);
|
||||||
* @type {Object<string, *>}
|
for (const key in ViewProperty) {
|
||||||
*/
|
delete properties[key];
|
||||||
const properties = {};
|
}
|
||||||
|
this.setProperties(properties, true);
|
||||||
|
|
||||||
const resolutionConstraintInfo = createResolutionConstraint(options);
|
const resolutionConstraintInfo = createResolutionConstraint(options);
|
||||||
|
|
||||||
@@ -479,17 +480,10 @@ class View extends BaseObject {
|
|||||||
);
|
);
|
||||||
if (options.resolution !== undefined) {
|
if (options.resolution !== undefined) {
|
||||||
this.setResolution(options.resolution);
|
this.setResolution(options.resolution);
|
||||||
} else if (options.zoom !== undefined) {
|
}
|
||||||
|
if (options.zoom !== undefined) {
|
||||||
this.setZoom(options.zoom);
|
this.setZoom(options.zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setProperties(properties);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {ViewOptions}
|
|
||||||
*/
|
|
||||||
this.options_ = options;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -531,12 +525,13 @@ class View extends BaseObject {
|
|||||||
* @return {ViewOptions} New options updated with the current view state.
|
* @return {ViewOptions} New options updated with the current view state.
|
||||||
*/
|
*/
|
||||||
getUpdatedOptions_(newOptions) {
|
getUpdatedOptions_(newOptions) {
|
||||||
const options = assign({}, this.options_);
|
const options = this.getProperties();
|
||||||
|
|
||||||
// preserve resolution (or zoom)
|
// preserve resolution (or zoom)
|
||||||
if (options.resolution !== undefined) {
|
if (options.resolution !== undefined) {
|
||||||
options.resolution = this.getResolution();
|
options.resolution = this.getResolution();
|
||||||
} else {
|
}
|
||||||
|
if (options.zoom !== undefined) {
|
||||||
options.zoom = this.getZoom();
|
options.zoom = this.getZoom();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -973,7 +968,7 @@ class View extends BaseObject {
|
|||||||
* @return {boolean} Resolution constraint is set
|
* @return {boolean} Resolution constraint is set
|
||||||
*/
|
*/
|
||||||
getConstrainResolution() {
|
getConstrainResolution() {
|
||||||
return this.options_.constrainResolution;
|
return this.get('constrainResolution');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -617,6 +617,19 @@ describe('ol/View', function () {
|
|||||||
expect(options.zoom).to.eql(10);
|
expect(options.zoom).to.eql(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns the current properties with getProperties()', function () {
|
||||||
|
const view = new View({
|
||||||
|
center: [0, 0],
|
||||||
|
minZoom: 2,
|
||||||
|
zoom: 10,
|
||||||
|
});
|
||||||
|
const options = view.getProperties();
|
||||||
|
|
||||||
|
expect(options.center).to.eql([0, 0]);
|
||||||
|
expect(options.minZoom).to.eql(2);
|
||||||
|
expect(options.zoom).to.eql(10);
|
||||||
|
});
|
||||||
|
|
||||||
it('applies the current zoom', function () {
|
it('applies the current zoom', function () {
|
||||||
const view = new View({
|
const view = new View({
|
||||||
center: [0, 0],
|
center: [0, 0],
|
||||||
@@ -1874,8 +1887,8 @@ describe('ol/View', function () {
|
|||||||
expect(view.getCenter()[1]).to.be(1500);
|
expect(view.getCenter()[1]).to.be(1500);
|
||||||
});
|
});
|
||||||
it('fits correctly to the extent when a view extent is configured', function () {
|
it('fits correctly to the extent when a view extent is configured', function () {
|
||||||
view.options_.extent = [1500, 0, 2500, 10000];
|
view.set('extent', [1500, 0, 2500, 10000]);
|
||||||
view.applyOptions_(view.options_);
|
view.applyOptions_(view.getProperties());
|
||||||
view.fit([1000, 1000, 2000, 2000]);
|
view.fit([1000, 1000, 2000, 2000]);
|
||||||
expect(view.calculateExtent()).eql([1500, 1000, 2500, 2000]);
|
expect(view.calculateExtent()).eql([1500, 1000, 2500, 2000]);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user