From 778aec45d83b7bb271b2e8bfcb6b82202c29c3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sun, 14 Apr 2013 22:00:09 +0200 Subject: [PATCH 1/3] View2D option "numZoomLevels" changed to "maxZoom" This is to be consistent with ol.source.XYZ and ol.tilegrid.XYZ. --- src/objectliterals.jsdoc | 6 +++--- src/ol/view2d.js | 12 ++++++------ test/spec/ol/view2d.test.js | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index a98eadda99..efd75780ce 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -49,14 +49,14 @@ * @property {ol.Coordinate|undefined} center The view center in map projection. * @property {number|undefined} maxResolution The maximum resolution in map * units per pixel. - * @property {number|undefined} numZoomLevels The number of zoom levels for this - * view. Zoom level 0 uses the `maxResolution`; subsequent zoom levels are + * @property {number|undefined} maxZoom The maximum zoom level for this view. + * Zoom level 0 uses the `maxResolution`; subsequent zoom levels are * calculated by dividing the previous resolution by `zoomFactor`. * @property {ol.ProjectionLike} projection The map projection. * @property {number|undefined} resolution The initial resolution for the view. * @property {Array.|undefined} resolutions The resolutions for this * view. If configured, this is equivalent to specifying `maxResolution` and - * `numZoomLevels`. + * `maxZoom`. * @property {number|undefined} rotation Initial rotation of the view. * @property {number|undefined} zoom Initial zoom level of the view. * @property {number|undefined} zoomFactor Factor to calculate resolutions for diff --git a/src/ol/view2d.js b/src/ol/view2d.js index e6a118a83f..035ac3120c 100644 --- a/src/ol/view2d.js +++ b/src/ol/view2d.js @@ -391,12 +391,12 @@ ol.View2D.createResolutionConstraint_ = function(options) { resolutionConstraint = ol.ResolutionConstraint.createSnapToResolutions( resolutions); } else { - var numZoomLevels, zoomFactor; + var maxZoom, zoomFactor; if (goog.isDef(options.maxResolution) && - goog.isDef(options.numZoomLevels) && + goog.isDef(options.maxZoom) && goog.isDef(options.zoomFactor)) { maxResolution = options.maxResolution; - numZoomLevels = options.numZoomLevels; + maxZoom = options.maxZoom; zoomFactor = options.zoomFactor; } else { var projectionExtent = ol.projection.createProjection( @@ -404,12 +404,12 @@ ol.View2D.createResolutionConstraint_ = function(options) { maxResolution = Math.max( projectionExtent.maxX - projectionExtent.minX, projectionExtent.maxY - projectionExtent.minY) / ol.DEFAULT_TILE_SIZE; - numZoomLevels = 29; + maxZoom = 28; zoomFactor = 2; } - minResolution = maxResolution / Math.pow(zoomFactor, numZoomLevels - 1); + minResolution = maxResolution / Math.pow(zoomFactor, maxZoom); resolutionConstraint = ol.ResolutionConstraint.createSnapToPower( - zoomFactor, maxResolution, numZoomLevels - 1); + zoomFactor, maxResolution, maxZoom); } return [resolutionConstraint, maxResolution, minResolution]; }; diff --git a/test/spec/ol/view2d.test.js b/test/spec/ol/view2d.test.js index 95dfab872f..16dc4d499d 100644 --- a/test/spec/ol/view2d.test.js +++ b/test/spec/ol/view2d.test.js @@ -16,12 +16,12 @@ describe('ol.View2D', function() { }); }); - describe('with maxResolution, numZoomLevels, and zoomFactor options', + describe('with maxResolution, maxZoom, and zoomFactor options', function() { it('gives a correct resolution constraint function', function() { var options = { maxResolution: 81, - numZoomLevels: 4, + maxZoom: 3, zoomFactor: 3 }; var parts = ol.View2D.createResolutionConstraint_(options); From 48f0e7e2ec3eb62a9f7d72ae2250449c6a57bf37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sun, 14 Apr 2013 22:12:12 +0200 Subject: [PATCH 2/3] More View2D configuration flexibility --- src/ol/view2d.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ol/view2d.js b/src/ol/view2d.js index 035ac3120c..c7b2fc6df2 100644 --- a/src/ol/view2d.js +++ b/src/ol/view2d.js @@ -391,20 +391,20 @@ ol.View2D.createResolutionConstraint_ = function(options) { resolutionConstraint = ol.ResolutionConstraint.createSnapToResolutions( resolutions); } else { - var maxZoom, zoomFactor; - if (goog.isDef(options.maxResolution) && - goog.isDef(options.maxZoom) && - goog.isDef(options.zoomFactor)) { - maxResolution = options.maxResolution; - maxZoom = options.maxZoom; - zoomFactor = options.zoomFactor; - } else { + maxResolution = options.maxResolution; + if (!goog.isDef(maxResolution)) { var projectionExtent = ol.projection.createProjection( options.projection, 'EPSG:3857').getExtent(); maxResolution = Math.max( projectionExtent.maxX - projectionExtent.minX, projectionExtent.maxY - projectionExtent.minY) / ol.DEFAULT_TILE_SIZE; + } + var maxZoom = options.maxZoom; + if (!goog.isDef(maxZoom)) { maxZoom = 28; + } + var zoomFactor = options.zoomFactor; + if (!goog.isDef(zoomFactor)) { zoomFactor = 2; } minResolution = maxResolution / Math.pow(zoomFactor, maxZoom); From 78b2983fdfd0044443fbc663f9d8d96fef2b2a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sun, 14 Apr 2013 22:14:05 +0200 Subject: [PATCH 3/3] maxZoom 18 in localized-openstreetmap example --- examples/localized-openstreetmap.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/localized-openstreetmap.js b/examples/localized-openstreetmap.js index fa78fce8b2..e8053c83d1 100644 --- a/examples/localized-openstreetmap.js +++ b/examples/localized-openstreetmap.js @@ -23,6 +23,7 @@ var map = new ol.Map({ renderers: ol.RendererHints.createFromQueryData(), target: 'map', view: new ol.View2D({ + maxZoom: 18, center: [-172857, 5977746], zoom: 12 })