Transformed

This commit is contained in:
Tim Schaub
2017-12-11 16:29:33 -07:00
parent 1cdb6a66f0
commit 7f47883c48
737 changed files with 22216 additions and 21609 deletions

View File

@@ -1,16 +1,16 @@
goog.provide('ol.source.WMTS');
goog.require('ol');
goog.require('ol.TileUrlFunction');
goog.require('ol.array');
goog.require('ol.extent');
goog.require('ol.obj');
goog.require('ol.proj');
goog.require('ol.source.TileImage');
goog.require('ol.source.WMTSRequestEncoding');
goog.require('ol.tilegrid.WMTS');
goog.require('ol.uri');
/**
* @module ol/source/WMTS
*/
import _ol_ from '../index.js';
import _ol_TileUrlFunction_ from '../TileUrlFunction.js';
import _ol_array_ from '../array.js';
import _ol_extent_ from '../extent.js';
import _ol_obj_ from '../obj.js';
import _ol_proj_ from '../proj.js';
import _ol_source_TileImage_ from '../source/TileImage.js';
import _ol_source_WMTSRequestEncoding_ from '../source/WMTSRequestEncoding.js';
import _ol_tilegrid_WMTS_ from '../tilegrid/WMTS.js';
import _ol_uri_ from '../uri.js';
/**
* @classdesc
@@ -21,7 +21,7 @@ goog.require('ol.uri');
* @param {olx.source.WMTSOptions} options WMTS options.
* @api
*/
ol.source.WMTS = function(options) {
var _ol_source_WMTS_ = function(options) {
// TODO: add support for TileMatrixLimits
@@ -63,7 +63,7 @@ ol.source.WMTS = function(options) {
var urls = options.urls;
if (urls === undefined && options.url !== undefined) {
urls = ol.TileUrlFunction.expandUrl(options.url);
urls = _ol_TileUrlFunction_.expandUrl(options.url);
}
// FIXME: should we guess this requestEncoding from options.url(s)
@@ -75,7 +75,7 @@ ol.source.WMTS = function(options) {
*/
this.requestEncoding_ = options.requestEncoding !== undefined ?
/** @type {ol.source.WMTSRequestEncoding} */ (options.requestEncoding) :
ol.source.WMTSRequestEncoding.KVP;
_ol_source_WMTSRequestEncoding_.KVP;
var requestEncoding = this.requestEncoding_;
@@ -91,8 +91,8 @@ ol.source.WMTS = function(options) {
'tilematrixset': this.matrixSet_
};
if (requestEncoding == ol.source.WMTSRequestEncoding.KVP) {
ol.obj.assign(context, {
if (requestEncoding == _ol_source_WMTSRequestEncoding_.KVP) {
_ol_obj_.assign(context, {
'Service': 'WMTS',
'Request': 'GetTile',
'Version': this.version_,
@@ -113,8 +113,8 @@ ol.source.WMTS = function(options) {
// order conforms to wmts spec guidance, and so that we can avoid to escape
// special template params
template = (requestEncoding == ol.source.WMTSRequestEncoding.KVP) ?
ol.uri.appendParams(template, context) :
template = (requestEncoding == _ol_source_WMTSRequestEncoding_.KVP) ?
_ol_uri_.appendParams(template, context) :
template.replace(/\{(\w+?)\}/g, function(m, p) {
return (p.toLowerCase() in context) ? context[p.toLowerCase()] : m;
});
@@ -135,10 +135,10 @@ ol.source.WMTS = function(options) {
'TileCol': tileCoord[1],
'TileRow': -tileCoord[2] - 1
};
ol.obj.assign(localContext, dimensions);
_ol_obj_.assign(localContext, dimensions);
var url = template;
if (requestEncoding == ol.source.WMTSRequestEncoding.KVP) {
url = ol.uri.appendParams(url, localContext);
if (requestEncoding == _ol_source_WMTSRequestEncoding_.KVP) {
url = _ol_uri_.appendParams(url, localContext);
} else {
url = url.replace(/\{(\w+?)\}/g, function(m, p) {
return localContext[p];
@@ -146,15 +146,16 @@ ol.source.WMTS = function(options) {
}
return url;
}
});
}
);
};
var tileUrlFunction = (urls && urls.length > 0) ?
ol.TileUrlFunction.createFromTileUrlFunctions(
_ol_TileUrlFunction_.createFromTileUrlFunctions(
urls.map(this.createFromWMTSTemplate_)) :
ol.TileUrlFunction.nullTileUrlFunction;
_ol_TileUrlFunction_.nullTileUrlFunction;
ol.source.TileImage.call(this, {
_ol_source_TileImage_.call(this, {
attributions: options.attributions,
cacheSize: options.cacheSize,
crossOrigin: options.crossOrigin,
@@ -174,19 +175,20 @@ ol.source.WMTS = function(options) {
this.setKey(this.getKeyForDimensions_());
};
ol.inherits(ol.source.WMTS, ol.source.TileImage);
_ol_.inherits(_ol_source_WMTS_, _ol_source_TileImage_);
/**
* Set the URLs to use for requests.
* URLs may contain OCG conform URL Template Variables: {TileMatrix}, {TileRow}, {TileCol}.
* @override
*/
ol.source.WMTS.prototype.setUrls = function(urls) {
_ol_source_WMTS_.prototype.setUrls = function(urls) {
this.urls = urls;
var key = urls.join('\n');
this.setTileUrlFunction(this.fixedTileUrlFunction ?
this.fixedTileUrlFunction.bind(this) :
ol.TileUrlFunction.createFromTileUrlFunctions(urls.map(this.createFromWMTSTemplate_.bind(this))), key);
_ol_TileUrlFunction_.createFromTileUrlFunctions(urls.map(this.createFromWMTSTemplate_.bind(this))), key);
};
/**
@@ -196,7 +198,7 @@ ol.source.WMTS.prototype.setUrls = function(urls) {
* @return {!Object} Dimensions.
* @api
*/
ol.source.WMTS.prototype.getDimensions = function() {
_ol_source_WMTS_.prototype.getDimensions = function() {
return this.dimensions_;
};
@@ -206,7 +208,7 @@ ol.source.WMTS.prototype.getDimensions = function() {
* @return {string} Format.
* @api
*/
ol.source.WMTS.prototype.getFormat = function() {
_ol_source_WMTS_.prototype.getFormat = function() {
return this.format_;
};
@@ -216,7 +218,7 @@ ol.source.WMTS.prototype.getFormat = function() {
* @return {string} Layer.
* @api
*/
ol.source.WMTS.prototype.getLayer = function() {
_ol_source_WMTS_.prototype.getLayer = function() {
return this.layer_;
};
@@ -226,7 +228,7 @@ ol.source.WMTS.prototype.getLayer = function() {
* @return {string} MatrixSet.
* @api
*/
ol.source.WMTS.prototype.getMatrixSet = function() {
_ol_source_WMTS_.prototype.getMatrixSet = function() {
return this.matrixSet_;
};
@@ -236,7 +238,7 @@ ol.source.WMTS.prototype.getMatrixSet = function() {
* @return {ol.source.WMTSRequestEncoding} Request encoding.
* @api
*/
ol.source.WMTS.prototype.getRequestEncoding = function() {
_ol_source_WMTS_.prototype.getRequestEncoding = function() {
return this.requestEncoding_;
};
@@ -246,7 +248,7 @@ ol.source.WMTS.prototype.getRequestEncoding = function() {
* @return {string} Style.
* @api
*/
ol.source.WMTS.prototype.getStyle = function() {
_ol_source_WMTS_.prototype.getStyle = function() {
return this.style_;
};
@@ -256,7 +258,7 @@ ol.source.WMTS.prototype.getStyle = function() {
* @return {string} Version.
* @api
*/
ol.source.WMTS.prototype.getVersion = function() {
_ol_source_WMTS_.prototype.getVersion = function() {
return this.version_;
};
@@ -265,7 +267,7 @@ ol.source.WMTS.prototype.getVersion = function() {
* @private
* @return {string} The key for the current dimensions.
*/
ol.source.WMTS.prototype.getKeyForDimensions_ = function() {
_ol_source_WMTS_.prototype.getKeyForDimensions_ = function() {
var i = 0;
var res = [];
for (var key in this.dimensions_) {
@@ -280,8 +282,8 @@ ol.source.WMTS.prototype.getKeyForDimensions_ = function() {
* @param {Object} dimensions Dimensions.
* @api
*/
ol.source.WMTS.prototype.updateDimensions = function(dimensions) {
ol.obj.assign(this.dimensions_, dimensions);
_ol_source_WMTS_.prototype.updateDimensions = function(dimensions) {
_ol_obj_.assign(this.dimensions_, dimensions);
this.setKey(this.getKeyForDimensions_());
};
@@ -310,9 +312,9 @@ ol.source.WMTS.prototype.updateDimensions = function(dimensions) {
* @return {?olx.source.WMTSOptions} WMTS source options object or `null` if the layer was not found.
* @api
*/
ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
_ol_source_WMTS_.optionsFromCapabilities = function(wmtsCap, config) {
var layers = wmtsCap['Contents']['Layer'];
var l = ol.array.find(layers, function(elt, index, array) {
var l = _ol_array_.find(layers, function(elt, index, array) {
return elt['Identifier'] == config['layer'];
});
if (l === null) {
@@ -322,23 +324,23 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
var idx, matrixSet, matrixLimits;
if (l['TileMatrixSetLink'].length > 1) {
if ('projection' in config) {
idx = ol.array.findIndex(l['TileMatrixSetLink'],
idx = _ol_array_.findIndex(l['TileMatrixSetLink'],
function(elt, index, array) {
var tileMatrixSet = ol.array.find(tileMatrixSets, function(el) {
var tileMatrixSet = _ol_array_.find(tileMatrixSets, function(el) {
return el['Identifier'] == elt['TileMatrixSet'];
});
var supportedCRS = tileMatrixSet['SupportedCRS'];
var proj1 = ol.proj.get(supportedCRS.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) ||
ol.proj.get(supportedCRS);
var proj2 = ol.proj.get(config['projection']);
var proj1 = _ol_proj_.get(supportedCRS.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) ||
_ol_proj_.get(supportedCRS);
var proj2 = _ol_proj_.get(config['projection']);
if (proj1 && proj2) {
return ol.proj.equivalent(proj1, proj2);
return _ol_proj_.equivalent(proj1, proj2);
} else {
return supportedCRS == config['projection'];
}
});
} else {
idx = ol.array.findIndex(l['TileMatrixSetLink'],
idx = _ol_array_.findIndex(l['TileMatrixSetLink'],
function(elt, index, array) {
return elt['TileMatrixSet'] == config['matrixSet'];
});
@@ -358,7 +360,7 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
if ('format' in config) {
format = config['format'];
}
idx = ol.array.findIndex(l['Style'], function(elt, index, array) {
idx = _ol_array_.findIndex(l['Style'], function(elt, index, array) {
if ('style' in config) {
return elt['Title'] == config['style'];
} else {
@@ -383,20 +385,20 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
}
var matrixSets = wmtsCap['Contents']['TileMatrixSet'];
var matrixSetObj = ol.array.find(matrixSets, function(elt, index, array) {
var matrixSetObj = _ol_array_.find(matrixSets, function(elt, index, array) {
return elt['Identifier'] == matrixSet;
});
var projection;
var code = matrixSetObj['SupportedCRS'];
if (code) {
projection = ol.proj.get(code.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) ||
ol.proj.get(code);
projection = _ol_proj_.get(code.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) ||
_ol_proj_.get(code);
}
if ('projection' in config) {
var projConfig = ol.proj.get(config['projection']);
var projConfig = _ol_proj_.get(config['projection']);
if (projConfig) {
if (!projection || ol.proj.equivalent(projConfig, projection)) {
if (!projection || _ol_proj_.equivalent(projConfig, projection)) {
projection = projConfig;
}
}
@@ -405,22 +407,22 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
var wgs84BoundingBox = l['WGS84BoundingBox'];
var extent, wrapX;
if (wgs84BoundingBox !== undefined) {
var wgs84ProjectionExtent = ol.proj.get('EPSG:4326').getExtent();
var wgs84ProjectionExtent = _ol_proj_.get('EPSG:4326').getExtent();
wrapX = (wgs84BoundingBox[0] == wgs84ProjectionExtent[0] &&
wgs84BoundingBox[2] == wgs84ProjectionExtent[2]);
extent = ol.proj.transformExtent(
extent = _ol_proj_.transformExtent(
wgs84BoundingBox, 'EPSG:4326', projection);
var projectionExtent = projection.getExtent();
if (projectionExtent) {
// If possible, do a sanity check on the extent - it should never be
// bigger than the validity extent of the projection of a matrix set.
if (!ol.extent.containsExtent(projectionExtent, extent)) {
if (!_ol_extent_.containsExtent(projectionExtent, extent)) {
extent = undefined;
}
}
}
var tileGrid = ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet(
var tileGrid = _ol_tilegrid_WMTS_.createFromCapabilitiesMatrixSet(
matrixSetObj, extent, matrixLimits);
/** @type {!Array.<string>} */
@@ -433,7 +435,7 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
for (var i = 0, ii = gets.length; i < ii; ++i) {
if (gets[i]['Constraint']) {
var constraint = ol.array.find(gets[i]['Constraint'], function(element) {
var constraint = _ol_array_.find(gets[i]['Constraint'], function(element) {
return element['name'] == 'GetEncoding';
});
var encodings = constraint['AllowedValues']['Value'];
@@ -442,21 +444,21 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
// requestEncoding not provided, use the first encoding from the list
requestEncoding = encodings[0];
}
if (requestEncoding === ol.source.WMTSRequestEncoding.KVP) {
if (ol.array.includes(encodings, ol.source.WMTSRequestEncoding.KVP)) {
if (requestEncoding === _ol_source_WMTSRequestEncoding_.KVP) {
if (_ol_array_.includes(encodings, _ol_source_WMTSRequestEncoding_.KVP)) {
urls.push(/** @type {string} */ (gets[i]['href']));
}
} else {
break;
}
} else if (gets[i]['href']) {
requestEncoding = ol.source.WMTSRequestEncoding.KVP;
requestEncoding = _ol_source_WMTSRequestEncoding_.KVP;
urls.push(/** @type {string} */ (gets[i]['href']));
}
}
}
if (urls.length === 0) {
requestEncoding = ol.source.WMTSRequestEncoding.REST;
requestEncoding = _ol_source_WMTSRequestEncoding_.REST;
l['ResourceURL'].forEach(function(element) {
if (element['resourceType'] === 'tile') {
format = element['format'];
@@ -479,3 +481,4 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
crossOrigin: config['crossOrigin']
};
};
export default _ol_source_WMTS_;