Merge pull request #6475 from fredj/zoomify_url_template
Use an url template for ol.source.Zoomify
This commit is contained in:
@@ -2,6 +2,15 @@
|
|||||||
|
|
||||||
### Next release
|
### Next release
|
||||||
|
|
||||||
|
#### Simpler `ol.source.Zoomify` `url` configuration
|
||||||
|
|
||||||
|
Instead specifying a base url, the `url` for the `ol.source.Zoomify` source can now be a template. The `{TileGroup}`, `{x}`, `{y}`, `{z}` and placeholders must be included in the `url` in this case. the `url` can now also include subdomain placeholders:
|
||||||
|
```js
|
||||||
|
new ol.source.Zoomify({
|
||||||
|
url: 'https://{a-f}.example.com/cgi-bin/iipsrv.fcgi?zoomify=/a/b/{TileGroup}/{z}-{x}-{y}.jpg'
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
#### Removal of deprecated methods
|
#### Removal of deprecated methods
|
||||||
|
|
||||||
The deprecated `ol.animation` functions and `map.beforeRender()` method have been removed. Use `view.animate()` instead.
|
The deprecated `ol.animation` functions and `map.beforeRender()` method have been removed. Use `view.animate()` instead.
|
||||||
|
|||||||
+7
-1
@@ -6759,7 +6759,13 @@ olx.source.ZoomifyOptions.prototype.reprojectionErrorThreshold;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prefix of URL template.
|
* URL template or base URL of the Zoomify service. A base URL is the fixed part
|
||||||
|
* 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
|
||||||
|
* `{TileGroup}`, `{x}`, `{y}`, and `{z}` placeholders, e.g.
|
||||||
|
* `http://my.zoomify.info/IMAGE.TIF/{TileGroup}/{z}-{x}-{y}.jpg`.
|
||||||
|
* A `{?-?}` template pattern, for example `subdomain{a-f}.domain.com`, may be
|
||||||
|
* used instead of defining each one separately in the `urls` option.
|
||||||
* @type {!string}
|
* @type {!string}
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
|
|||||||
+41
-20
@@ -3,6 +3,7 @@ goog.provide('ol.source.Zoomify');
|
|||||||
goog.require('ol');
|
goog.require('ol');
|
||||||
goog.require('ol.ImageTile');
|
goog.require('ol.ImageTile');
|
||||||
goog.require('ol.TileState');
|
goog.require('ol.TileState');
|
||||||
|
goog.require('ol.TileUrlFunction');
|
||||||
goog.require('ol.asserts');
|
goog.require('ol.asserts');
|
||||||
goog.require('ol.dom');
|
goog.require('ol.dom');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
@@ -83,31 +84,51 @@ ol.source.Zoomify = function(opt_options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var url = options.url;
|
var url = options.url;
|
||||||
|
if (url && url.indexOf('{TileGroup}') == -1) {
|
||||||
|
url += '{TileGroup}/{z}-{x}-{y}.jpg';
|
||||||
|
}
|
||||||
|
var urls = ol.TileUrlFunction.expandUrl(url);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @this {ol.source.TileImage}
|
* @param {string} template Template.
|
||||||
* @param {ol.TileCoord} tileCoord Tile Coordinate.
|
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||||
* @param {number} pixelRatio Pixel ratio.
|
|
||||||
* @param {ol.proj.Projection} projection Projection.
|
|
||||||
* @return {string|undefined} Tile URL.
|
|
||||||
*/
|
*/
|
||||||
function tileUrlFunction(tileCoord, pixelRatio, projection) {
|
function createFromTemplate(template) {
|
||||||
if (!tileCoord) {
|
|
||||||
return undefined;
|
return (
|
||||||
} else {
|
/**
|
||||||
var tileCoordZ = tileCoord[0];
|
* @param {ol.TileCoord} tileCoord Tile Coordinate.
|
||||||
var tileCoordX = tileCoord[1];
|
* @param {number} pixelRatio Pixel ratio.
|
||||||
var tileCoordY = -tileCoord[2] - 1;
|
* @param {ol.proj.Projection} projection Projection.
|
||||||
var tileIndex =
|
* @return {string|undefined} Tile URL.
|
||||||
tileCoordX +
|
*/
|
||||||
tileCoordY * tierSizeInTiles[tileCoordZ][0] +
|
function(tileCoord, pixelRatio, projection) {
|
||||||
tileCountUpToTier[tileCoordZ];
|
if (!tileCoord) {
|
||||||
var tileGroup = (tileIndex / ol.DEFAULT_TILE_SIZE) | 0;
|
return undefined;
|
||||||
return url + 'TileGroup' + tileGroup + '/' +
|
} else {
|
||||||
tileCoordZ + '-' + tileCoordX + '-' + tileCoordY + '.jpg';
|
var tileCoordZ = tileCoord[0];
|
||||||
}
|
var tileCoordX = tileCoord[1];
|
||||||
|
var tileCoordY = -tileCoord[2] - 1;
|
||||||
|
var tileIndex =
|
||||||
|
tileCoordX +
|
||||||
|
tileCoordY * tierSizeInTiles[tileCoordZ][0] +
|
||||||
|
tileCountUpToTier[tileCoordZ];
|
||||||
|
var tileGroup = (tileIndex / ol.DEFAULT_TILE_SIZE) | 0;
|
||||||
|
var localContext = {
|
||||||
|
'z': tileCoordZ,
|
||||||
|
'x': tileCoordX,
|
||||||
|
'y': tileCoordY,
|
||||||
|
'TileGroup': 'TileGroup' + tileGroup
|
||||||
|
};
|
||||||
|
return template.replace(/\{(\w+?)\}/g, function(m, p) {
|
||||||
|
return localContext[p];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(urls.map(createFromTemplate));
|
||||||
|
|
||||||
ol.source.TileImage.call(this, {
|
ol.source.TileImage.call(this, {
|
||||||
attributions: options.attributions,
|
attributions: options.attributions,
|
||||||
cacheSize: options.cacheSize,
|
cacheSize: options.cacheSize,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ describe('ol.source.Zoomify', function() {
|
|||||||
var w = 1024;
|
var w = 1024;
|
||||||
var h = 512;
|
var h = 512;
|
||||||
var size = [w, h];
|
var size = [w, h];
|
||||||
var url = 'zoomify-url/';
|
var url = 'zoomify-url/{TileGroup}/{z}-{x}-{y}.jpg';
|
||||||
var proj = new ol.proj.Projection({
|
var proj = new ol.proj.Projection({
|
||||||
code: 'ZOOMIFY',
|
code: 'ZOOMIFY',
|
||||||
units: 'pixels',
|
units: 'pixels',
|
||||||
@@ -167,7 +167,7 @@ describe('ol.source.Zoomify', function() {
|
|||||||
|
|
||||||
describe('generated tileUrlFunction', function() {
|
describe('generated tileUrlFunction', function() {
|
||||||
|
|
||||||
it('creates an expected tileUrlFunction', function() {
|
it('creates an expected tileUrlFunction with template', function() {
|
||||||
var source = getZoomifySource();
|
var source = getZoomifySource();
|
||||||
var tileUrlFunction = source.getTileUrlFunction();
|
var tileUrlFunction = source.getTileUrlFunction();
|
||||||
// zoomlevel 0
|
// zoomlevel 0
|
||||||
@@ -179,6 +179,20 @@ describe('ol.source.Zoomify', function() {
|
|||||||
expect(tileUrlFunction([1, 1, -2])).to.eql('zoomify-url/TileGroup0/1-1-1.jpg');
|
expect(tileUrlFunction([1, 1, -2])).to.eql('zoomify-url/TileGroup0/1-1-1.jpg');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('creates an expected tileUrlFunction without template', function() {
|
||||||
|
var source = new ol.source.Zoomify({
|
||||||
|
url: 'zoomify-url/',
|
||||||
|
size: size
|
||||||
|
});
|
||||||
|
var tileUrlFunction = source.getTileUrlFunction();
|
||||||
|
// zoomlevel 0
|
||||||
|
expect(tileUrlFunction([0, 0, -1])).to.eql('zoomify-url/TileGroup0/0-0-0.jpg');
|
||||||
|
// zoomlevel 1
|
||||||
|
expect(tileUrlFunction([1, 0, -1])).to.eql('zoomify-url/TileGroup0/1-0-0.jpg');
|
||||||
|
expect(tileUrlFunction([1, 1, -1])).to.eql('zoomify-url/TileGroup0/1-1-0.jpg');
|
||||||
|
expect(tileUrlFunction([1, 0, -2])).to.eql('zoomify-url/TileGroup0/1-0-1.jpg');
|
||||||
|
expect(tileUrlFunction([1, 1, -2])).to.eql('zoomify-url/TileGroup0/1-1-1.jpg');
|
||||||
|
});
|
||||||
it('returns undefined if no tileCoord passed', function() {
|
it('returns undefined if no tileCoord passed', function() {
|
||||||
var source = getZoomifySource();
|
var source = getZoomifySource();
|
||||||
var tileUrlFunction = source.getTileUrlFunction();
|
var tileUrlFunction = source.getTileUrlFunction();
|
||||||
|
|||||||
Reference in New Issue
Block a user