Merge pull request #546 from elemoine/view2d
View2D - more consistency and configuration flexibility
This commit is contained in:
@@ -23,6 +23,7 @@ var map = new ol.Map({
|
|||||||
renderers: ol.RendererHints.createFromQueryData(),
|
renderers: ol.RendererHints.createFromQueryData(),
|
||||||
target: 'map',
|
target: 'map',
|
||||||
view: new ol.View2D({
|
view: new ol.View2D({
|
||||||
|
maxZoom: 18,
|
||||||
center: [-172857, 5977746],
|
center: [-172857, 5977746],
|
||||||
zoom: 12
|
zoom: 12
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -49,14 +49,14 @@
|
|||||||
* @property {ol.Coordinate|undefined} center The view center in map projection.
|
* @property {ol.Coordinate|undefined} center The view center in map projection.
|
||||||
* @property {number|undefined} maxResolution The maximum resolution in map
|
* @property {number|undefined} maxResolution The maximum resolution in map
|
||||||
* units per pixel.
|
* units per pixel.
|
||||||
* @property {number|undefined} numZoomLevels The number of zoom levels for this
|
* @property {number|undefined} maxZoom The maximum zoom level for this view.
|
||||||
* view. Zoom level 0 uses the `maxResolution`; subsequent zoom levels are
|
* Zoom level 0 uses the `maxResolution`; subsequent zoom levels are
|
||||||
* calculated by dividing the previous resolution by `zoomFactor`.
|
* calculated by dividing the previous resolution by `zoomFactor`.
|
||||||
* @property {ol.ProjectionLike} projection The map projection.
|
* @property {ol.ProjectionLike} projection The map projection.
|
||||||
* @property {number|undefined} resolution The initial resolution for the view.
|
* @property {number|undefined} resolution The initial resolution for the view.
|
||||||
* @property {Array.<number>|undefined} resolutions The resolutions for this
|
* @property {Array.<number>|undefined} resolutions The resolutions for this
|
||||||
* view. If configured, this is equivalent to specifying `maxResolution` and
|
* view. If configured, this is equivalent to specifying `maxResolution` and
|
||||||
* `numZoomLevels`.
|
* `maxZoom`.
|
||||||
* @property {number|undefined} rotation Initial rotation of the view.
|
* @property {number|undefined} rotation Initial rotation of the view.
|
||||||
* @property {number|undefined} zoom Initial zoom level of the view.
|
* @property {number|undefined} zoom Initial zoom level of the view.
|
||||||
* @property {number|undefined} zoomFactor Factor to calculate resolutions for
|
* @property {number|undefined} zoomFactor Factor to calculate resolutions for
|
||||||
|
|||||||
+11
-11
@@ -391,25 +391,25 @@ ol.View2D.createResolutionConstraint_ = function(options) {
|
|||||||
resolutionConstraint = ol.ResolutionConstraint.createSnapToResolutions(
|
resolutionConstraint = ol.ResolutionConstraint.createSnapToResolutions(
|
||||||
resolutions);
|
resolutions);
|
||||||
} else {
|
} else {
|
||||||
var numZoomLevels, zoomFactor;
|
maxResolution = options.maxResolution;
|
||||||
if (goog.isDef(options.maxResolution) &&
|
if (!goog.isDef(maxResolution)) {
|
||||||
goog.isDef(options.numZoomLevels) &&
|
|
||||||
goog.isDef(options.zoomFactor)) {
|
|
||||||
maxResolution = options.maxResolution;
|
|
||||||
numZoomLevels = options.numZoomLevels;
|
|
||||||
zoomFactor = options.zoomFactor;
|
|
||||||
} else {
|
|
||||||
var projectionExtent = ol.projection.createProjection(
|
var projectionExtent = ol.projection.createProjection(
|
||||||
options.projection, 'EPSG:3857').getExtent();
|
options.projection, 'EPSG:3857').getExtent();
|
||||||
maxResolution = Math.max(
|
maxResolution = Math.max(
|
||||||
projectionExtent.maxX - projectionExtent.minX,
|
projectionExtent.maxX - projectionExtent.minX,
|
||||||
projectionExtent.maxY - projectionExtent.minY) / ol.DEFAULT_TILE_SIZE;
|
projectionExtent.maxY - projectionExtent.minY) / ol.DEFAULT_TILE_SIZE;
|
||||||
numZoomLevels = 29;
|
}
|
||||||
|
var maxZoom = options.maxZoom;
|
||||||
|
if (!goog.isDef(maxZoom)) {
|
||||||
|
maxZoom = 28;
|
||||||
|
}
|
||||||
|
var zoomFactor = options.zoomFactor;
|
||||||
|
if (!goog.isDef(zoomFactor)) {
|
||||||
zoomFactor = 2;
|
zoomFactor = 2;
|
||||||
}
|
}
|
||||||
minResolution = maxResolution / Math.pow(zoomFactor, numZoomLevels - 1);
|
minResolution = maxResolution / Math.pow(zoomFactor, maxZoom);
|
||||||
resolutionConstraint = ol.ResolutionConstraint.createSnapToPower(
|
resolutionConstraint = ol.ResolutionConstraint.createSnapToPower(
|
||||||
zoomFactor, maxResolution, numZoomLevels - 1);
|
zoomFactor, maxResolution, maxZoom);
|
||||||
}
|
}
|
||||||
return [resolutionConstraint, maxResolution, minResolution];
|
return [resolutionConstraint, maxResolution, minResolution];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ describe('ol.View2D', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with maxResolution, numZoomLevels, and zoomFactor options',
|
describe('with maxResolution, maxZoom, and zoomFactor options',
|
||||||
function() {
|
function() {
|
||||||
it('gives a correct resolution constraint function', function() {
|
it('gives a correct resolution constraint function', function() {
|
||||||
var options = {
|
var options = {
|
||||||
maxResolution: 81,
|
maxResolution: 81,
|
||||||
numZoomLevels: 4,
|
maxZoom: 3,
|
||||||
zoomFactor: 3
|
zoomFactor: 3
|
||||||
};
|
};
|
||||||
var parts = ol.View2D.createResolutionConstraint_(options);
|
var parts = ol.View2D.createResolutionConstraint_(options);
|
||||||
|
|||||||
Reference in New Issue
Block a user