Manual class transform

This commit is contained in:
Tim Schaub
2018-07-16 17:09:50 -06:00
parent 7b4a73f3b9
commit f78d0d4cfa
96 changed files with 8112 additions and 7964 deletions

View File

@@ -51,18 +51,23 @@ const ImageSourceEventType = {
* @param {string} type Type.
* @param {module:ol/Image} image The image.
*/
const ImageSourceEvent = function(type, image) {
class ImageSourceEvent {
Event.call(this, type);
constructor(type, image) {
/**
* The image related to the event.
* @type {module:ol/Image}
* @api
*/
this.image = image;
Event.call(this, type);
/**
* The image related to the event.
* @type {module:ol/Image}
* @api
*/
this.image = image;
}
}
};
inherits(ImageSourceEvent, Event);

View File

@@ -50,36 +50,40 @@ export const ATTRIBUTION = '© ' +
* @param {module:ol/source/OSM~Options=} [opt_options] Open Street Map options.
* @api
*/
const OSM = function(opt_options) {
class OSM {
const options = opt_options || {};
constructor(opt_options) {
const options = opt_options || {};
let attributions;
if (options.attributions !== undefined) {
attributions = options.attributions;
} else {
attributions = [ATTRIBUTION];
}
const crossOrigin = options.crossOrigin !== undefined ?
options.crossOrigin : 'anonymous';
const url = options.url !== undefined ?
options.url : 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png';
XYZ.call(this, {
attributions: attributions,
cacheSize: options.cacheSize,
crossOrigin: crossOrigin,
opaque: options.opaque !== undefined ? options.opaque : true,
maxZoom: options.maxZoom !== undefined ? options.maxZoom : 19,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileLoadFunction: options.tileLoadFunction,
url: url,
wrapX: options.wrapX
});
let attributions;
if (options.attributions !== undefined) {
attributions = options.attributions;
} else {
attributions = [ATTRIBUTION];
}
const crossOrigin = options.crossOrigin !== undefined ?
options.crossOrigin : 'anonymous';
const url = options.url !== undefined ?
options.url : 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png';
XYZ.call(this, {
attributions: attributions,
cacheSize: options.cacheSize,
crossOrigin: crossOrigin,
opaque: options.opaque !== undefined ? options.opaque : true,
maxZoom: options.maxZoom !== undefined ? options.maxZoom : 19,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileLoadFunction: options.tileLoadFunction,
url: url,
wrapX: options.wrapX
});
};
}
inherits(OSM, XYZ);

View File

@@ -83,32 +83,37 @@ const RasterOperationType = {
* @param {module:ol/PluggableMap~FrameState} frameState The frame state.
* @param {Object} data An object made available to operations.
*/
const RasterSourceEvent = function(type, frameState, data) {
Event.call(this, type);
class RasterSourceEvent {
/**
* The raster extent.
* @type {module:ol/extent~Extent}
* @api
*/
this.extent = frameState.extent;
constructor(type, frameState, data) {
Event.call(this, type);
/**
* The pixel resolution (map units per pixel).
* @type {number}
* @api
*/
this.resolution = frameState.viewState.resolution / frameState.pixelRatio;
/**
* The raster extent.
* @type {module:ol/extent~Extent}
* @api
*/
this.extent = frameState.extent;
/**
* An object made available to all operations. This can be used by operations
* as a storage object (e.g. for calculating statistics).
* @type {Object}
* @api
*/
this.data = data;
/**
* The pixel resolution (map units per pixel).
* @type {number}
* @api
*/
this.resolution = frameState.viewState.resolution / frameState.pixelRatio;
/**
* An object made available to all operations. This can be used by operations
* as a storage object (e.g. for calculating statistics).
* @type {Object}
* @api
*/
this.data = data;
}
}
};
inherits(RasterSourceEvent, Event);
/**

View File

@@ -118,30 +118,35 @@ const ProviderConfig = {
* @param {module:ol/source/Stamen~Options=} options Stamen options.
* @api
*/
const Stamen = function(options) {
const i = options.layer.indexOf('-');
const provider = i == -1 ? options.layer : options.layer.slice(0, i);
const providerConfig = ProviderConfig[provider];
class Stamen {
const layerConfig = LayerConfig[options.layer];
constructor(options) {
const i = options.layer.indexOf('-');
const provider = i == -1 ? options.layer : options.layer.slice(0, i);
const providerConfig = ProviderConfig[provider];
const url = options.url !== undefined ? options.url :
'https://stamen-tiles-{a-d}.a.ssl.fastly.net/' + options.layer +
'/{z}/{x}/{y}.' + layerConfig.extension;
const layerConfig = LayerConfig[options.layer];
XYZ.call(this, {
attributions: ATTRIBUTIONS,
cacheSize: options.cacheSize,
crossOrigin: 'anonymous',
maxZoom: options.maxZoom != undefined ? options.maxZoom : providerConfig.maxZoom,
minZoom: options.minZoom != undefined ? options.minZoom : providerConfig.minZoom,
opaque: layerConfig.opaque,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileLoadFunction: options.tileLoadFunction,
url: url,
wrapX: options.wrapX
});
};
const url = options.url !== undefined ? options.url :
'https://stamen-tiles-{a-d}.a.ssl.fastly.net/' + options.layer +
'/{z}/{x}/{y}.' + layerConfig.extension;
XYZ.call(this, {
attributions: ATTRIBUTIONS,
cacheSize: options.cacheSize,
crossOrigin: 'anonymous',
maxZoom: options.maxZoom != undefined ? options.maxZoom : providerConfig.maxZoom,
minZoom: options.minZoom != undefined ? options.minZoom : providerConfig.minZoom,
opaque: layerConfig.opaque,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileLoadFunction: options.tileLoadFunction,
url: url,
wrapX: options.wrapX
});
}
}
inherits(Stamen, XYZ);

View File

@@ -318,18 +318,23 @@ TileSource.prototype.useTile = UNDEFINED;
* @param {string} type Type.
* @param {module:ol/Tile} tile The tile.
*/
export const TileSourceEvent = function(type, tile) {
export class TileSourceEvent {
Event.call(this, type);
constructor(type, tile) {
/**
* The tile related to the event.
* @type {module:ol/Tile}
* @api
*/
this.tile = tile;
Event.call(this, type);
/**
* The tile related to the event.
* @type {module:ol/Tile}
* @api
*/
this.tile = tile;
}
}
};
inherits(TileSourceEvent, Event);
export default TileSource;

View File

@@ -27,54 +27,59 @@ import {createXYZ, extentFromProjection} from '../tilegrid.js';
* @param {boolean} preemptive Load the tile when visible (before it's needed).
* @param {boolean} jsonp Load the tile as a script.
*/
export const CustomTile = function(tileCoord, state, src, extent, preemptive, jsonp) {
export class CustomTile {
Tile.call(this, tileCoord, state);
constructor(tileCoord, state, src, extent, preemptive, jsonp) {
/**
* @private
* @type {string}
*/
this.src_ = src;
Tile.call(this, tileCoord, state);
/**
* @private
* @type {module:ol/extent~Extent}
*/
this.extent_ = extent;
/**
* @private
* @type {string}
*/
this.src_ = src;
/**
* @private
* @type {boolean}
*/
this.preemptive_ = preemptive;
/**
* @private
* @type {module:ol/extent~Extent}
*/
this.extent_ = extent;
/**
* @private
* @type {Array.<string>}
*/
this.grid_ = null;
/**
* @private
* @type {boolean}
*/
this.preemptive_ = preemptive;
/**
* @private
* @type {Array.<string>}
*/
this.keys_ = null;
/**
* @private
* @type {Array.<string>}
*/
this.grid_ = null;
/**
* @private
* @type {Object.<string, Object>|undefined}
*/
this.data_ = null;
/**
* @private
* @type {Array.<string>}
*/
this.keys_ = null;
/**
* @private
* @type {Object.<string, Object>|undefined}
*/
this.data_ = null;
/**
* @private
* @type {boolean}
*/
this.jsonp_ = jsonp;
/**
* @private
* @type {boolean}
*/
this.jsonp_ = jsonp;
}
}
};
inherits(CustomTile, Tile);
@@ -275,54 +280,59 @@ CustomTile.prototype.load = function() {
* @param {module:ol/source/UTFGrid~Options=} options Source options.
* @api
*/
const UTFGrid = function(options) {
TileSource.call(this, {
projection: getProjection('EPSG:3857'),
state: SourceState.LOADING
});
class UTFGrid {
/**
* @private
* @type {boolean}
*/
this.preemptive_ = options.preemptive !== undefined ?
options.preemptive : true;
constructor(options) {
TileSource.call(this, {
projection: getProjection('EPSG:3857'),
state: SourceState.LOADING
});
/**
* @private
* @type {!module:ol/Tile~UrlFunction}
*/
this.tileUrlFunction_ = nullTileUrlFunction;
/**
* @private
* @type {boolean}
*/
this.preemptive_ = options.preemptive !== undefined ?
options.preemptive : true;
/**
* @private
* @type {string|undefined}
*/
this.template_ = undefined;
/**
* @private
* @type {!module:ol/Tile~UrlFunction}
*/
this.tileUrlFunction_ = nullTileUrlFunction;
/**
* @private
* @type {boolean}
*/
this.jsonp_ = options.jsonp || false;
/**
* @private
* @type {string|undefined}
*/
this.template_ = undefined;
if (options.url) {
if (this.jsonp_) {
requestJSONP(options.url, this.handleTileJSONResponse.bind(this),
this.handleTileJSONError.bind(this));
/**
* @private
* @type {boolean}
*/
this.jsonp_ = options.jsonp || false;
if (options.url) {
if (this.jsonp_) {
requestJSONP(options.url, this.handleTileJSONResponse.bind(this),
this.handleTileJSONError.bind(this));
} else {
const client = new XMLHttpRequest();
client.addEventListener('load', this.onXHRLoad_.bind(this));
client.addEventListener('error', this.onXHRError_.bind(this));
client.open('GET', options.url);
client.send();
}
} else if (options.tileJSON) {
this.handleTileJSONResponse(options.tileJSON);
} else {
const client = new XMLHttpRequest();
client.addEventListener('load', this.onXHRLoad_.bind(this));
client.addEventListener('error', this.onXHRError_.bind(this));
client.open('GET', options.url);
client.send();
assert(false, 51); // Either `url` or `tileJSON` options must be provided
}
} else if (options.tileJSON) {
this.handleTileJSONResponse(options.tileJSON);
} else {
assert(false, 51); // Either `url` or `tileJSON` options must be provided
}
};
}
inherits(UTFGrid, TileSource);

View File

@@ -41,18 +41,23 @@ import RBush from '../structs/RBush.js';
* @param {string} type Type.
* @param {module:ol/Feature=} opt_feature Feature.
*/
export const VectorSourceEvent = function(type, opt_feature) {
export class VectorSourceEvent {
Event.call(this, type);
constructor(type, opt_feature) {
/**
* The feature being added or removed.
* @type {module:ol/Feature|undefined}
* @api
*/
this.feature = opt_feature;
Event.call(this, type);
/**
* The feature being added or removed.
* @type {module:ol/Feature|undefined}
* @api
*/
this.feature = opt_feature;
}
}
};
inherits(VectorSourceEvent, Event);
@@ -158,120 +163,124 @@ inherits(VectorSourceEvent, Event);
* @param {module:ol/source/Vector~Options=} opt_options Vector source options.
* @api
*/
const VectorSource = function(opt_options) {
class VectorSource {
const options = opt_options || {};
constructor(opt_options) {
Source.call(this, {
attributions: options.attributions,
projection: undefined,
state: SourceState.READY,
wrapX: options.wrapX !== undefined ? options.wrapX : true
});
const options = opt_options || {};
/**
* @private
* @type {module:ol/featureloader~FeatureLoader}
*/
this.loader_ = UNDEFINED;
Source.call(this, {
attributions: options.attributions,
projection: undefined,
state: SourceState.READY,
wrapX: options.wrapX !== undefined ? options.wrapX : true
});
/**
* @private
* @type {module:ol/format/Feature|undefined}
*/
this.format_ = options.format;
/**
* @private
* @type {module:ol/featureloader~FeatureLoader}
*/
this.loader_ = UNDEFINED;
/**
* @private
* @type {boolean}
*/
this.overlaps_ = options.overlaps == undefined ? true : options.overlaps;
/**
* @private
* @type {module:ol/format/Feature|undefined}
*/
this.format_ = options.format;
/**
* @private
* @type {string|module:ol/featureloader~FeatureUrlFunction|undefined}
*/
this.url_ = options.url;
/**
* @private
* @type {boolean}
*/
this.overlaps_ = options.overlaps == undefined ? true : options.overlaps;
/**
* @private
* @type {string|module:ol/featureloader~FeatureUrlFunction|undefined}
*/
this.url_ = options.url;
if (options.loader !== undefined) {
this.loader_ = options.loader;
} else if (this.url_ !== undefined) {
assert(this.format_, 7); // `format` must be set when `url` is set
// create a XHR feature loader for "url" and "format"
this.loader_ = xhr(this.url_, /** @type {module:ol/format/Feature} */ (this.format_));
}
/**
* @private
* @type {module:ol/source/Vector~LoadingStrategy}
*/
this.strategy_ = options.strategy !== undefined ? options.strategy : allStrategy;
const useSpatialIndex =
options.useSpatialIndex !== undefined ? options.useSpatialIndex : true;
/**
* @private
* @type {module:ol/structs/RBush.<module:ol/Feature>}
*/
this.featuresRtree_ = useSpatialIndex ? new RBush() : null;
/**
* @private
* @type {module:ol/structs/RBush.<{extent: module:ol/extent~Extent}>}
*/
this.loadedExtentsRtree_ = new RBush();
/**
* @private
* @type {!Object.<string, module:ol/Feature>}
*/
this.nullGeometryFeatures_ = {};
/**
* A lookup of features by id (the return from feature.getId()).
* @private
* @type {!Object.<string, module:ol/Feature>}
*/
this.idIndex_ = {};
/**
* A lookup of features without id (keyed by getUid(feature)).
* @private
* @type {!Object.<string, module:ol/Feature>}
*/
this.undefIdIndex_ = {};
/**
* @private
* @type {Object.<string, Array.<module:ol/events~EventsKey>>}
*/
this.featureChangeKeys_ = {};
/**
* @private
* @type {module:ol/Collection.<module:ol/Feature>}
*/
this.featuresCollection_ = null;
let collection, features;
if (options.features instanceof Collection) {
collection = options.features;
features = collection.getArray();
} else if (Array.isArray(options.features)) {
features = options.features;
}
if (!useSpatialIndex && collection === undefined) {
collection = new Collection(features);
}
if (features !== undefined) {
this.addFeaturesInternal(features);
}
if (collection !== undefined) {
this.bindFeaturesCollection_(collection);
}
if (options.loader !== undefined) {
this.loader_ = options.loader;
} else if (this.url_ !== undefined) {
assert(this.format_, 7); // `format` must be set when `url` is set
// create a XHR feature loader for "url" and "format"
this.loader_ = xhr(this.url_, /** @type {module:ol/format/Feature} */ (this.format_));
}
/**
* @private
* @type {module:ol/source/Vector~LoadingStrategy}
*/
this.strategy_ = options.strategy !== undefined ? options.strategy : allStrategy;
const useSpatialIndex =
options.useSpatialIndex !== undefined ? options.useSpatialIndex : true;
/**
* @private
* @type {module:ol/structs/RBush.<module:ol/Feature>}
*/
this.featuresRtree_ = useSpatialIndex ? new RBush() : null;
/**
* @private
* @type {module:ol/structs/RBush.<{extent: module:ol/extent~Extent}>}
*/
this.loadedExtentsRtree_ = new RBush();
/**
* @private
* @type {!Object.<string, module:ol/Feature>}
*/
this.nullGeometryFeatures_ = {};
/**
* A lookup of features by id (the return from feature.getId()).
* @private
* @type {!Object.<string, module:ol/Feature>}
*/
this.idIndex_ = {};
/**
* A lookup of features without id (keyed by getUid(feature)).
* @private
* @type {!Object.<string, module:ol/Feature>}
*/
this.undefIdIndex_ = {};
/**
* @private
* @type {Object.<string, Array.<module:ol/events~EventsKey>>}
*/
this.featureChangeKeys_ = {};
/**
* @private
* @type {module:ol/Collection.<module:ol/Feature>}
*/
this.featuresCollection_ = null;
let collection, features;
if (options.features instanceof Collection) {
collection = options.features;
features = collection.getArray();
} else if (Array.isArray(options.features)) {
features = options.features;
}
if (!useSpatialIndex && collection === undefined) {
collection = new Collection(features);
}
if (features !== undefined) {
this.addFeaturesInternal(features);
}
if (collection !== undefined) {
this.bindFeaturesCollection_(collection);
}
};
}
inherits(VectorSource, Source);

View File

@@ -74,66 +74,70 @@ import {createXYZ, extentFromProjection, createForProjection} from '../tilegrid.
* @param {module:ol/source/VectorTile~Options=} options Vector tile options.
* @api
*/
const VectorTile = function(options) {
const projection = options.projection || 'EPSG:3857';
class VectorTile {
const extent = options.extent || extentFromProjection(projection);
constructor(options) {
const projection = options.projection || 'EPSG:3857';
const tileGrid = options.tileGrid || createXYZ({
extent: extent,
maxZoom: options.maxZoom || 22,
minZoom: options.minZoom,
tileSize: options.tileSize || 512
});
const extent = options.extent || extentFromProjection(projection);
UrlTile.call(this, {
attributions: options.attributions,
cacheSize: options.cacheSize !== undefined ? options.cacheSize : 128,
extent: extent,
opaque: false,
projection: projection,
state: options.state,
tileGrid: tileGrid,
tileLoadFunction: options.tileLoadFunction ? options.tileLoadFunction : defaultLoadFunction,
tileUrlFunction: options.tileUrlFunction,
url: options.url,
urls: options.urls,
wrapX: options.wrapX === undefined ? true : options.wrapX,
transition: options.transition
});
const tileGrid = options.tileGrid || createXYZ({
extent: extent,
maxZoom: options.maxZoom || 22,
minZoom: options.minZoom,
tileSize: options.tileSize || 512
});
/**
* @private
* @type {module:ol/format/Feature}
*/
this.format_ = options.format ? options.format : null;
UrlTile.call(this, {
attributions: options.attributions,
cacheSize: options.cacheSize !== undefined ? options.cacheSize : 128,
extent: extent,
opaque: false,
projection: projection,
state: options.state,
tileGrid: tileGrid,
tileLoadFunction: options.tileLoadFunction ? options.tileLoadFunction : defaultLoadFunction,
tileUrlFunction: options.tileUrlFunction,
url: options.url,
urls: options.urls,
wrapX: options.wrapX === undefined ? true : options.wrapX,
transition: options.transition
});
/**
/**
* @private
* @type {Object.<string, module:ol/VectorTile>}
* @type {module:ol/format/Feature}
*/
this.sourceTiles_ = {};
this.format_ = options.format ? options.format : null;
/**
* @private
* @type {boolean}
*/
this.overlaps_ = options.overlaps == undefined ? true : options.overlaps;
/**
* @private
* @type {Object.<string, module:ol/VectorTile>}
*/
this.sourceTiles_ = {};
/**
* @protected
* @type {function(new: module:ol/VectorTile, module:ol/tilecoord~TileCoord, module:ol/TileState, string,
* module:ol/format/Feature, module:ol/Tile~LoadFunction)}
/**
* @private
* @type {boolean}
*/
this.tileClass = options.tileClass ? options.tileClass : Tile;
this.overlaps_ = options.overlaps == undefined ? true : options.overlaps;
/**
* @private
* @type {Object.<string, module:ol/tilegrid/TileGrid>}
*/
this.tileGrids_ = {};
/**
* @protected
* @type {function(new: module:ol/VectorTile, module:ol/tilecoord~TileCoord, module:ol/TileState, string,
* module:ol/format/Feature, module:ol/Tile~LoadFunction)}
*/
this.tileClass = options.tileClass ? options.tileClass : Tile;
};
/**
* @private
* @type {Object.<string, module:ol/tilegrid/TileGrid>}
*/
this.tileGrids_ = {};
}
}
inherits(VectorTile, UrlTile);

View File

@@ -65,157 +65,161 @@ import {appendParams} from '../uri.js';
* @param {module:ol/source/WMTS~Options=} options WMTS options.
* @api
*/
const WMTS = function(options) {
class WMTS {
// TODO: add support for TileMatrixLimits
constructor(options) {
/**
* @private
* @type {string}
*/
this.version_ = options.version !== undefined ? options.version : '1.0.0';
// TODO: add support for TileMatrixLimits
/**
* @private
* @type {string}
*/
this.format_ = options.format !== undefined ? options.format : 'image/jpeg';
/**
* @private
* @type {string}
*/
this.version_ = options.version !== undefined ? options.version : '1.0.0';
/**
* @private
* @type {!Object}
*/
this.dimensions_ = options.dimensions !== undefined ? options.dimensions : {};
/**
* @private
* @type {string}
*/
this.format_ = options.format !== undefined ? options.format : 'image/jpeg';
/**
* @private
* @type {string}
*/
this.layer_ = options.layer;
/**
* @private
* @type {!Object}
*/
this.dimensions_ = options.dimensions !== undefined ? options.dimensions : {};
/**
* @private
* @type {string}
*/
this.matrixSet_ = options.matrixSet;
/**
* @private
* @type {string}
*/
this.layer_ = options.layer;
/**
* @private
* @type {string}
*/
this.style_ = options.style;
/**
* @private
* @type {string}
*/
this.matrixSet_ = options.matrixSet;
let urls = options.urls;
if (urls === undefined && options.url !== undefined) {
urls = expandUrl(options.url);
}
/**
* @private
* @type {string}
*/
this.style_ = options.style;
// FIXME: should we guess this requestEncoding from options.url(s)
// structure? that would mean KVP only if a template is not provided.
let urls = options.urls;
if (urls === undefined && options.url !== undefined) {
urls = expandUrl(options.url);
}
/**
* @private
* @type {module:ol/source/WMTSRequestEncoding}
*/
this.requestEncoding_ = options.requestEncoding !== undefined ?
/** @type {module:ol/source/WMTSRequestEncoding} */ (options.requestEncoding) :
WMTSRequestEncoding.KVP;
// FIXME: should we guess this requestEncoding from options.url(s)
// structure? that would mean KVP only if a template is not provided.
const requestEncoding = this.requestEncoding_;
/**
* @private
* @type {module:ol/source/WMTSRequestEncoding}
*/
this.requestEncoding_ = options.requestEncoding !== undefined ?
/** @type {module:ol/source/WMTSRequestEncoding} */ (options.requestEncoding) :
WMTSRequestEncoding.KVP;
// FIXME: should we create a default tileGrid?
// we could issue a getCapabilities xhr to retrieve missing configuration
const tileGrid = options.tileGrid;
const requestEncoding = this.requestEncoding_;
// context property names are lower case to allow for a case insensitive
// replacement as some services use different naming conventions
const context = {
'layer': this.layer_,
'style': this.style_,
'tilematrixset': this.matrixSet_
};
// FIXME: should we create a default tileGrid?
// we could issue a getCapabilities xhr to retrieve missing configuration
const tileGrid = options.tileGrid;
if (requestEncoding == WMTSRequestEncoding.KVP) {
assign(context, {
'Service': 'WMTS',
'Request': 'GetTile',
'Version': this.version_,
'Format': this.format_
});
}
// context property names are lower case to allow for a case insensitive
// replacement as some services use different naming conventions
const context = {
'layer': this.layer_,
'style': this.style_,
'tilematrixset': this.matrixSet_
};
const dimensions = this.dimensions_;
/**
* @param {string} template Template.
* @return {module:ol/Tile~UrlFunction} Tile URL function.
* @private
*/
this.createFromWMTSTemplate_ = function(template) {
// TODO: we may want to create our own appendParams function so that params
// order conforms to wmts spec guidance, and so that we can avoid to escape
// special template params
template = (requestEncoding == WMTSRequestEncoding.KVP) ?
appendParams(template, context) :
template.replace(/\{(\w+?)\}/g, function(m, p) {
return (p.toLowerCase() in context) ? context[p.toLowerCase()] : m;
if (requestEncoding == WMTSRequestEncoding.KVP) {
assign(context, {
'Service': 'WMTS',
'Request': 'GetTile',
'Version': this.version_,
'Format': this.format_
});
}
return (
/**
* @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate.
* @param {number} pixelRatio Pixel ratio.
* @param {module:ol/proj/Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, pixelRatio, projection) {
if (!tileCoord) {
return undefined;
} else {
const localContext = {
'TileMatrix': tileGrid.getMatrixId(tileCoord[0]),
'TileCol': tileCoord[1],
'TileRow': -tileCoord[2] - 1
};
assign(localContext, dimensions);
let url = template;
if (requestEncoding == WMTSRequestEncoding.KVP) {
url = appendParams(url, localContext);
const dimensions = this.dimensions_;
/**
* @param {string} template Template.
* @return {module:ol/Tile~UrlFunction} Tile URL function.
* @private
*/
this.createFromWMTSTemplate_ = function(template) {
// TODO: we may want to create our own appendParams function so that params
// order conforms to wmts spec guidance, and so that we can avoid to escape
// special template params
template = (requestEncoding == WMTSRequestEncoding.KVP) ?
appendParams(template, context) :
template.replace(/\{(\w+?)\}/g, function(m, p) {
return (p.toLowerCase() in context) ? context[p.toLowerCase()] : m;
});
return (
/**
* @param {module:ol/tilecoord~TileCoord} tileCoord Tile coordinate.
* @param {number} pixelRatio Pixel ratio.
* @param {module:ol/proj/Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, pixelRatio, projection) {
if (!tileCoord) {
return undefined;
} else {
url = url.replace(/\{(\w+?)\}/g, function(m, p) {
return localContext[p];
});
const localContext = {
'TileMatrix': tileGrid.getMatrixId(tileCoord[0]),
'TileCol': tileCoord[1],
'TileRow': -tileCoord[2] - 1
};
assign(localContext, dimensions);
let url = template;
if (requestEncoding == WMTSRequestEncoding.KVP) {
url = appendParams(url, localContext);
} else {
url = url.replace(/\{(\w+?)\}/g, function(m, p) {
return localContext[p];
});
}
return url;
}
return url;
}
}
);
};
);
};
const tileUrlFunction = (urls && urls.length > 0) ?
createFromTileUrlFunctions(urls.map(this.createFromWMTSTemplate_)) : nullTileUrlFunction;
const tileUrlFunction = (urls && urls.length > 0) ?
createFromTileUrlFunctions(urls.map(this.createFromWMTSTemplate_)) : nullTileUrlFunction;
TileImage.call(this, {
attributions: options.attributions,
cacheSize: options.cacheSize,
crossOrigin: options.crossOrigin,
projection: options.projection,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileClass: options.tileClass,
tileGrid: tileGrid,
tileLoadFunction: options.tileLoadFunction,
tilePixelRatio: options.tilePixelRatio,
tileUrlFunction: tileUrlFunction,
urls: urls,
wrapX: options.wrapX !== undefined ? options.wrapX : false,
transition: options.transition
});
TileImage.call(this, {
attributions: options.attributions,
cacheSize: options.cacheSize,
crossOrigin: options.crossOrigin,
projection: options.projection,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileClass: options.tileClass,
tileGrid: tileGrid,
tileLoadFunction: options.tileLoadFunction,
tilePixelRatio: options.tilePixelRatio,
tileUrlFunction: tileUrlFunction,
urls: urls,
wrapX: options.wrapX !== undefined ? options.wrapX : false,
transition: options.transition
});
this.setKey(this.getKeyForDimensions_());
this.setKey(this.getKeyForDimensions_());
};
}
}
inherits(WMTS, TileImage);

View File

@@ -66,37 +66,42 @@ import {createXYZ, extentFromProjection} from '../tilegrid.js';
* @param {module:ol/source/XYZ~Options=} opt_options XYZ options.
* @api
*/
const XYZ = function(opt_options) {
const options = opt_options || {};
const projection = options.projection !== undefined ?
options.projection : 'EPSG:3857';
class XYZ {
const tileGrid = options.tileGrid !== undefined ? options.tileGrid :
createXYZ({
extent: extentFromProjection(projection),
maxZoom: options.maxZoom,
minZoom: options.minZoom,
tileSize: options.tileSize
constructor(opt_options) {
const options = opt_options || {};
const projection = options.projection !== undefined ?
options.projection : 'EPSG:3857';
const tileGrid = options.tileGrid !== undefined ? options.tileGrid :
createXYZ({
extent: extentFromProjection(projection),
maxZoom: options.maxZoom,
minZoom: options.minZoom,
tileSize: options.tileSize
});
TileImage.call(this, {
attributions: options.attributions,
cacheSize: options.cacheSize,
crossOrigin: options.crossOrigin,
opaque: options.opaque,
projection: projection,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileGrid: tileGrid,
tileLoadFunction: options.tileLoadFunction,
tilePixelRatio: options.tilePixelRatio,
tileUrlFunction: options.tileUrlFunction,
url: options.url,
urls: options.urls,
wrapX: options.wrapX !== undefined ? options.wrapX : true,
transition: options.transition
});
TileImage.call(this, {
attributions: options.attributions,
cacheSize: options.cacheSize,
crossOrigin: options.crossOrigin,
opaque: options.opaque,
projection: projection,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileGrid: tileGrid,
tileLoadFunction: options.tileLoadFunction,
tilePixelRatio: options.tilePixelRatio,
tileUrlFunction: options.tileUrlFunction,
url: options.url,
urls: options.urls,
wrapX: options.wrapX !== undefined ? options.wrapX : true,
transition: options.transition
});
}
};
}
inherits(XYZ, TileImage);
export default XYZ;

View File

@@ -34,23 +34,28 @@ const TierSizeCalculation = {
* @param {module:ol/Tile~LoadFunction} tileLoadFunction Tile load function.
* @param {module:ol/Tile~Options=} opt_options Tile options.
*/
export const CustomTile = function(
tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
export class CustomTile {
ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options);
constructor(tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) {
/**
* @private
* @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement}
*/
this.zoomifyImage_ = null;
ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options);
/**
* @private
* @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement}
*/
this.zoomifyImage_ = null;
/**
* @private
* @type {module:ol/size~Size}
*/
this.tileSize_ = toSize(tileGrid.getTileSize(tileCoord[0]));
}
}
/**
* @private
* @type {module:ol/size~Size}
*/
this.tileSize_ = toSize(tileGrid.getTileSize(tileCoord[0]));
};
inherits(CustomTile, ImageTile);
@@ -124,135 +129,138 @@ CustomTile.prototype.getImage = function() {
* @param {module:ol/source/Zoomify~Options=} opt_options Options.
* @api
*/
const Zoomify = function(opt_options) {
class Zoomify {
const options = opt_options || {};
constructor(opt_options) {
const size = options.size;
const tierSizeCalculation = options.tierSizeCalculation !== undefined ?
options.tierSizeCalculation :
TierSizeCalculation.DEFAULT;
const options = opt_options || {};
const imageWidth = size[0];
const imageHeight = size[1];
const extent = options.extent || [0, -size[1], size[0], 0];
const tierSizeInTiles = [];
const tileSize = options.tileSize || DEFAULT_TILE_SIZE;
let tileSizeForTierSizeCalculation = tileSize;
const size = options.size;
const tierSizeCalculation = options.tierSizeCalculation !== undefined ?
options.tierSizeCalculation :
TierSizeCalculation.DEFAULT;
switch (tierSizeCalculation) {
case TierSizeCalculation.DEFAULT:
while (imageWidth > tileSizeForTierSizeCalculation || imageHeight > tileSizeForTierSizeCalculation) {
tierSizeInTiles.push([
Math.ceil(imageWidth / tileSizeForTierSizeCalculation),
Math.ceil(imageHeight / tileSizeForTierSizeCalculation)
]);
tileSizeForTierSizeCalculation += tileSizeForTierSizeCalculation;
}
break;
case TierSizeCalculation.TRUNCATED:
let width = imageWidth;
let height = imageHeight;
while (width > tileSizeForTierSizeCalculation || height > tileSizeForTierSizeCalculation) {
tierSizeInTiles.push([
Math.ceil(width / tileSizeForTierSizeCalculation),
Math.ceil(height / tileSizeForTierSizeCalculation)
]);
width >>= 1;
height >>= 1;
}
break;
default:
assert(false, 53); // Unknown `tierSizeCalculation` configured
break;
}
const imageWidth = size[0];
const imageHeight = size[1];
const extent = options.extent || [0, -size[1], size[0], 0];
const tierSizeInTiles = [];
const tileSize = options.tileSize || DEFAULT_TILE_SIZE;
let tileSizeForTierSizeCalculation = tileSize;
tierSizeInTiles.push([1, 1]);
tierSizeInTiles.reverse();
const resolutions = [1];
const tileCountUpToTier = [0];
for (let i = 1, ii = tierSizeInTiles.length; i < ii; i++) {
resolutions.push(1 << i);
tileCountUpToTier.push(
tierSizeInTiles[i - 1][0] * tierSizeInTiles[i - 1][1] +
tileCountUpToTier[i - 1]
);
}
resolutions.reverse();
const tileGrid = new TileGrid({
tileSize: tileSize,
extent: extent,
origin: getTopLeft(extent),
resolutions: resolutions
});
let url = options.url;
if (url && url.indexOf('{TileGroup}') == -1 && url.indexOf('{tileIndex}') == -1) {
url += '{TileGroup}/{z}-{x}-{y}.jpg';
}
const urls = expandUrl(url);
/**
* @param {string} template Template.
* @return {module:ol/Tile~UrlFunction} Tile URL function.
*/
function createFromTemplate(template) {
return (
/**
* @param {module:ol/tilecoord~TileCoord} tileCoord Tile Coordinate.
* @param {number} pixelRatio Pixel ratio.
* @param {module:ol/proj/Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, pixelRatio, projection) {
if (!tileCoord) {
return undefined;
} else {
const tileCoordZ = tileCoord[0];
const tileCoordX = tileCoord[1];
const tileCoordY = -tileCoord[2] - 1;
const tileIndex =
tileCoordX +
tileCoordY * tierSizeInTiles[tileCoordZ][0];
const tileSize = tileGrid.getTileSize(tileCoordZ);
const tileGroup = ((tileIndex + tileCountUpToTier[tileCoordZ]) / tileSize) | 0;
const localContext = {
'z': tileCoordZ,
'x': tileCoordX,
'y': tileCoordY,
'tileIndex': tileIndex,
'TileGroup': 'TileGroup' + tileGroup
};
return template.replace(/\{(\w+?)\}/g, function(m, p) {
return localContext[p];
});
switch (tierSizeCalculation) {
case TierSizeCalculation.DEFAULT:
while (imageWidth > tileSizeForTierSizeCalculation || imageHeight > tileSizeForTierSizeCalculation) {
tierSizeInTiles.push([
Math.ceil(imageWidth / tileSizeForTierSizeCalculation),
Math.ceil(imageHeight / tileSizeForTierSizeCalculation)
]);
tileSizeForTierSizeCalculation += tileSizeForTierSizeCalculation;
}
}
);
break;
case TierSizeCalculation.TRUNCATED:
let width = imageWidth;
let height = imageHeight;
while (width > tileSizeForTierSizeCalculation || height > tileSizeForTierSizeCalculation) {
tierSizeInTiles.push([
Math.ceil(width / tileSizeForTierSizeCalculation),
Math.ceil(height / tileSizeForTierSizeCalculation)
]);
width >>= 1;
height >>= 1;
}
break;
default:
assert(false, 53); // Unknown `tierSizeCalculation` configured
break;
}
tierSizeInTiles.push([1, 1]);
tierSizeInTiles.reverse();
const resolutions = [1];
const tileCountUpToTier = [0];
for (let i = 1, ii = tierSizeInTiles.length; i < ii; i++) {
resolutions.push(1 << i);
tileCountUpToTier.push(
tierSizeInTiles[i - 1][0] * tierSizeInTiles[i - 1][1] +
tileCountUpToTier[i - 1]
);
}
resolutions.reverse();
const tileGrid = new TileGrid({
tileSize: tileSize,
extent: extent,
origin: getTopLeft(extent),
resolutions: resolutions
});
let url = options.url;
if (url && url.indexOf('{TileGroup}') == -1 && url.indexOf('{tileIndex}') == -1) {
url += '{TileGroup}/{z}-{x}-{y}.jpg';
}
const urls = expandUrl(url);
/**
* @param {string} template Template.
* @return {module:ol/Tile~UrlFunction} Tile URL function.
*/
function createFromTemplate(template) {
return (
/**
* @param {module:ol/tilecoord~TileCoord} tileCoord Tile Coordinate.
* @param {number} pixelRatio Pixel ratio.
* @param {module:ol/proj/Projection} projection Projection.
* @return {string|undefined} Tile URL.
*/
function(tileCoord, pixelRatio, projection) {
if (!tileCoord) {
return undefined;
} else {
const tileCoordZ = tileCoord[0];
const tileCoordX = tileCoord[1];
const tileCoordY = -tileCoord[2] - 1;
const tileIndex =
tileCoordX +
tileCoordY * tierSizeInTiles[tileCoordZ][0];
const tileSize = tileGrid.getTileSize(tileCoordZ);
const tileGroup = ((tileIndex + tileCountUpToTier[tileCoordZ]) / tileSize) | 0;
const localContext = {
'z': tileCoordZ,
'x': tileCoordX,
'y': tileCoordY,
'tileIndex': tileIndex,
'TileGroup': 'TileGroup' + tileGroup
};
return template.replace(/\{(\w+?)\}/g, function(m, p) {
return localContext[p];
});
}
}
);
}
const tileUrlFunction = createFromTileUrlFunctions(urls.map(createFromTemplate));
const ZoomifyTileClass = CustomTile.bind(null, tileGrid);
TileImage.call(this, {
attributions: options.attributions,
cacheSize: options.cacheSize,
crossOrigin: options.crossOrigin,
projection: options.projection,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileClass: ZoomifyTileClass,
tileGrid: tileGrid,
tileUrlFunction: tileUrlFunction,
transition: options.transition
});
}
const tileUrlFunction = createFromTileUrlFunctions(urls.map(createFromTemplate));
const ZoomifyTileClass = CustomTile.bind(null, tileGrid);
TileImage.call(this, {
attributions: options.attributions,
cacheSize: options.cacheSize,
crossOrigin: options.crossOrigin,
projection: options.projection,
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
tileClass: ZoomifyTileClass,
tileGrid: tileGrid,
tileUrlFunction: tileUrlFunction,
transition: options.transition
});
};
}
inherits(Zoomify, TileImage);
export default Zoomify;