diff --git a/doc/tutorials/raster-reprojection.md b/doc/tutorials/raster-reprojection.md index e771d50d67..3f88f3647b 100644 --- a/doc/tutorials/raster-reprojection.md +++ b/doc/tutorials/raster-reprojection.md @@ -107,7 +107,7 @@ In case you are creating a custom build of OpenLayers and do not need the reproj See [Custom builds](custom-builds.html#defines) tutorial on how to do this. ### Triangulation precision threshold -The default [triangulation error threshold](#dynamic-triangulation) in pixels is given by `DEFAULT_RASTER_REPROJECTION_ERROR_THRESHOLD` (0.5 pixel). +The default [triangulation error threshold](#dynamic-triangulation) in pixels is given by `ERROR_THRESHOLD` (0.5 pixel). In case a different threshold needs to be defined for different sources, the `reprojectionErrorThreshold` option can be passed when constructing the tile image source. ###Limiting visibility of reprojected map by extent diff --git a/externs/olx.js b/externs/olx.js index 65bcf571c9..f1e2320d35 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -7443,7 +7443,7 @@ olx.source.ZoomifyOptions.prototype.transition; /** * Tile size. Same tile size is used for all zoom levels. Default value is - * `OpenLayers.DEFAULT_TILE_SIZE`. + * `256`. * @type {number|undefined} * @api */ @@ -8612,8 +8612,7 @@ olx.style.AtlasManagerOptions; /** - * The size in pixels of the first atlas image. If no value is given the - * `ol.INITIAL_ATLAS_SIZE` compile-time constant will be used. + * The size in pixels of the first atlas image. Default is `256`. * @type {number|undefined} * @api */ @@ -8621,11 +8620,8 @@ olx.style.AtlasManagerOptions.prototype.initialSize; /** - * The maximum size in pixels of atlas images. If no value is given then - * the `ol.MAX_ATLAS_SIZE` compile-time constant will be used. And if - * `ol.MAX_ATLAS_SIZE` is set to `-1` (the default) then - * `ol.WEBGL_MAX_TEXTURE_SIZE` will used if WebGL is supported. Otherwise - * 2048 is used. + * The maximum size in pixels of atlas images. Default is + * `WEBGL_MAX_TEXTURE_SIZE` or 2048 if WebGL is not supported. * @type {number|undefined} * @api */ diff --git a/src/ol/Map.js b/src/ol/Map.js index 5987b2f158..40b7cd33e5 100644 --- a/src/ol/Map.js +++ b/src/ol/Map.js @@ -1,7 +1,7 @@ /** * @module ol/Map */ -import {ENABLE_CANVAS, ENABLE_WEBGL, inherits} from './index.js'; +import {inherits} from './index.js'; import _ol_PluggableMap_ from './PluggableMap.js'; import _ol_PluginType_ from './PluginType.js'; import _ol_control_ from './control.js'; @@ -19,24 +19,21 @@ import _ol_renderer_webgl_TileLayer_ from './renderer/webgl/TileLayer.js'; import _ol_renderer_webgl_VectorLayer_ from './renderer/webgl/VectorLayer.js'; -if (ENABLE_CANVAS) { - _ol_plugins_.register(_ol_PluginType_.MAP_RENDERER, _ol_renderer_canvas_Map_); - _ol_plugins_.registerMultiple(_ol_PluginType_.LAYER_RENDERER, [ - _ol_renderer_canvas_ImageLayer_, - _ol_renderer_canvas_TileLayer_, - _ol_renderer_canvas_VectorLayer_, - _ol_renderer_canvas_VectorTileLayer_ - ]); -} +_ol_plugins_.register(_ol_PluginType_.MAP_RENDERER, _ol_renderer_canvas_Map_); +_ol_plugins_.registerMultiple(_ol_PluginType_.LAYER_RENDERER, [ + _ol_renderer_canvas_ImageLayer_, + _ol_renderer_canvas_TileLayer_, + _ol_renderer_canvas_VectorLayer_, + _ol_renderer_canvas_VectorTileLayer_ +]); -if (ENABLE_WEBGL) { - _ol_plugins_.register(_ol_PluginType_.MAP_RENDERER, _ol_renderer_webgl_Map_); - _ol_plugins_.registerMultiple(_ol_PluginType_.LAYER_RENDERER, [ - _ol_renderer_webgl_ImageLayer_, - _ol_renderer_webgl_TileLayer_, - _ol_renderer_webgl_VectorLayer_ - ]); -} +// TODO: move these to new ol-webgl package +_ol_plugins_.register(_ol_PluginType_.MAP_RENDERER, _ol_renderer_webgl_Map_); +_ol_plugins_.registerMultiple(_ol_PluginType_.LAYER_RENDERER, [ + _ol_renderer_webgl_ImageLayer_, + _ol_renderer_webgl_TileLayer_, + _ol_renderer_webgl_VectorLayer_ +]); /** diff --git a/src/ol/View.js b/src/ol/View.js index 88212a3699..6d1bbe8eb4 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -1,7 +1,8 @@ /** * @module ol/View */ -import {DEFAULT_MIN_ZOOM, DEFAULT_TILE_SIZE, inherits, getUid, nullFunction} from './index.js'; +import {DEFAULT_TILE_SIZE} from './tilegrid/common.js'; +import {inherits, getUid, nullFunction} from './index.js'; import _ol_CenterConstraint_ from './CenterConstraint.js'; import _ol_Object_ from './Object.js'; import _ol_ResolutionConstraint_ from './ResolutionConstraint.js'; @@ -21,6 +22,13 @@ import _ol_obj_ from './obj.js'; import _ol_proj_ from './proj.js'; import _ol_proj_Units_ from './proj/Units.js'; + +/** + * @type {number} Default min zoom level for the map view. + */ +var DEFAULT_MIN_ZOOM = 0; + + /** * @classdesc * An ol.View object represents a simple 2D view of the map. diff --git a/src/ol/control/OverviewMap.js b/src/ol/control/OverviewMap.js index 0fc75f9325..b3c0104fee 100644 --- a/src/ol/control/OverviewMap.js +++ b/src/ol/control/OverviewMap.js @@ -1,7 +1,7 @@ /** * @module ol/control/OverviewMap */ -import {OVERVIEWMAP_MAX_RATIO, OVERVIEWMAP_MIN_RATIO, inherits} from '../index.js'; +import {inherits} from '../index.js'; import _ol_Collection_ from '../Collection.js'; import _ol_PluggableMap_ from '../PluggableMap.js'; import _ol_MapEventType_ from '../MapEventType.js'; @@ -19,6 +19,21 @@ import _ol_events_ from '../events.js'; import _ol_events_EventType_ from '../events/EventType.js'; import _ol_extent_ from '../extent.js'; + +/** + * @type {number} Maximum width and/or height extent ratio that determines + * when the overview map should be zoomed out. + */ +var MAX_RATIO = 0.75; + + +/** + * @type {number} Minimum width and/or height extent ratio that determines + * when the overview map should be zoomed in. + */ +var MIN_RATIO = 0.1; + + /** * Create a new control with a map acting as an overview map for an other * defined map. @@ -336,10 +351,10 @@ _ol_control_OverviewMap_.prototype.validateExtent_ = function() { var ovmapWidth = ovmapSize[0]; var ovmapHeight = ovmapSize[1]; - if (boxWidth < ovmapWidth * OVERVIEWMAP_MIN_RATIO || - boxHeight < ovmapHeight * OVERVIEWMAP_MIN_RATIO || - boxWidth > ovmapWidth * OVERVIEWMAP_MAX_RATIO || - boxHeight > ovmapHeight * OVERVIEWMAP_MAX_RATIO) { + if (boxWidth < ovmapWidth * MIN_RATIO || + boxHeight < ovmapHeight * MIN_RATIO || + boxWidth > ovmapWidth * MAX_RATIO || + boxHeight > ovmapHeight * MAX_RATIO) { this.resetExtent_(); } else if (!_ol_extent_.containsExtent(ovextent, extent)) { this.recenter_(); @@ -353,7 +368,7 @@ _ol_control_OverviewMap_.prototype.validateExtent_ = function() { * @private */ _ol_control_OverviewMap_.prototype.resetExtent_ = function() { - if (OVERVIEWMAP_MAX_RATIO === 0 || OVERVIEWMAP_MIN_RATIO === 0) { + if (MAX_RATIO === 0 || MIN_RATIO === 0) { return; } @@ -371,8 +386,8 @@ _ol_control_OverviewMap_.prototype.resetExtent_ = function() { // box sizes using the min and max ratio, pick the step in the middle used // to calculate the extent from the main map to set it to the overview map, var steps = Math.log( - OVERVIEWMAP_MAX_RATIO / OVERVIEWMAP_MIN_RATIO) / Math.LN2; - var ratio = 1 / (Math.pow(2, steps / 2) * OVERVIEWMAP_MIN_RATIO); + MAX_RATIO / MIN_RATIO) / Math.LN2; + var ratio = 1 / (Math.pow(2, steps / 2) * MIN_RATIO); _ol_extent_.scaleFromCenter(extent, ratio); ovview.fit(extent); }; diff --git a/src/ol/has.js b/src/ol/has.js index 7428ec4c60..182eaea2ea 100644 --- a/src/ol/has.js +++ b/src/ol/has.js @@ -1,7 +1,7 @@ /** * @module ol/has */ -import {ENABLE_CANVAS, ASSUME_TOUCH, HAS_WEBGL} from './index.js'; +import {HAS_WEBGL} from './index.js'; var _ol_has_ = {}; @@ -51,13 +51,12 @@ _ol_has_.CANVAS_LINE_DASH = false; /** - * True if both the library and browser support Canvas. Always `false` - * if `ol.ENABLE_CANVAS` is set to `false` at compile time. + * True if the and browsers support Canvas. * @const * @type {boolean} * @api */ -_ol_has_.CANVAS = ENABLE_CANVAS && ( +_ol_has_.CANVAS = ( /** * @return {boolean} Canvas supported. */ @@ -105,7 +104,7 @@ _ol_has_.GEOLOCATION = 'geolocation' in navigator; * @type {boolean} * @api */ -_ol_has_.TOUCH = ASSUME_TOUCH || 'ontouchstart' in window; +_ol_has_.TOUCH = 'ontouchstart' in window; /** diff --git a/src/ol/index.js b/src/ol/index.js index 5c04cec288..f6aced6ae8 100644 --- a/src/ol/index.js +++ b/src/ol/index.js @@ -6,174 +6,15 @@ import webgl from './webgl.js'; /** - * Constants defined with the define tag cannot be changed in application - * code, but can be set at compile time. - * Some reduce the size of the build in advanced compile mode. - */ - - -/** - * @type {boolean} Assume touch. Default is `false`. - */ -export var ASSUME_TOUCH = false; - - -/** - * TODO: rename this to something having to do with tile grids - * see https://github.com/openlayers/openlayers/issues/2076 - * @type {number} Default maximum zoom for default tile grids. - */ -export var DEFAULT_MAX_ZOOM = 42; - - -/** - * @type {number} Default min zoom level for the map view. Default is `0`. - */ -export var DEFAULT_MIN_ZOOM = 0; - - -/** - * @type {number} Default maximum allowed threshold (in pixels) for - * reprojection triangulation. Default is `0.5`. - */ -export var DEFAULT_RASTER_REPROJECTION_ERROR_THRESHOLD = 0.5; - - -/** - * @type {number} Default tile size. - */ -export var DEFAULT_TILE_SIZE = 256; - - -/** - * @type {string} Default WMS version. - */ -export var DEFAULT_WMS_VERSION = '1.3.0'; - - -/** - * @type {boolean} Enable the Canvas renderer. Default is `true`. Setting - * this to false at compile time in advanced mode removes all code - * supporting the Canvas renderer from the build. - */ -export var ENABLE_CANVAS = true; - - -/** - * @type {boolean} Enable integration with the Proj4js library. Default is - * `true`. - */ -export var ENABLE_PROJ4JS = true; - - -/** - * @type {boolean} Enable automatic reprojection of raster sources. Default is - * `true`. - */ -export var ENABLE_RASTER_REPROJECTION = true; - - -/** - * @type {boolean} Enable the WebGL renderer. Default is `true`. Setting - * this to false at compile time in advanced mode removes all code - * supporting the WebGL renderer from the build. - */ -export var ENABLE_WEBGL = true; - - -/** + * TODO: move to a separate ol-webgl package * @type {boolean} Include debuggable shader sources. Default is `true`. - * This should be set to `false` for production builds (if `ENABLE_WEBGL` - * is `true`). + * This should be set to `false` for production builds. */ export var DEBUG_WEBGL = true; /** - * TODO: get rid of this or move it to AtlasManager.js - * @type {number} The size in pixels of the first atlas image. Default is - * `256`. - */ -export var INITIAL_ATLAS_SIZE = 256; - - -/** - * TODO: get rid of this or move it to AtlasManager.js - * @type {number} The maximum size in pixels of atlas images. Default is - * `-1`, meaning it is not used (and `WEBGL_MAX_TEXTURE_SIZE` is - * used instead). - */ -export var MAX_ATLAS_SIZE = -1; - - -/** - * TODO: move this to MouseWheelZoom.js - * @type {number} Maximum mouse wheel delta. - */ -export var MOUSEWHEELZOOM_MAXDELTA = 1; - - -/** - * TODO: move this to OverviewMap.js - * @type {number} Maximum width and/or height extent ratio that determines - * when the overview map should be zoomed out. - */ -export var OVERVIEWMAP_MAX_RATIO = 0.75; - - -/** - * TODO: move this to OverviewMap.js - * @type {number} Minimum width and/or height extent ratio that determines - * when the overview map should be zoomed in. - */ -export var OVERVIEWMAP_MIN_RATIO = 0.1; - - -/** - * TODO: move this to Triangulation.js - * @type {number} Maximum number of subdivision steps during raster - * reprojection triangulation. Prevents high memory usage and large - * number of proj4 calls (for certain transformations and areas). - * At most `2*(2^this)` triangles are created for each triangulated - * extent (tile/image). Default is `10`. - */ -export var RASTER_REPROJECTION_MAX_SUBDIVISION = 10; - - -/** - * TODO: move this to Triangulation.js - * @type {number} Maximum allowed size of triangle relative to world width. - * When transforming corners of world extent between certain projections, - * the resulting triangulation seems to have zero error and no subdivision - * is performed. - * If the triangle width is more than this (relative to world width; 0-1), - * subdivison is forced (up to `RASTER_REPROJECTION_MAX_SUBDIVISION`). - * Default is `0.25`. - */ -export var RASTER_REPROJECTION_MAX_TRIANGLE_WIDTH = 0.25; - - -/** - * TODO: move this to renderer/vector.js - * @type {number} Tolerance for geometry simplification in device pixels. - */ -export var SIMPLIFY_TOLERANCE = 0.5; - - -/** - * TODO: move this to webgl/Map.js - * @type {number} Texture cache high water mark. - */ -export var WEBGL_TEXTURE_CACHE_HIGH_WATER_MARK = 1024; - - -/** - * @type {string} OpenLayers version. - */ -export var VERSION = 'v4.6.4'; - - -/** + * TODO: move to a separate ol-webgl package * The maximum supported WebGL texture size in pixels. If WebGL is not * supported, the value is set to `undefined`. * @const @@ -183,6 +24,7 @@ var WEBGL_MAX_TEXTURE_SIZE; // value is set below /** + * TODO: move to a separate ol-webgl package * List of supported WebGL extensions. * @const * @type {Array.} @@ -191,13 +33,14 @@ var WEBGL_EXTENSIONS; // value is set below /** + * TODO: move to a separate ol-webgl package * WebGL is available. * @type {boolean} */ var HAS_WEBGL = false; -if (ENABLE_WEBGL && 'WebGLRenderingContext' in window) { +if ('WebGLRenderingContext' in window) { try { var canvas = /** @type {HTMLCanvasElement} */ (document.createElement('CANVAS')); @@ -216,6 +59,12 @@ if (ENABLE_WEBGL && 'WebGLRenderingContext' in window) { export {HAS_WEBGL, WEBGL_MAX_TEXTURE_SIZE, WEBGL_EXTENSIONS}; +/** + * @type {string} OpenLayers version. + */ +export var VERSION = 'v4.6.4'; + + /** * Inherit the prototype methods from one constructor into another. * @@ -277,27 +126,8 @@ export default { nullFunction: nullFunction, inherits: inherits, VERSION: VERSION, - ASSUME_TOUCH: ASSUME_TOUCH, - DEFAULT_MAX_ZOOM: DEFAULT_MAX_ZOOM, - DEFAULT_MIN_ZOOM: DEFAULT_MIN_ZOOM, - DEFAULT_RASTER_REPROJECTION_ERROR_THRESHOLD: DEFAULT_RASTER_REPROJECTION_ERROR_THRESHOLD, - DEFAULT_TILE_SIZE: DEFAULT_TILE_SIZE, - DEFAULT_WMS_VERSION: DEFAULT_WMS_VERSION, - ENABLE_CANVAS: ENABLE_CANVAS, - ENABLE_PROJ4JS: ENABLE_PROJ4JS, - ENABLE_RASTER_REPROJECTION: ENABLE_RASTER_REPROJECTION, - ENABLE_WEBGL: ENABLE_WEBGL, DEBUG_WEBGL: DEBUG_WEBGL, - INITIAL_ATLAS_SIZE: INITIAL_ATLAS_SIZE, - MAX_ATLAS_SIZE: MAX_ATLAS_SIZE, - MOUSEWHEELZOOM_MAXDELTA: MOUSEWHEELZOOM_MAXDELTA, - OVERVIEWMAP_MAX_RATIO: OVERVIEWMAP_MAX_RATIO, - OVERVIEWMAP_MIN_RATIO: OVERVIEWMAP_MIN_RATIO, - RASTER_REPROJECTION_MAX_SUBDIVISION: RASTER_REPROJECTION_MAX_SUBDIVISION, - RASTER_REPROJECTION_MAX_TRIANGLE_WIDTH: RASTER_REPROJECTION_MAX_TRIANGLE_WIDTH, - SIMPLIFY_TOLERANCE: SIMPLIFY_TOLERANCE, HAS_WEBGL: HAS_WEBGL, - WEBGL_TEXTURE_CACHE_HIGH_WATER_MARK: WEBGL_TEXTURE_CACHE_HIGH_WATER_MARK, WEBGL_MAX_TEXTURE_SIZE: WEBGL_MAX_TEXTURE_SIZE, WEBGL_EXTENSIONS: WEBGL_EXTENSIONS }; diff --git a/src/ol/interaction/MouseWheelZoom.js b/src/ol/interaction/MouseWheelZoom.js index 16e16dc7cc..18d93663cc 100644 --- a/src/ol/interaction/MouseWheelZoom.js +++ b/src/ol/interaction/MouseWheelZoom.js @@ -1,7 +1,7 @@ /** * @module ol/interaction/MouseWheelZoom */ -import {MOUSEWHEELZOOM_MAXDELTA, inherits} from '../index.js'; +import {inherits} from '../index.js'; import _ol_ViewHint_ from '../ViewHint.js'; import _ol_easing_ from '../easing.js'; import _ol_events_EventType_ from '../events/EventType.js'; @@ -9,6 +9,13 @@ import _ol_has_ from '../has.js'; import _ol_interaction_Interaction_ from '../interaction/Interaction.js'; import _ol_math_ from '../math.js'; + +/** + * @type {number} Maximum mouse wheel delta. + */ +var MAX_DELTA = 1; + + /** * @classdesc * Allows the user to zoom the map by scrolling the mouse wheel. @@ -252,7 +259,7 @@ _ol_interaction_MouseWheelZoom_.prototype.handleWheelZoom_ = function(map) { if (view.getAnimating()) { view.cancelAnimations(); } - var maxDelta = MOUSEWHEELZOOM_MAXDELTA; + var maxDelta = MAX_DELTA; var delta = _ol_math_.clamp(this.delta_, -maxDelta, maxDelta); _ol_interaction_Interaction_.zoomByDelta(view, -delta, this.lastAnchor_, this.duration_); diff --git a/src/ol/proj.js b/src/ol/proj.js index d28c2616d1..dd5a47e98f 100644 --- a/src/ol/proj.js +++ b/src/ol/proj.js @@ -1,7 +1,6 @@ /** * @module ol/proj */ -import {ENABLE_PROJ4JS} from './index.js'; import _ol_Sphere_ from './Sphere.js'; import _ol_extent_ from './extent.js'; import _ol_math_ from './math.js'; @@ -32,23 +31,21 @@ _ol_proj_.METERS_PER_UNIT = _ol_proj_Units_.METERS_PER_UNIT; _ol_proj_.SPHERE_ = new _ol_Sphere_(_ol_Sphere_.DEFAULT_RADIUS); -if (ENABLE_PROJ4JS) { - /** - * Register proj4. If not explicitly registered, it will be assumed that - * proj4js will be loaded in the global namespace. For example in a - * browserify ES6 environment you could use: - * - * import ol from 'openlayers'; - * import proj4 from 'proj4'; - * ol.proj.setProj4(proj4); - * - * @param {Proj4} proj4 Proj4. - * @api - */ - _ol_proj_.setProj4 = function(proj4) { - _ol_proj_proj4_.set(proj4); - }; -} +/** + * Register proj4. If not explicitly registered, it will be assumed that + * proj4js will be loaded in the global namespace. For example in a + * browserify ES6 environment you could use: + * + * import ol from 'openlayers'; + * import proj4 from 'proj4'; + * ol.proj.setProj4(proj4); + * + * @param {Proj4} proj4 Proj4. + * @api + */ +_ol_proj_.setProj4 = function(proj4) { + _ol_proj_proj4_.set(proj4); +}; /** @@ -311,7 +308,7 @@ _ol_proj_.get = function(projectionLike) { } else if (typeof projectionLike === 'string') { var code = projectionLike; projection = _ol_proj_projections_.get(code); - if (ENABLE_PROJ4JS && !projection) { + if (!projection) { var proj4js = _ol_proj_proj4_.get(); if (typeof proj4js == 'function' && proj4js.defs(code) !== undefined) { @@ -380,7 +377,7 @@ _ol_proj_.getTransformFromProjections = function(sourceProjection, destinationPr var sourceCode = sourceProjection.getCode(); var destinationCode = destinationProjection.getCode(); var transform = _ol_proj_transforms_.get(sourceCode, destinationCode); - if (ENABLE_PROJ4JS && !transform) { + if (!transform) { var proj4js = _ol_proj_proj4_.get(); if (typeof proj4js == 'function') { var sourceDef = proj4js.defs(sourceCode); diff --git a/src/ol/proj/Projection.js b/src/ol/proj/Projection.js index 6a08d1a8ac..6e925544ed 100644 --- a/src/ol/proj/Projection.js +++ b/src/ol/proj/Projection.js @@ -1,7 +1,6 @@ /** * @module ol/proj/Projection */ -import {ENABLE_PROJ4JS} from '../index.js'; import _ol_proj_Units_ from '../proj/Units.js'; import _ol_proj_proj4_ from '../proj/proj4.js'; @@ -108,20 +107,18 @@ var _ol_proj_Projection_ = function(options) { this.metersPerUnit_ = options.metersPerUnit; var code = options.code; - if (ENABLE_PROJ4JS) { - var proj4js = _ol_proj_proj4_.get(); - if (typeof proj4js == 'function') { - var def = proj4js.defs(code); - if (def !== undefined) { - if (def.axis !== undefined && options.axisOrientation === undefined) { - this.axisOrientation_ = def.axis; - } - if (options.metersPerUnit === undefined) { - this.metersPerUnit_ = def.to_meter; - } - if (options.units === undefined) { - this.units_ = def.units; - } + var proj4js = _ol_proj_proj4_.get(); + if (typeof proj4js == 'function') { + var def = proj4js.defs(code); + if (def !== undefined) { + if (def.axis !== undefined && options.axisOrientation === undefined) { + this.axisOrientation_ = def.axis; + } + if (options.metersPerUnit === undefined) { + this.metersPerUnit_ = def.to_meter; + } + if (options.units === undefined) { + this.units_ = def.units; } } } diff --git a/src/ol/renderer/canvas/ImageLayer.js b/src/ol/renderer/canvas/ImageLayer.js index ab01e9a8a1..3e36728ef4 100644 --- a/src/ol/renderer/canvas/ImageLayer.js +++ b/src/ol/renderer/canvas/ImageLayer.js @@ -1,7 +1,8 @@ /** * @module ol/renderer/canvas/ImageLayer */ -import {ENABLE_RASTER_REPROJECTION, inherits} from '../../index.js'; +import {ENABLE_RASTER_REPROJECTION} from '../../reproj/common.js'; +import {inherits} from '../../index.js'; import _ol_ImageCanvas_ from '../../ImageCanvas.js'; import _ol_LayerType_ from '../../LayerType.js'; import _ol_ViewHint_ from '../../ViewHint.js'; diff --git a/src/ol/renderer/vector.js b/src/ol/renderer/vector.js index dd9003b7dd..9d18b05175 100644 --- a/src/ol/renderer/vector.js +++ b/src/ol/renderer/vector.js @@ -1,13 +1,19 @@ /** * @module ol/renderer/vector */ -import {SIMPLIFY_TOLERANCE, getUid} from '../index.js'; +import {getUid} from '../index.js'; import _ol_ImageState_ from '../ImageState.js'; import _ol_geom_GeometryType_ from '../geom/GeometryType.js'; import _ol_render_ReplayType_ from '../render/ReplayType.js'; var _ol_renderer_vector_ = {}; +/** + * @type {number} Tolerance for geometry simplification in device pixels. + */ +var SIMPLIFY_TOLERANCE = 0.5; + + /** * @param {ol.Feature|ol.render.Feature} feature1 Feature 1. * @param {ol.Feature|ol.render.Feature} feature2 Feature 2. diff --git a/src/ol/renderer/webgl/ImageLayer.js b/src/ol/renderer/webgl/ImageLayer.js index d67457c8c2..9b29331f77 100644 --- a/src/ol/renderer/webgl/ImageLayer.js +++ b/src/ol/renderer/webgl/ImageLayer.js @@ -1,7 +1,8 @@ /** * @module ol/renderer/webgl/ImageLayer */ -import {ENABLE_RASTER_REPROJECTION, inherits, nullFunction} from '../../index.js'; +import {ENABLE_RASTER_REPROJECTION} from '../../reproj/common.js'; +import {inherits, nullFunction} from '../../index.js'; import _ol_LayerType_ from '../../LayerType.js'; import _ol_ViewHint_ from '../../ViewHint.js'; import _ol_dom_ from '../../dom.js'; diff --git a/src/ol/renderer/webgl/Map.js b/src/ol/renderer/webgl/Map.js index 7515e47673..642eb73d06 100644 --- a/src/ol/renderer/webgl/Map.js +++ b/src/ol/renderer/webgl/Map.js @@ -1,9 +1,8 @@ /** * @module ol/renderer/webgl/Map */ -// FIXME check against gl.getParameter(webgl.MAX_TEXTURE_SIZE) -import {WEBGL_TEXTURE_CACHE_HIGH_WATER_MARK, inherits} from '../../index.js'; +import {inherits} from '../../index.js'; import _ol_array_ from '../../array.js'; import _ol_css_ from '../../css.js'; import _ol_dom_ from '../../dom.js'; @@ -22,6 +21,13 @@ import _ol_webgl_ from '../../webgl.js'; import _ol_webgl_Context_ from '../../webgl/Context.js'; import _ol_webgl_ContextEventType_ from '../../webgl/ContextEventType.js'; + +/** + * @type {number} Texture cache high water mark. + */ +var WEBGL_TEXTURE_CACHE_HIGH_WATER_MARK = 1024; + + /** * @constructor * @extends {ol.renderer.Map} diff --git a/src/ol/reproj/Image.js b/src/ol/reproj/Image.js index cf843e2bdc..ec94824ce9 100644 --- a/src/ol/reproj/Image.js +++ b/src/ol/reproj/Image.js @@ -1,7 +1,8 @@ /** * @module ol/reproj/Image */ -import {DEFAULT_RASTER_REPROJECTION_ERROR_THRESHOLD, inherits} from '../index.js'; +import {ERROR_THRESHOLD} from './common.js'; +import {inherits} from '../index.js'; import _ol_ImageBase_ from '../ImageBase.js'; import _ol_ImageState_ from '../ImageState.js'; import _ol_events_ from '../events.js'; @@ -48,7 +49,7 @@ var _ol_reproj_Image_ = function(sourceProj, targetProj, var sourceResolution = _ol_reproj_.calculateSourceResolution( sourceProj, targetProj, targetCenter, targetResolution); - var errorThresholdInPixels = DEFAULT_RASTER_REPROJECTION_ERROR_THRESHOLD; + var errorThresholdInPixels = ERROR_THRESHOLD; /** * @private diff --git a/src/ol/reproj/Tile.js b/src/ol/reproj/Tile.js index d0e7be6530..10d5ddcdfe 100644 --- a/src/ol/reproj/Tile.js +++ b/src/ol/reproj/Tile.js @@ -1,7 +1,8 @@ /** * @module ol/reproj/Tile */ -import {DEFAULT_RASTER_REPROJECTION_ERROR_THRESHOLD, inherits} from '../index.js'; +import {ERROR_THRESHOLD} from './common.js'; +import {inherits} from '../index.js'; import _ol_Tile_ from '../Tile.js'; import _ol_TileState_ from '../TileState.js'; import _ol_events_ from '../events.js'; @@ -136,7 +137,7 @@ var _ol_reproj_Tile_ = function(sourceProj, sourceTileGrid, } var errorThresholdInPixels = opt_errorThreshold !== undefined ? - opt_errorThreshold : DEFAULT_RASTER_REPROJECTION_ERROR_THRESHOLD; + opt_errorThreshold : ERROR_THRESHOLD; /** * @private diff --git a/src/ol/reproj/Triangulation.js b/src/ol/reproj/Triangulation.js index d70031a88b..954153633a 100644 --- a/src/ol/reproj/Triangulation.js +++ b/src/ol/reproj/Triangulation.js @@ -1,11 +1,33 @@ /** * @module ol/reproj/Triangulation */ -import {RASTER_REPROJECTION_MAX_SUBDIVISION, RASTER_REPROJECTION_MAX_TRIANGLE_WIDTH} from '../index.js'; import _ol_extent_ from '../extent.js'; import _ol_math_ from '../math.js'; import _ol_proj_ from '../proj.js'; + +/** + * @type {number} Maximum number of subdivision steps during raster + * reprojection triangulation. Prevents high memory usage and large + * number of proj4 calls (for certain transformations and areas). + * At most `2*(2^this)` triangles are created for each triangulated + * extent (tile/image). + */ +var MAX_SUBDIVISION = 10; + + +/** + * @type {number} Maximum allowed size of triangle relative to world width. + * When transforming corners of world extent between certain projections, + * the resulting triangulation seems to have zero error and no subdivision + * is performed. + * If the triangle width is more than this (relative to world width; 0-1), + * subdivison is forced (up to `MAX_SUBDIVISION`). + * Default is `0.25`. + */ +var MAX_TRIANGLE_WIDTH = 0.25; + + /** * @classdesc * Class containing triangulation of the given target extent. @@ -112,7 +134,7 @@ var _ol_reproj_Triangulation_ = function(sourceProj, targetProj, targetExtent, destinationTopLeft, destinationTopRight, destinationBottomRight, destinationBottomLeft, sourceTopLeft, sourceTopRight, sourceBottomRight, sourceBottomLeft, - RASTER_REPROJECTION_MAX_SUBDIVISION); + MAX_SUBDIVISION); if (this.wrapsXInSource_) { var leftBound = Infinity; @@ -213,11 +235,11 @@ _ol_reproj_Triangulation_.prototype.addQuad_ = function(a, b, c, d, var targetCoverageX = _ol_extent_.getWidth(targetQuadExtent) / this.targetWorldWidth_; needsSubdivision |= - targetCoverageX > RASTER_REPROJECTION_MAX_TRIANGLE_WIDTH; + targetCoverageX > MAX_TRIANGLE_WIDTH; } if (!wrapsX && this.sourceProj_.isGlobal() && sourceCoverageX) { needsSubdivision |= - sourceCoverageX > RASTER_REPROJECTION_MAX_TRIANGLE_WIDTH; + sourceCoverageX > MAX_TRIANGLE_WIDTH; } } diff --git a/src/ol/reproj/common.js b/src/ol/reproj/common.js new file mode 100644 index 0000000000..524358e314 --- /dev/null +++ b/src/ol/reproj/common.js @@ -0,0 +1,12 @@ +/** + * @type {number} Default maximum allowed threshold (in pixels) for + * reprojection triangulation. + */ +export var ERROR_THRESHOLD = 0.5; + +/** + * TODO: decide if we want to expose this as a build flag or remove it + * @type {boolean} Enable automatic reprojection of raster sources. Default is + * `true`. + */ +export var ENABLE_RASTER_REPROJECTION = true; diff --git a/src/ol/source/Image.js b/src/ol/source/Image.js index 1f9dc15919..db0fb79b6e 100644 --- a/src/ol/source/Image.js +++ b/src/ol/source/Image.js @@ -1,7 +1,8 @@ /** * @module ol/source/Image */ -import {ENABLE_RASTER_REPROJECTION, inherits} from '../index.js'; +import {ENABLE_RASTER_REPROJECTION} from '../reproj/common.js'; +import {inherits} from '../index.js'; import _ol_ImageState_ from '../ImageState.js'; import _ol_array_ from '../array.js'; import _ol_events_Event_ from '../events/Event.js'; diff --git a/src/ol/source/ImageWMS.js b/src/ol/source/ImageWMS.js index 74a7d46274..98fa89fab9 100644 --- a/src/ol/source/ImageWMS.js +++ b/src/ol/source/ImageWMS.js @@ -2,7 +2,8 @@ * @module ol/source/ImageWMS */ -import {DEFAULT_WMS_VERSION, inherits} from '../index.js'; +import {DEFAULT_WMS_VERSION} from './common.js'; +import {inherits} from '../index.js'; import _ol_Image_ from '../Image.js'; import _ol_asserts_ from '../asserts.js'; import _ol_events_ from '../events.js'; diff --git a/src/ol/source/TileImage.js b/src/ol/source/TileImage.js index 56ae68cd6d..c827ef15c0 100644 --- a/src/ol/source/TileImage.js +++ b/src/ol/source/TileImage.js @@ -1,7 +1,8 @@ /** * @module ol/source/TileImage */ -import {ENABLE_RASTER_REPROJECTION, getUid, inherits} from '../index.js'; +import {ENABLE_RASTER_REPROJECTION} from '../reproj/common.js'; +import {getUid, inherits} from '../index.js'; import _ol_ImageTile_ from '../ImageTile.js'; import _ol_TileCache_ from '../TileCache.js'; import _ol_TileState_ from '../TileState.js'; diff --git a/src/ol/source/TileWMS.js b/src/ol/source/TileWMS.js index 1a63818b98..a03a4f718e 100644 --- a/src/ol/source/TileWMS.js +++ b/src/ol/source/TileWMS.js @@ -2,7 +2,8 @@ * @module ol/source/TileWMS */ -import {DEFAULT_WMS_VERSION, inherits} from '../index.js'; +import {DEFAULT_WMS_VERSION} from './common.js'; +import {inherits} from '../index.js'; import _ol_asserts_ from '../asserts.js'; import _ol_extent_ from '../extent.js'; import _ol_obj_ from '../obj.js'; diff --git a/src/ol/source/Zoomify.js b/src/ol/source/Zoomify.js index d9e1179252..807fa0fd55 100644 --- a/src/ol/source/Zoomify.js +++ b/src/ol/source/Zoomify.js @@ -1,7 +1,8 @@ /** * @module ol/source/Zoomify */ -import {DEFAULT_TILE_SIZE, inherits} from '../index.js'; +import {DEFAULT_TILE_SIZE} from '../tilegrid/common.js'; +import {inherits} from '../index.js'; import _ol_ImageTile_ from '../ImageTile.js'; import _ol_TileState_ from '../TileState.js'; import _ol_TileUrlFunction_ from '../TileUrlFunction.js'; diff --git a/src/ol/source/common.js b/src/ol/source/common.js new file mode 100644 index 0000000000..a20bbd8c85 --- /dev/null +++ b/src/ol/source/common.js @@ -0,0 +1,4 @@ +/** + * @type {string} Default WMS version. + */ +export var DEFAULT_WMS_VERSION = '1.3.0'; diff --git a/src/ol/style/AtlasManager.js b/src/ol/style/AtlasManager.js index 26b01aeaeb..9d67ff1a2d 100644 --- a/src/ol/style/AtlasManager.js +++ b/src/ol/style/AtlasManager.js @@ -1,9 +1,21 @@ /** * @module ol/style/AtlasManager */ -import {INITIAL_ATLAS_SIZE, MAX_ATLAS_SIZE, WEBGL_MAX_TEXTURE_SIZE, nullFunction} from '../index.js'; +import {WEBGL_MAX_TEXTURE_SIZE, nullFunction} from '../index.js'; import _ol_style_Atlas_ from '../style/Atlas.js'; + +/** + * @type {number} The size in pixels of the first atlas image. + */ +var INITIAL_ATLAS_SIZE = 256; + +/** + * @type {number} The maximum size in pixels of atlas images. + */ +var MAX_ATLAS_SIZE = -1; + + /** * Manages the creation of image atlases. * diff --git a/src/ol/tilegrid.js b/src/ol/tilegrid.js index 30fcb5fd11..4c9e7ba0e6 100644 --- a/src/ol/tilegrid.js +++ b/src/ol/tilegrid.js @@ -1,7 +1,7 @@ /** * @module ol/tilegrid */ -import {DEFAULT_MAX_ZOOM, DEFAULT_TILE_SIZE} from './index.js'; +import {DEFAULT_MAX_ZOOM, DEFAULT_TILE_SIZE} from './tilegrid/common.js'; import _ol_size_ from './size.js'; import _ol_extent_ from './extent.js'; import _ol_extent_Corner_ from './extent/Corner.js'; diff --git a/src/ol/tilegrid/TileGrid.js b/src/ol/tilegrid/TileGrid.js index e57728e603..edab2d53de 100644 --- a/src/ol/tilegrid/TileGrid.js +++ b/src/ol/tilegrid/TileGrid.js @@ -1,7 +1,7 @@ /** * @module ol/tilegrid/TileGrid */ -import {DEFAULT_TILE_SIZE} from '../index.js'; +import {DEFAULT_TILE_SIZE} from './common.js'; import _ol_asserts_ from '../asserts.js'; import _ol_TileRange_ from '../TileRange.js'; import _ol_array_ from '../array.js'; diff --git a/src/ol/tilegrid/common.js b/src/ol/tilegrid/common.js new file mode 100644 index 0000000000..e003fba738 --- /dev/null +++ b/src/ol/tilegrid/common.js @@ -0,0 +1,9 @@ +/** + * @type {number} Default maximum zoom for default tile grids. + */ +export var DEFAULT_MAX_ZOOM = 42; + +/** + * @type {number} Default tile size. + */ +export var DEFAULT_TILE_SIZE = 256; diff --git a/test/spec/ol/source/zoomify.test.js b/test/spec/ol/source/zoomify.test.js index 3d21657ca7..a6b7d364b3 100644 --- a/test/spec/ol/source/zoomify.test.js +++ b/test/spec/ol/source/zoomify.test.js @@ -1,4 +1,4 @@ -import {DEFAULT_TILE_SIZE} from '../../../../src/ol/index.js'; +import {DEFAULT_TILE_SIZE} from '../../../../src/ol/tilegrid/common.js'; import _ol_events_ from '../../../../src/ol/events.js'; import _ol_proj_Projection_ from '../../../../src/ol/proj/Projection.js'; import _ol_source_Zoomify_ from '../../../../src/ol/source/Zoomify.js'; diff --git a/test/spec/ol/tilegrid/tilegrid.test.js b/test/spec/ol/tilegrid/tilegrid.test.js index 346c9d8b95..86a6bf3886 100644 --- a/test/spec/ol/tilegrid/tilegrid.test.js +++ b/test/spec/ol/tilegrid/tilegrid.test.js @@ -1,4 +1,4 @@ -import {DEFAULT_MAX_ZOOM, DEFAULT_TILE_SIZE} from '../../../../src/ol/index.js'; +import {DEFAULT_MAX_ZOOM, DEFAULT_TILE_SIZE} from '../../../../src/ol/tilegrid/common.js'; import _ol_TileRange_ from '../../../../src/ol/TileRange.js'; import _ol_extent_ from '../../../../src/ol/extent.js'; import _ol_proj_ from '../../../../src/ol/proj.js';