Skip to content

Commit

Permalink
Merge pull request openlayers#840 from fredj/zoomcontrol
Browse files Browse the repository at this point in the history
Add ol.control.Zoom#zoomByDelta function
  • Loading branch information
Éric Lemoine committed Jul 10, 2013
2 parents 2cc5c7a + 17f0d01 commit d7e8382
Showing 1 changed file with 9 additions and 36 deletions.
45 changes: 9 additions & 36 deletions src/ol/control/zoomcontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ ol.control.Zoom = function(opt_options) {

var className = goog.isDef(options.className) ? options.className : 'ol-zoom';

var delta = goog.isDef(options.delta) ? options.delta : 1;

var inElement = goog.dom.createDom(goog.dom.TagName.A, {
'href': '#zoomIn',
'class': className + '-in'
});
goog.events.listen(inElement, [
goog.events.EventType.TOUCHEND,
goog.events.EventType.CLICK
], this.handleIn_, false, this);
], goog.partial(ol.control.Zoom.prototype.zoomByDelta_, delta), false, this);

var outElement = goog.dom.createDom(goog.dom.TagName.A, {
'href': '#zoomOut',
Expand All @@ -49,7 +51,7 @@ ol.control.Zoom = function(opt_options) {
goog.events.listen(outElement, [
goog.events.EventType.TOUCHEND,
goog.events.EventType.CLICK
], this.handleOut_, false, this);
], goog.partial(ol.control.Zoom.prototype.zoomByDelta_, -delta), false, this);

var cssClasses = className + ' ' + ol.css.CLASS_UNSELECTABLE;
var element = goog.dom.createDom(goog.dom.TagName.DIV, cssClasses, inElement,
Expand All @@ -61,46 +63,17 @@ ol.control.Zoom = function(opt_options) {
target: options.target
});

/**
* @type {number}
* @private
*/
this.delta_ = goog.isDef(options.delta) ? options.delta : 1;

};
goog.inherits(ol.control.Zoom, ol.control.Control);


/**
* @param {number} delta Zoom delta.
* @param {goog.events.BrowserEvent} browserEvent The browser event to handle.
* @private
*/
ol.control.Zoom.prototype.handleIn_ = function(browserEvent) {
// prevent #zoomIn anchor from getting appended to the url
browserEvent.preventDefault();
var map = this.getMap();
map.requestRenderFrame();
// FIXME works for View2D only
var view = map.getView().getView2D();
var currentResolution = view.getResolution();
if (goog.isDef(currentResolution)) {
map.addPreRenderFunction(ol.animation.zoom({
resolution: currentResolution,
duration: ol.control.ZOOM_DURATION,
easing: ol.easing.easeOut
}));
}
var resolution = view.constrainResolution(currentResolution, this.delta_);
view.setResolution(resolution);
};


/**
* @param {goog.events.BrowserEvent} browserEvent The browser event to handle.
* @private
*/
ol.control.Zoom.prototype.handleOut_ = function(browserEvent) {
// prevent #zoomOut anchor from getting appended to the url
ol.control.Zoom.prototype.zoomByDelta_ = function(delta, browserEvent) {
// prevent the anchor from getting appended to the url
browserEvent.preventDefault();
var map = this.getMap();
// FIXME works for View2D only
Expand All @@ -112,7 +85,7 @@ ol.control.Zoom.prototype.handleOut_ = function(browserEvent) {
duration: ol.control.ZOOM_DURATION,
easing: ol.easing.easeOut
}));
var newResolution = view.constrainResolution(currentResolution, delta);
view.setResolution(newResolution);
}
var resolution = view.constrainResolution(currentResolution, -this.delta_);
view.setResolution(resolution);
};

0 comments on commit d7e8382

Please sign in to comment.