Merge pull request #10785 from ahocevar/zoomify-retina
Detect Zoomify server-side retina tiles
This commit is contained in:
@@ -11,6 +11,7 @@ import {createCanvasContext2D} from '../dom.js';
|
|||||||
import {toSize} from '../size.js';
|
import {toSize} from '../size.js';
|
||||||
import TileImage from './TileImage.js';
|
import TileImage from './TileImage.js';
|
||||||
import TileGrid from '../tilegrid/TileGrid.js';
|
import TileGrid from '../tilegrid/TileGrid.js';
|
||||||
|
import {getCenter} from '../extent.js';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,7 +89,7 @@ export class CustomTile extends ImageTile {
|
|||||||
* @property {number} [tilePixelRatio] The pixel ratio used by the tile service. For example, if the tile service advertizes 256px by 256px tiles but actually sends 512px by 512px images (for retina/hidpi devices) then `tilePixelRatio` should be set to `2`
|
* @property {number} [tilePixelRatio] The pixel ratio used by the tile service. For example, if the tile service advertizes 256px by 256px tiles but actually sends 512px by 512px images (for retina/hidpi devices) then `tilePixelRatio` should be set to `2`
|
||||||
* @property {number} [reprojectionErrorThreshold=0.5] Maximum allowed reprojection error (in pixels).
|
* @property {number} [reprojectionErrorThreshold=0.5] Maximum allowed reprojection error (in pixels).
|
||||||
* Higher values can increase reprojection performance, but decrease precision.
|
* Higher values can increase reprojection performance, but decrease precision.
|
||||||
* @property {string} [url] URL template or base URL of the Zoomify service.
|
* @property {string} url URL template or base URL of the Zoomify service.
|
||||||
* A base URL is the fixed part
|
* A base URL is the fixed part
|
||||||
* of the URL, excluding the tile group, z, x, and y folder structure, e.g.
|
* of the URL, excluding the tile group, z, x, and y folder structure, e.g.
|
||||||
* `http://my.zoomify.info/IMAGE.TIF/`. A URL template must include
|
* `http://my.zoomify.info/IMAGE.TIF/`. A URL template must include
|
||||||
@@ -100,7 +101,7 @@ export class CustomTile extends ImageTile {
|
|||||||
* A `{?-?}` template pattern, for example `subdomain{a-f}.domain.com`, may be
|
* A `{?-?}` template pattern, for example `subdomain{a-f}.domain.com`, may be
|
||||||
* used instead of defining each one separately in the `urls` option.
|
* used instead of defining each one separately in the `urls` option.
|
||||||
* @property {string} [tierSizeCalculation] Tier size calculation method: `default` or `truncated`.
|
* @property {string} [tierSizeCalculation] Tier size calculation method: `default` or `truncated`.
|
||||||
* @property {import("../size.js").Size} [size] Size of the image.
|
* @property {import("../size.js").Size} size
|
||||||
* @property {import("../extent.js").Extent} [extent] Extent for the TileGrid that is created.
|
* @property {import("../extent.js").Extent} [extent] Extent for the TileGrid that is created.
|
||||||
* Default sets the TileGrid in the
|
* Default sets the TileGrid in the
|
||||||
* fourth quadrant, meaning extent is `[0, -height, width, 0]`. To change the
|
* fourth quadrant, meaning extent is `[0, -height, width, 0]`. To change the
|
||||||
@@ -125,11 +126,11 @@ export class CustomTile extends ImageTile {
|
|||||||
class Zoomify extends TileImage {
|
class Zoomify extends TileImage {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Options=} opt_options Options.
|
* @param {Options} opt_options Options.
|
||||||
*/
|
*/
|
||||||
constructor(opt_options) {
|
constructor(opt_options) {
|
||||||
|
|
||||||
const options = opt_options || {};
|
const options = opt_options;
|
||||||
|
|
||||||
const size = options.size;
|
const size = options.size;
|
||||||
const tierSizeCalculation = options.tierSizeCalculation !== undefined ?
|
const tierSizeCalculation = options.tierSizeCalculation !== undefined ?
|
||||||
@@ -196,7 +197,7 @@ class Zoomify extends TileImage {
|
|||||||
}
|
}
|
||||||
const urls = expandUrl(url);
|
const urls = expandUrl(url);
|
||||||
|
|
||||||
const tileWidth = tileSize * tilePixelRatio;
|
let tileWidth = tileSize * tilePixelRatio;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} template Template.
|
* @param {string} template Template.
|
||||||
@@ -259,6 +260,19 @@ class Zoomify extends TileImage {
|
|||||||
*/
|
*/
|
||||||
this.zDirection = options.zDirection;
|
this.zDirection = options.zDirection;
|
||||||
|
|
||||||
|
// Server retina tile detection (non-standard):
|
||||||
|
// Try loading the center tile for the highest resolution. If it is not
|
||||||
|
// available, we are dealing with retina tiles, and need to adjust the
|
||||||
|
// tile url calculation.
|
||||||
|
const tileUrl = tileGrid.getTileCoordForCoordAndResolution(getCenter(tileGrid.getExtent()), resolutions[resolutions.length - 1]);
|
||||||
|
const testTileUrl = tileUrlFunction(tileUrl, 1, null);
|
||||||
|
const image = new Image();
|
||||||
|
image.addEventListener('error', function() {
|
||||||
|
tileWidth = tileSize;
|
||||||
|
this.changed();
|
||||||
|
}.bind(this));
|
||||||
|
image.src = testTileUrl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ describe('ol.source.Zoomify', function() {
|
|||||||
|
|
||||||
describe('constructor', function() {
|
describe('constructor', function() {
|
||||||
|
|
||||||
it('requires config "size"', function() {
|
it('requires config "size" and "url"', function() {
|
||||||
let source;
|
let source;
|
||||||
|
|
||||||
// undefined config object
|
// undefined config object
|
||||||
@@ -58,7 +58,7 @@ describe('ol.source.Zoomify', function() {
|
|||||||
source = new Zoomify({});
|
source = new Zoomify({});
|
||||||
}).to.throwException();
|
}).to.throwException();
|
||||||
|
|
||||||
// not passing "size" in config object
|
// passing "url" in config object
|
||||||
expect(function() {
|
expect(function() {
|
||||||
source = new Zoomify({
|
source = new Zoomify({
|
||||||
url: 'some-url'
|
url: 'some-url'
|
||||||
@@ -70,6 +70,14 @@ describe('ol.source.Zoomify', function() {
|
|||||||
source = new Zoomify({
|
source = new Zoomify({
|
||||||
size: [47, 11]
|
size: [47, 11]
|
||||||
});
|
});
|
||||||
|
}).to.throwException();
|
||||||
|
|
||||||
|
// passing "size" and "url" in config object
|
||||||
|
expect(function() {
|
||||||
|
source = new Zoomify({
|
||||||
|
url: '',
|
||||||
|
size: [47, 11]
|
||||||
|
});
|
||||||
}).to.not.throwException();
|
}).to.not.throwException();
|
||||||
// we got a source
|
// we got a source
|
||||||
expect(source).to.be.a(Zoomify);
|
expect(source).to.be.a(Zoomify);
|
||||||
@@ -88,6 +96,7 @@ describe('ol.source.Zoomify', function() {
|
|||||||
it('does not need "tierSizeCalculation" option', function() {
|
it('does not need "tierSizeCalculation" option', function() {
|
||||||
expect(function() {
|
expect(function() {
|
||||||
new Zoomify({
|
new Zoomify({
|
||||||
|
url: '',
|
||||||
size: [47, 11]
|
size: [47, 11]
|
||||||
});
|
});
|
||||||
}).to.not.throwException();
|
}).to.not.throwException();
|
||||||
@@ -96,6 +105,7 @@ describe('ol.source.Zoomify', function() {
|
|||||||
it('accepts "tierSizeCalculation" option "default"', function() {
|
it('accepts "tierSizeCalculation" option "default"', function() {
|
||||||
expect(function() {
|
expect(function() {
|
||||||
new Zoomify({
|
new Zoomify({
|
||||||
|
url: '',
|
||||||
size: [47, 11],
|
size: [47, 11],
|
||||||
tierSizeCalculation: 'default'
|
tierSizeCalculation: 'default'
|
||||||
});
|
});
|
||||||
@@ -105,6 +115,7 @@ describe('ol.source.Zoomify', function() {
|
|||||||
it('accepts "tierSizeCalculation" option "truncated"', function() {
|
it('accepts "tierSizeCalculation" option "truncated"', function() {
|
||||||
expect(function() {
|
expect(function() {
|
||||||
new Zoomify({
|
new Zoomify({
|
||||||
|
url: '',
|
||||||
size: [47, 11],
|
size: [47, 11],
|
||||||
tierSizeCalculation: 'truncated'
|
tierSizeCalculation: 'truncated'
|
||||||
});
|
});
|
||||||
@@ -115,6 +126,7 @@ describe('ol.source.Zoomify', function() {
|
|||||||
// passing unknown string will throw
|
// passing unknown string will throw
|
||||||
expect(function() {
|
expect(function() {
|
||||||
new Zoomify({
|
new Zoomify({
|
||||||
|
url: '',
|
||||||
size: [47, 11],
|
size: [47, 11],
|
||||||
tierSizeCalculation: 'ace-of-spades'
|
tierSizeCalculation: 'ace-of-spades'
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user