diff --git a/examples/wmts-layer-from-capabilities.js b/examples/wmts-layer-from-capabilities.js index 921912588f..c84850f426 100644 --- a/examples/wmts-layer-from-capabilities.js +++ b/examples/wmts-layer-from-capabilities.js @@ -2,7 +2,6 @@ goog.require('ol.Map'); goog.require('ol.View'); goog.require('ol.format.WMTSCapabilities'); goog.require('ol.layer.Tile'); -goog.require('ol.proj'); goog.require('ol.source.OSM'); goog.require('ol.source.WMTS'); @@ -14,8 +13,6 @@ $.ajax('data/WMTSCapabilities.xml').then(function(response) { var options = ol.source.WMTS.optionsFromCapabilities(result, {layer: 'layer-7328', matrixSet: 'EPSG:3857'}); - var projection = ol.proj.get('EPSG:3857'); - var projectionExtent = projection.getExtent(); map = new ol.Map({ layers: [ new ol.layer.Tile({ @@ -24,7 +21,6 @@ $.ajax('data/WMTSCapabilities.xml').then(function(response) { }), new ol.layer.Tile({ opacity: 1, - extent: projectionExtent, source: new ol.source.WMTS(options) }) ], diff --git a/examples/wmts.js b/examples/wmts.js index b8daeb176a..0b3d2bd456 100644 --- a/examples/wmts.js +++ b/examples/wmts.js @@ -35,7 +35,6 @@ var map = new ol.Map({ }), new ol.layer.Tile({ opacity: 0.7, - extent: projectionExtent, source: new ol.source.WMTS({ attributions: [attribution], url: 'http://services.arcgisonline.com/arcgis/rest/' + @@ -49,7 +48,8 @@ var map = new ol.Map({ resolutions: resolutions, matrixIds: matrixIds }), - style: 'default' + style: 'default', + wrapX: true }) }) ], diff --git a/externs/olx.js b/externs/olx.js index be41aa7676..33c38bf9cc 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -5530,7 +5530,8 @@ olx.source.StaticVectorOptions.prototype.urls; * urls: (Array.|undefined), * tileClass: (function(new: ol.ImageTile, ol.TileCoord, * ol.TileState, string, ?string, - * ol.TileLoadFunctionType)|undefined)}} + * ol.TileLoadFunctionType)|undefined), + * wrapX: (boolean|undefined)}} * @api */ olx.source.WMTSOptions; @@ -5689,6 +5690,14 @@ olx.source.WMTSOptions.prototype.tileLoadFunction; olx.source.WMTSOptions.prototype.urls; +/** + * Whether to wrap the world horizontally. Default is `false`. + * @type {boolean|undefined} + * @api + */ +olx.source.WMTSOptions.prototype.wrapX; + + /** * @typedef {{attributions: (Array.|undefined), * crossOrigin: (null|string|undefined), diff --git a/src/ol/source/wmtssource.js b/src/ol/source/wmtssource.js index 2fca62db1e..19fb88f5e5 100644 --- a/src/ol/source/wmtssource.js +++ b/src/ol/source/wmtssource.js @@ -3,7 +3,6 @@ goog.provide('ol.source.WMTSRequestEncoding'); goog.require('goog.array'); goog.require('goog.asserts'); -goog.require('goog.math'); goog.require('goog.object'); goog.require('goog.string'); goog.require('goog.uri.utils'); @@ -170,7 +169,6 @@ ol.source.WMTS = function(options) { } var tmpExtent = ol.extent.createEmpty(); - var tmpTileCoord = [0, 0, 0]; tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform( /** * @param {ol.TileCoord} tileCoord Tile coordinate. @@ -188,16 +186,6 @@ ol.source.WMTS = function(options) { var tileExtent = tileGrid.getTileCoordExtent(tileCoord, tmpExtent); var extent = projection.getExtent(); - if (!goog.isNull(extent) && projection.isGlobal()) { - var numCols = Math.ceil( - ol.extent.getWidth(extent) / - ol.extent.getWidth(tileExtent)); - x = goog.math.modulo(x, numCols); - tmpTileCoord[0] = tileCoord[0]; - tmpTileCoord[1] = x; - tmpTileCoord[2] = tileCoord[2]; - tileExtent = tileGrid.getTileCoordExtent(tmpTileCoord, tmpExtent); - } if (!ol.extent.intersects(tileExtent, extent) || ol.extent.touches(tileExtent, extent)) { return null; @@ -215,7 +203,8 @@ ol.source.WMTS = function(options) { tileGrid: tileGrid, tileLoadFunction: options.tileLoadFunction, tilePixelRatio: options.tilePixelRatio, - tileUrlFunction: tileUrlFunction + tileUrlFunction: tileUrlFunction, + wrapX: goog.isDef(options.wrapX) ? options.wrapX : false }); }; @@ -348,7 +337,7 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) { goog.asserts.assert(!goog.isNull(l)); goog.asserts.assert(l['TileMatrixSetLink'].length > 0); - var idx, matrixSet; + var idx, matrixSet, wrapX; if (l['TileMatrixSetLink'].length > 1) { idx = goog.array.findIndex(l['TileMatrixSetLink'], function(elt, index, array) { @@ -372,6 +361,13 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) { goog.asserts.assert(!goog.isNull(matrixSet)); + var wgs84BoundingBox = l['WGS84BoundingBox']; + if (goog.isDef(wgs84BoundingBox)) { + var wgs84ProjectionExtent = ol.proj.get('EPSG:4326').getExtent(); + wrapX = (wgs84BoundingBox[0] == wgs84ProjectionExtent[0] && + wgs84BoundingBox[2] == wgs84ProjectionExtent[2]); + } + var format = /** @type {string} */ (l['Format'][0]); if (goog.isDef(config['format'])) { format = config['format']; @@ -463,7 +459,8 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) { requestEncoding: requestEncoding, tileGrid: tileGrid, style: style, - dimensions: dimensions + dimensions: dimensions, + wrapX: wrapX }; /* jshint +W069 */