Make sure the requested image size matches the desired ratio
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import ImageWMS from '../../../../src/ol/source/ImageWMS.js';
|
import ImageWMS from '../../../../src/ol/source/ImageWMS.js';
|
||||||
import {get as getProjection} from '../../../../src/ol/proj.js';
|
import {get as getProjection} from '../../../../src/ol/proj.js';
|
||||||
|
import {getWidth, getHeight} from '../../../../src/ol/extent.js';
|
||||||
|
|
||||||
|
|
||||||
describe('ol.source.ImageWMS', function() {
|
describe('ol.source.ImageWMS', function() {
|
||||||
@@ -30,15 +31,24 @@ describe('ol.source.ImageWMS', function() {
|
|||||||
describe('#getImage', function() {
|
describe('#getImage', function() {
|
||||||
|
|
||||||
it('returns the expected image URL', function() {
|
it('returns the expected image URL', function() {
|
||||||
options.ratio = 1.5;
|
[1, 1.5].forEach(function(ratio) {
|
||||||
const source = new ImageWMS(options);
|
options.ratio = ratio;
|
||||||
const image = source.getImage([10, 20, 30.1, 39.9], resolution, pixelRatio, projection);
|
const source = new ImageWMS(options);
|
||||||
const uri = new URL(image.src_);
|
const viewExtent = [10, 20, 30.1, 39.9];
|
||||||
const queryData = uri.searchParams;
|
const viewWidth = getWidth(viewExtent);
|
||||||
const extent = queryData.get('BBOX').split(',').map(Number);
|
const viewHeight = getHeight(viewExtent);
|
||||||
const extentAspectRatio = (extent[3] - extent[1]) / (extent[2] - extent[0]);
|
const image = source.getImage(viewExtent, resolution, pixelRatio, projection);
|
||||||
const imageAspectRatio = Number(queryData.get('WIDTH') / Number(queryData.get('HEIGHT')));
|
const uri = new URL(image.src_);
|
||||||
expect(extentAspectRatio).to.roughlyEqual(imageAspectRatio, 1e-12);
|
const queryData = uri.searchParams;
|
||||||
|
const imageWidth = Number(queryData.get('WIDTH'));
|
||||||
|
const imageHeight = Number(queryData.get('HEIGHT'));
|
||||||
|
const bbox = queryData.get('BBOX').split(',').map(Number);
|
||||||
|
const bboxAspectRatio = (bbox[3] - bbox[1]) / (bbox[2] - bbox[0]);
|
||||||
|
const imageAspectRatio = imageWidth / imageHeight;
|
||||||
|
expect (imageWidth).to.be(Math.ceil(viewWidth / resolution * ratio));
|
||||||
|
expect (imageHeight).to.be(Math.ceil(viewHeight / resolution * ratio));
|
||||||
|
expect(bboxAspectRatio).to.roughlyEqual(imageAspectRatio, 1e-12);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses correct WIDTH and HEIGHT for HiDPI devices', function() {
|
it('uses correct WIDTH and HEIGHT for HiDPI devices', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user