Use the map's zoom method instead of our own
This also allows us to get rid of the resolutions constraint and configuration.
This commit is contained in:
@@ -21,4 +21,4 @@ var map = new ol.Map(document.getElementById('map'), {
|
|||||||
layers: new ol.Collection([layer]),
|
layers: new ol.Collection([layer]),
|
||||||
zoom: 0
|
zoom: 0
|
||||||
});
|
});
|
||||||
var zoom = new ol.control.Zoom(map, layer.getSource().getResolutions());
|
var zoom = new ol.control.Zoom(map, 4);
|
||||||
|
|||||||
@@ -16,25 +16,17 @@ goog.require('ol.control.Control');
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.control.Control}
|
* @extends {ol.control.Control}
|
||||||
* @param {ol.Map} map Map.
|
* @param {ol.Map} map Map.
|
||||||
* @param {Array.<number>=} opt_resolutions The resolutions to zoom to.
|
* @param {number=} opt_zoomDelta Optional zoom delta.
|
||||||
*/
|
*/
|
||||||
ol.control.Zoom = function(map, opt_resolutions) {
|
ol.control.Zoom = function(map, opt_zoomDelta) {
|
||||||
|
|
||||||
goog.base(this, map);
|
goog.base(this, map);
|
||||||
|
|
||||||
if (!goog.isDef(opt_resolutions)) {
|
|
||||||
opt_resolutions = new Array(19);
|
|
||||||
for (var z = 0; z <= 18; ++z) {
|
|
||||||
opt_resolutions[z] = ol.Projection.EPSG_3857_HALF_SIZE / (128 << z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Function}
|
* @type {number}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.constraint_ = ol.ResolutionConstraint.createSnapToResolutions(
|
this.zoomDelta_ = goog.isDef(opt_zoomDelta) ? opt_zoomDelta : 1;
|
||||||
opt_resolutions);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Element}
|
* @type {Element}
|
||||||
@@ -87,7 +79,7 @@ ol.control.Zoom.prototype.getElement = function() {
|
|||||||
ol.control.Zoom.prototype.handleIn_ = function(browserEvent) {
|
ol.control.Zoom.prototype.handleIn_ = function(browserEvent) {
|
||||||
browserEvent.stopPropagation();
|
browserEvent.stopPropagation();
|
||||||
browserEvent.preventDefault();
|
browserEvent.preventDefault();
|
||||||
this.zoom_(1);
|
this.getMap().zoom(this.zoomDelta_);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -98,27 +90,12 @@ ol.control.Zoom.prototype.handleIn_ = function(browserEvent) {
|
|||||||
ol.control.Zoom.prototype.handleOut_ = function(browserEvent) {
|
ol.control.Zoom.prototype.handleOut_ = function(browserEvent) {
|
||||||
browserEvent.stopPropagation();
|
browserEvent.stopPropagation();
|
||||||
browserEvent.preventDefault();
|
browserEvent.preventDefault();
|
||||||
this.zoom_(-1);
|
this.getMap().zoom(-this.zoomDelta_);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {number} delta Delta.
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
ol.control.Zoom.prototype.zoom_ = function(delta) {
|
|
||||||
var map = this.getMap();
|
|
||||||
var resolution = this.constraint_(map.getResolution(), delta);
|
|
||||||
map.setResolution(resolution);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.control.Zoom.prototype.disposeInternal = function() {
|
ol.control.Zoom.prototype.disposeInternal = function() {
|
||||||
goog.dom.removeNode(this.inButton_);
|
|
||||||
goog.dom.removeNode(this.outButton_);
|
|
||||||
goog.dom.removeNode(this.divElement_);
|
goog.dom.removeNode(this.divElement_);
|
||||||
delete this.inButton_;
|
delete this.inButton_;
|
||||||
delete this.outButton_;
|
delete this.outButton_;
|
||||||
|
|||||||
Reference in New Issue
Block a user