diff --git a/changelog/upgrade-notes.md b/changelog/upgrade-notes.md index 9dab9b583f..20bc5408b6 100644 --- a/changelog/upgrade-notes.md +++ b/changelog/upgrade-notes.md @@ -2,6 +2,16 @@ ### Next release +#### `ol.source.VectorTile` no longer has a `tilePixelRatio` option + +The `tilePixelRatio` option was only used for tiles in projections with `tile-pixels` as units. For tiles read with `ol.format.MVT` and the default tile loader, or tiles with the default pixel size of 4096 pixels, no changes are necessary. For the very rare cases that do not fall under these categories, a custom `tileLoadFunction` now needs to be configured on the `ol.source.VectorTile`. In addition to calling `tile.setFeatures()` and `tile.setProjection()`, it also needs to contain code like the following: +```js +var extent = tile.getFormat() instanceof ol.format.MVT ? + tile.getLastExtent() : + [0, 0, tilePixelRatio * tileSize, tilePixelRatio * tileSize]; +tile.setExtent(extent); +``` + #### `ol.animate` now takes the shortest arc for rotation animation Usually rotation animations should animate along the shortest arc. There are rare occasions where a spinning animation effect is desired. So if you previously had something like diff --git a/examples/geojson-vt.js b/examples/geojson-vt.js index e891938786..892c4795b4 100644 --- a/examples/geojson-vt.js +++ b/examples/geojson-vt.js @@ -78,7 +78,6 @@ fetch(url).then(function(response) { var vectorSource = new ol.source.VectorTile({ format: new ol.format.GeoJSON(), tileGrid: ol.tilegrid.createXYZ(), - tilePixelRatio: 16, tileLoadFunction: function(tile) { var format = tile.getFormat(); var tileCoord = tile.getTileCoord(); diff --git a/externs/olx.js b/externs/olx.js index 98e545336f..7f31fbdcea 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -4898,7 +4898,6 @@ olx.source.TileImageOptions.prototype.wrapX; * ol.TileLoadFunctionType)|undefined), * tileGrid: (ol.tilegrid.TileGrid|undefined), * tileLoadFunction: (ol.TileLoadFunctionType|undefined), - * tilePixelRatio: (number|undefined), * tileUrlFunction: (ol.TileUrlFunctionType|undefined), * url: (string|undefined), * urls: (Array.|undefined), @@ -5005,19 +5004,6 @@ olx.source.VectorTileOptions.prototype.tileGrid; olx.source.VectorTileOptions.prototype.tileLoadFunction; -/** - * The pixel ratio used by the tile service. For example, if the tile service - * advertizes 512px by 512px tiles but actually sends tiles with coordinates in - * the range of 0..4096 pixels, then `tilePixelRatio` should be set to `8`. - * When {@link ol.format.MVT} is used to parse the features, this setting will - * be overridden by the coordinate range advertized in the tile. - * Default is `1`. - * @type {number|undefined} - * @api - */ -olx.source.VectorTileOptions.prototype.tilePixelRatio; - - /** * Optional function to get tile URL given a tile coordinate and the projection. * @type {ol.TileUrlFunctionType|undefined} diff --git a/src/ol/renderer/canvas/vectortilelayer.js b/src/ol/renderer/canvas/vectortilelayer.js index 2be15797da..de50ff99aa 100644 --- a/src/ol/renderer/canvas/vectortilelayer.js +++ b/src/ol/renderer/canvas/vectortilelayer.js @@ -325,11 +325,8 @@ ol.renderer.canvas.VectorTileLayer.prototype.getReplayTransform_ = function(tile * @return {number} The tile's pixel ratio. */ ol.renderer.canvas.VectorTileLayer.prototype.getTilePixelRatio_ = function(source, tile) { - var extent = tile.getExtent(); - return extent ? - ol.extent.getWidth(extent) / - ol.size.toSize(source.getTileGrid().getTileSize(tile.tileCoord[0]))[0] : - source.getTilePixelRatio(); + return ol.extent.getWidth(tile.getExtent()) / + ol.size.toSize(source.getTileGrid().getTileSize(tile.tileCoord[0]))[0]; }; diff --git a/src/ol/source/bingmaps.js b/src/ol/source/bingmaps.js index 8c545a585c..b79be85304 100644 --- a/src/ol/source/bingmaps.js +++ b/src/ol/source/bingmaps.js @@ -141,7 +141,7 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse = function(response) extent: extent, minZoom: resource.zoomMin, maxZoom: maxZoom, - tileSize: tileSize / this.getTilePixelRatio() + tileSize: tileSize / (this.hidpi_ ? 2 : 1) }); this.tileGrid = tileGrid; diff --git a/src/ol/source/tile.js b/src/ol/source/tile.js index e4f37bc2b6..0ee8f9f3cb 100644 --- a/src/ol/source/tile.js +++ b/src/ol/source/tile.js @@ -244,12 +244,11 @@ ol.source.Tile.prototype.getTileCacheForProjection = function(projection) { /** * Get the tile pixel ratio for this source. Subclasses may override this * method, which is meant to return a supported pixel ratio that matches the - * provided `opt_pixelRatio` as close as possible. When no `opt_pixelRatio` is - * provided, it is meant to return `this.tilePixelRatio_`. - * @param {number=} opt_pixelRatio Pixel ratio. + * provided `pixelRatio` as close as possible. + * @param {number} pixelRatio Pixel ratio. * @return {number} Tile pixel ratio. */ -ol.source.Tile.prototype.getTilePixelRatio = function(opt_pixelRatio) { +ol.source.Tile.prototype.getTilePixelRatio = function(pixelRatio) { return this.tilePixelRatio_; }; diff --git a/src/ol/source/vectortile.js b/src/ol/source/vectortile.js index 03f2b0da76..fc24c8d071 100644 --- a/src/ol/source/vectortile.js +++ b/src/ol/source/vectortile.js @@ -40,7 +40,6 @@ ol.source.VectorTile = function(options) { tileLoadFunction: options.tileLoadFunction ? options.tileLoadFunction : ol.VectorImageTile.defaultLoadFunction, tileUrlFunction: options.tileUrlFunction, - tilePixelRatio: options.tilePixelRatio, url: options.url, urls: options.urls, wrapX: options.wrapX === undefined ? true : options.wrapX @@ -141,10 +140,8 @@ ol.source.VectorTile.prototype.getTileGridForProjection = function(projection) { /** * @inheritDoc */ -ol.source.VectorTile.prototype.getTilePixelRatio = function(opt_pixelRatio) { - return opt_pixelRatio == undefined ? - ol.source.UrlTile.prototype.getTilePixelRatio.call(this, opt_pixelRatio) : - opt_pixelRatio; +ol.source.VectorTile.prototype.getTilePixelRatio = function(pixelRatio) { + return pixelRatio; }; diff --git a/src/ol/vectortile.js b/src/ol/vectortile.js index a7f1887096..c1789c1bbb 100644 --- a/src/ol/vectortile.js +++ b/src/ol/vectortile.js @@ -93,7 +93,7 @@ ol.VectorTile.prototype.disposeInternal = function() { * @return {ol.Extent} The extent. */ ol.VectorTile.prototype.getExtent = function() { - return this.extent_; + return this.extent_ || ol.VectorTile.DEFAULT_EXTENT; }; @@ -180,7 +180,12 @@ ol.VectorTile.prototype.onError = function() { /** - * Sets the extent of the vector tile. + * Sets the extent of the vector tile. For tiles in projections with + * `tile-pixels` as units, this should be set to + * `[0, 0, tilePixelSize, tilePixelSize]` by the source's `tileLoadFunction`. + * `tilePixelSize` is calculated by multiplying the tile size with the tile + * pixel ratio. When using `ol.format.MVT`, the format's `getLastExtent()` + * method returns the correct extent. The default is `[0, 0, 4096, 4096]`. * @param {ol.Extent} extent The extent. * @api */ @@ -227,3 +232,10 @@ ol.VectorTile.prototype.setReplayGroup = function(layer, key, replayGroup) { ol.VectorTile.prototype.setLoader = function(loader) { this.loader_ = loader; }; + + +/** + * @const + * @type {ol.Extent} + */ +ol.VectorTile.DEFAULT_EXTENT = [0, 0, 4096, 4096];