From 58d8b290afde26fb1df0be70e712645f62e0fb4b Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Mon, 8 Feb 2016 15:10:31 +0100 Subject: [PATCH 1/2] Add new cacheSize option to ol.source Option added to: - olx.source.BingMapsOptions - olx.source.MapQuestOptions - olx.source.OSMOptions - olx.source.StamenOptions - olx.source.TileArcGISRestOptions - olx.source.TileImageOptions - olx.source.TileJSONOptions - olx.source.TileWMSOptions - olx.source.VectorTileOptions - olx.source.XYZOptions - olx.source.WMTSOptions - olx.source.ZoomifyOptions --- externs/olx.js | 114 +++++++++++++++++++++++++- src/ol/source/bingmapssource.js | 1 + src/ol/source/mapquestsource.js | 1 + src/ol/source/osmsource.js | 1 + src/ol/source/stamensource.js | 1 + src/ol/source/tilearcgisrestsource.js | 1 + src/ol/source/tileimagesource.js | 1 + src/ol/source/tilejsonsource.js | 1 + src/ol/source/tilewmssource.js | 1 + src/ol/source/vectortilesource.js | 5 +- src/ol/source/wmtssource.js | 1 + src/ol/source/xyzsource.js | 1 + src/ol/source/zoomifysource.js | 1 + 13 files changed, 126 insertions(+), 4 deletions(-) diff --git a/externs/olx.js b/externs/olx.js index 9a9771e74e..039a95daf2 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -3904,7 +3904,8 @@ olx.source; /** - * @typedef {{culture: (string|undefined), + * @typedef {{cacheSize: (number|undefined), + * culture: (string|undefined), * key: string, * imagerySet: string, * maxZoom: (number|undefined), @@ -3916,6 +3917,14 @@ olx.source; olx.source.BingMapsOptions; +/** + * Cache size. Default is `2048`. + * @type {number|undefined} + * @api + */ +olx.source.BingMapsOptions.prototype.cacheSize; + + /** * Culture code. Default is `en-us`. * @type {string|undefined} @@ -4107,6 +4116,7 @@ olx.source.TileUTFGridOptions.prototype.url; /** * @typedef {{attributions: (Array.|undefined), + * cacheSize: (number|undefined), * crossOrigin: (null|string|undefined), * logo: (string|olx.LogoOptions|undefined), * opaque: (boolean|undefined), @@ -4136,6 +4146,14 @@ olx.source.TileImageOptions; olx.source.TileImageOptions.prototype.attributions; +/** + * Cache size. Default is `2048`. + * @type {number|undefined} + * @api + */ +olx.source.TileImageOptions.prototype.cacheSize; + + /** * The `crossOrigin` attribute for loaded images. Note that you must provide a * `crossOrigin` value if you are using the WebGL renderer or if you want to @@ -4270,6 +4288,7 @@ olx.source.TileImageOptions.prototype.wrapX; /** * @typedef {{attributions: (Array.|undefined), + * cacheSize: (number|undefined), * format: (ol.format.Feature|undefined), * logo: (string|olx.LogoOptions|undefined), * opaque: (boolean|undefined), @@ -4298,6 +4317,15 @@ olx.source.VectorTileOptions; olx.source.VectorTileOptions.prototype.attributions; + +/** + * Cache size. Default is `128`. + * @type {number|undefined} + * @api + */ +olx.source.VectorTileOptions.prototype.cacheSize; + + /** * Feature format for tiles. Used and required by the default * `tileLoadFunction`. @@ -4518,7 +4546,8 @@ olx.source.ImageMapGuideOptions.prototype.params; /** - * @typedef {{layer: string, + * @typedef {{cacheSize: (number|undefined), + * layer: string, * reprojectionErrorThreshold: (number|undefined), * tileLoadFunction: (ol.TileLoadFunctionType|undefined), * url: (string|undefined)}} @@ -4527,6 +4556,14 @@ olx.source.ImageMapGuideOptions.prototype.params; olx.source.MapQuestOptions; +/** + * Cache size. Default is `2048`. + * @type {number|undefined} + * @api + */ +olx.source.MapQuestOptions.prototype.cacheSize; + + /** * Layer. Possible values are `osm`, `sat`, and `hyb`. * @type {string} @@ -4600,6 +4637,7 @@ olx.source.TileDebugOptions.prototype.wrapX; /** * @typedef {{attributions: (Array.|undefined), + * cacheSize: (number|undefined), * crossOrigin: (null|string|undefined), * maxZoom: (number|undefined), * opaque: (boolean|undefined), @@ -4620,6 +4658,14 @@ olx.source.OSMOptions; olx.source.OSMOptions.prototype.attributions; +/** + * Cache size. Default is `2048`. + * @type {number|undefined} + * @api + */ +olx.source.OSMOptions.prototype.cacheSize; + + /** * The `crossOrigin` attribute for loaded images. Note that you must provide a * `crossOrigin` value if you are using the WebGL renderer or if you want to @@ -5016,7 +5062,8 @@ olx.source.ImageWMSOptions.prototype.url; /** - * @typedef {{layer: string, + * @typedef {{cacheSize: (number|undefined), + * layer: string, * minZoom: (number|undefined), * maxZoom: (number|undefined), * opaque: (boolean|undefined), @@ -5028,6 +5075,13 @@ olx.source.ImageWMSOptions.prototype.url; olx.source.StamenOptions; +/** + * Cache size. Default is `2048`. + * @type {number|undefined} + * @api + */ +olx.source.StamenOptions.prototype.cacheSize; + /** * Layer. * @type {string} @@ -5176,6 +5230,7 @@ olx.source.ImageStaticOptions.prototype.url; /** * @typedef {{attributions: (Array.|undefined), + * cacheSize: (number|undefined), * crossOrigin: (null|string|undefined), * params: (Object.|undefined), * logo: (string|olx.LogoOptions|undefined), @@ -5199,6 +5254,14 @@ olx.source.TileArcGISRestOptions; olx.source.TileArcGISRestOptions.prototype.attributions; +/** + * Cache size. Default is `2048`. + * @type {number|undefined} + * @api + */ +olx.source.TileArcGISRestOptions.prototype.cacheSize; + + /** * The `crossOrigin` attribute for loaded images. Note that you must provide a * `crossOrigin` value if you are using the WebGL renderer or if you want to @@ -5303,6 +5366,7 @@ olx.source.TileArcGISRestOptions.prototype.urls; /** * @typedef {{attributions: (Array.|undefined), + * cacheSize: (number|undefined), * crossOrigin: (null|string|undefined), * jsonp: (boolean|undefined), * reprojectionErrorThreshold: (number|undefined), @@ -5324,6 +5388,14 @@ olx.source.TileJSONOptions; olx.source.TileJSONOptions.prototype.attributions; +/** + * Cache size. Default is `2048`. + * @type {number|undefined} + * @api + */ +olx.source.TileJSONOptions.prototype.cacheSize; + + /** * The `crossOrigin` attribute for loaded images. Note that you must provide a * `crossOrigin` value if you are using the WebGL renderer or if you want to @@ -5385,6 +5457,7 @@ olx.source.TileJSONOptions.prototype.wrapX; /** * @typedef {{attributions: (Array.|undefined), + * cacheSize: (number|undefined), * params: Object., * crossOrigin: (null|string|undefined), * gutter: (number|undefined), @@ -5412,6 +5485,14 @@ olx.source.TileWMSOptions; olx.source.TileWMSOptions.prototype.attributions; +/** + * Cache size. Default is `2048`. + * @type {number|undefined} + * @api + */ +olx.source.TileWMSOptions.prototype.cacheSize; + + /** * WMS request parameters. At least a `LAYERS` param is required. `STYLES` is * `''` by default. `VERSION` is `1.3.0` by default. `WIDTH`, `HEIGHT`, `BBOX` @@ -5675,6 +5756,7 @@ olx.source.VectorOptions.prototype.wrapX; /** * @typedef {{attributions: (Array.|undefined), + * cacheSize: (number|undefined), * crossOrigin: (string|null|undefined), * logo: (string|olx.LogoOptions|undefined), * tileGrid: ol.tilegrid.WMTS, @@ -5709,6 +5791,14 @@ olx.source.WMTSOptions; olx.source.WMTSOptions.prototype.attributions; +/** + * Cache size. Default is `2048`. + * @type {number|undefined} + * @api + */ +olx.source.WMTSOptions.prototype.cacheSize; + + /** * The `crossOrigin` attribute for loaded images. Note that you must provide a * `crossOrigin` value if you are using the WebGL renderer or if you want to @@ -5882,6 +5972,7 @@ olx.source.WMTSOptions.prototype.wrapX; /** * @typedef {{attributions: (Array.|undefined), + * cacheSize: (number|undefined), * crossOrigin: (null|string|undefined), * logo: (string|olx.LogoOptions|undefined), * opaque: (boolean|undefined), @@ -5910,6 +6001,14 @@ olx.source.XYZOptions; olx.source.XYZOptions.prototype.attributions; +/** + * Cache size. Default is `2048`. + * @type {number|undefined} + * @api + */ +olx.source.XYZOptions.prototype.cacheSize; + + /** * The `crossOrigin` attribute for loaded images. Note that you must provide a * `crossOrigin` value if you are using the WebGL renderer or if you want to @@ -6048,6 +6147,7 @@ olx.source.XYZOptions.prototype.wrapX; /** * @typedef {{attributions: (Array.|undefined), + * cacheSize: (number|undefined), * crossOrigin: (null|string|undefined), * logo: (string|olx.LogoOptions|undefined), * reprojectionErrorThreshold: (number|undefined), @@ -6067,6 +6167,14 @@ olx.source.ZoomifyOptions; olx.source.ZoomifyOptions.prototype.attributions; +/** + * Cache size. Default is `2048`. + * @type {number|undefined} + * @api + */ +olx.source.ZoomifyOptions.prototype.cacheSize; + + /** * The `crossOrigin` attribute for loaded images. Note that you must provide a * `crossOrigin` value if you are using the WebGL renderer or if you want to diff --git a/src/ol/source/bingmapssource.js b/src/ol/source/bingmapssource.js index a2adf057f4..39377efea4 100644 --- a/src/ol/source/bingmapssource.js +++ b/src/ol/source/bingmapssource.js @@ -24,6 +24,7 @@ goog.require('ol.tilecoord'); ol.source.BingMaps = function(options) { goog.base(this, { + cacheSize: options.cacheSize, crossOrigin: 'anonymous', opaque: true, projection: ol.proj.get('EPSG:3857'), diff --git a/src/ol/source/mapquestsource.js b/src/ol/source/mapquestsource.js index a7f6ed1401..860f647e1e 100644 --- a/src/ol/source/mapquestsource.js +++ b/src/ol/source/mapquestsource.js @@ -36,6 +36,7 @@ ol.source.MapQuest = function(opt_options) { goog.base(this, { attributions: layerConfig.attributions, + cacheSize: options.cacheSize, crossOrigin: 'anonymous', logo: 'https://developer.mapquest.com/content/osm/mq_logo.png', maxZoom: layerConfig.maxZoom, diff --git a/src/ol/source/osmsource.js b/src/ol/source/osmsource.js index 91d9c69c93..c0d6800ef9 100644 --- a/src/ol/source/osmsource.js +++ b/src/ol/source/osmsource.js @@ -32,6 +32,7 @@ ol.source.OSM = function(opt_options) { goog.base(this, { attributions: attributions, + cacheSize: options.cacheSize, crossOrigin: crossOrigin, opaque: options.opaque !== undefined ? options.opaque : true, maxZoom: options.maxZoom !== undefined ? options.maxZoom : 19, diff --git a/src/ol/source/stamensource.js b/src/ol/source/stamensource.js index 2265e7d27f..c82a170139 100644 --- a/src/ol/source/stamensource.js +++ b/src/ol/source/stamensource.js @@ -103,6 +103,7 @@ ol.source.Stamen = function(options) { goog.base(this, { attributions: ol.source.Stamen.ATTRIBUTIONS, + cacheSize: options.cacheSize, crossOrigin: 'anonymous', maxZoom: providerConfig.maxZoom, // FIXME uncomment the following when tilegrid supports minZoom diff --git a/src/ol/source/tilearcgisrestsource.js b/src/ol/source/tilearcgisrestsource.js index a6f257794e..d72f00eafb 100644 --- a/src/ol/source/tilearcgisrestsource.js +++ b/src/ol/source/tilearcgisrestsource.js @@ -33,6 +33,7 @@ ol.source.TileArcGISRest = function(opt_options) { goog.base(this, { attributions: options.attributions, + cacheSize: options.cacheSize, crossOrigin: options.crossOrigin, logo: options.logo, projection: options.projection, diff --git a/src/ol/source/tileimagesource.js b/src/ol/source/tileimagesource.js index 13066682b2..5f623d67f4 100644 --- a/src/ol/source/tileimagesource.js +++ b/src/ol/source/tileimagesource.js @@ -25,6 +25,7 @@ ol.source.TileImage = function(options) { goog.base(this, { attributions: options.attributions, + cacheSize: options.cacheSize, extent: options.extent, logo: options.logo, opaque: options.opaque, diff --git a/src/ol/source/tilejsonsource.js b/src/ol/source/tilejsonsource.js index 05309fb651..09a991e5c3 100644 --- a/src/ol/source/tilejsonsource.js +++ b/src/ol/source/tilejsonsource.js @@ -31,6 +31,7 @@ ol.source.TileJSON = function(options) { goog.base(this, { attributions: options.attributions, + cacheSize: options.cacheSize, crossOrigin: options.crossOrigin, projection: ol.proj.get('EPSG:3857'), reprojectionErrorThreshold: options.reprojectionErrorThreshold, diff --git a/src/ol/source/tilewmssource.js b/src/ol/source/tilewmssource.js index f23c0babfa..f6d57cdf7e 100644 --- a/src/ol/source/tilewmssource.js +++ b/src/ol/source/tilewmssource.js @@ -39,6 +39,7 @@ ol.source.TileWMS = function(opt_options) { goog.base(this, { attributions: options.attributions, + cacheSize: options.cacheSize, crossOrigin: options.crossOrigin, logo: options.logo, opaque: !transparent, diff --git a/src/ol/source/vectortilesource.js b/src/ol/source/vectortilesource.js index b7417df27f..252e1b38fe 100644 --- a/src/ol/source/vectortilesource.js +++ b/src/ol/source/vectortilesource.js @@ -26,9 +26,12 @@ goog.require('ol.source.UrlTile'); */ ol.source.VectorTile = function(options) { + var cacheSize = options.cacheSize !== undefined ? + options.cacheSize : ol.DEFAULT_TILE_CACHE_HIGH_WATER_MARK / 16; + goog.base(this, { attributions: options.attributions, - cacheSize: ol.DEFAULT_TILE_CACHE_HIGH_WATER_MARK / 16, + cacheSize: cacheSize, extent: options.extent, logo: options.logo, opaque: options.opaque, diff --git a/src/ol/source/wmtssource.js b/src/ol/source/wmtssource.js index 8b4ecdce35..a32e1698a7 100644 --- a/src/ol/source/wmtssource.js +++ b/src/ol/source/wmtssource.js @@ -174,6 +174,7 @@ ol.source.WMTS = function(options) { goog.base(this, { attributions: options.attributions, + cacheSize: options.cacheSize, crossOrigin: options.crossOrigin, logo: options.logo, projection: options.projection, diff --git a/src/ol/source/xyzsource.js b/src/ol/source/xyzsource.js index fa1c702d24..a9a2aa9aa1 100644 --- a/src/ol/source/xyzsource.js +++ b/src/ol/source/xyzsource.js @@ -38,6 +38,7 @@ ol.source.XYZ = function(options) { goog.base(this, { attributions: options.attributions, + cacheSize: options.cacheSize, crossOrigin: options.crossOrigin, logo: options.logo, opaque: options.opaque, diff --git a/src/ol/source/zoomifysource.js b/src/ol/source/zoomifysource.js index 1e7cfa9382..94a7cee0f8 100644 --- a/src/ol/source/zoomifysource.js +++ b/src/ol/source/zoomifysource.js @@ -121,6 +121,7 @@ ol.source.Zoomify = function(opt_options) { goog.base(this, { attributions: options.attributions, + cacheSize: options.cacheSize, crossOrigin: options.crossOrigin, logo: options.logo, reprojectionErrorThreshold: options.reprojectionErrorThreshold, From 9819aa38f5fc7826e81be8398a91aa2d7a34add1 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Mon, 29 Feb 2016 14:50:46 +0100 Subject: [PATCH 2/2] Remove ol.DEFAULT_TILE_CACHE_HIGH_WATER_MARK --- changelog/upgrade-notes.md | 14 ++++++++++++++ src/ol/ol.js | 6 ------ src/ol/source/vectortilesource.js | 5 +---- src/ol/tilecache.js | 4 +--- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/changelog/upgrade-notes.md b/changelog/upgrade-notes.md index 7ed9288d43..a835d4a556 100644 --- a/changelog/upgrade-notes.md +++ b/changelog/upgrade-notes.md @@ -1,5 +1,19 @@ ## Upgrade notes +### v3.15.0 + +#### Removal of `ol.DEFAULT_TILE_CACHE_HIGH_WATER_MARK` + +The `ol.DEFAULT_TILE_CACHE_HIGH_WATER_MARK` define has been removed. The size of the cache can now be defined on every tile based `ol.source`: +```js +new ol.layer.Tile({ + source: new ol.source.OSM({ + cacheSize: 128 + }) +}) +``` +The default cache size is `2048`. + ### v3.14.0 #### Internet Explorer 9 support diff --git a/src/ol/ol.js b/src/ol/ol.js index 67f3cc5ddc..f91947d59b 100644 --- a/src/ol/ol.js +++ b/src/ol/ol.js @@ -35,12 +35,6 @@ ol.DEFAULT_MIN_ZOOM = 0; ol.DEFAULT_RASTER_REPROJECTION_ERROR_THRESHOLD = 0.5; -/** - * @define {number} Default high water mark. - */ -ol.DEFAULT_TILE_CACHE_HIGH_WATER_MARK = 2048; - - /** * @define {number} Default tile size. */ diff --git a/src/ol/source/vectortilesource.js b/src/ol/source/vectortilesource.js index 252e1b38fe..bbb6a825d6 100644 --- a/src/ol/source/vectortilesource.js +++ b/src/ol/source/vectortilesource.js @@ -26,12 +26,9 @@ goog.require('ol.source.UrlTile'); */ ol.source.VectorTile = function(options) { - var cacheSize = options.cacheSize !== undefined ? - options.cacheSize : ol.DEFAULT_TILE_CACHE_HIGH_WATER_MARK / 16; - goog.base(this, { attributions: options.attributions, - cacheSize: cacheSize, + cacheSize: options.cacheSize !== undefined ? options.cacheSize : 128, extent: options.extent, logo: options.logo, opaque: options.opaque, diff --git a/src/ol/tilecache.js b/src/ol/tilecache.js index 0726171e38..8fe0e5ac68 100644 --- a/src/ol/tilecache.js +++ b/src/ol/tilecache.js @@ -1,6 +1,5 @@ goog.provide('ol.TileCache'); -goog.require('ol'); goog.require('ol.TileRange'); goog.require('ol.structs.LRUCache'); goog.require('ol.tilecoord'); @@ -20,8 +19,7 @@ ol.TileCache = function(opt_highWaterMark) { * @private * @type {number} */ - this.highWaterMark_ = opt_highWaterMark !== undefined ? - opt_highWaterMark : ol.DEFAULT_TILE_CACHE_HIGH_WATER_MARK; + this.highWaterMark_ = opt_highWaterMark !== undefined ? opt_highWaterMark : 2048; }; goog.inherits(ol.TileCache, ol.structs.LRUCache);