Remove use of goog.math.Rect

This commit is contained in:
Frederic Junod
2016-02-24 14:32:28 +01:00
parent 373393dce7
commit 48064306a1
2 changed files with 21 additions and 23 deletions

View File

@@ -4,7 +4,6 @@ goog.provide('ol.control.ZoomSlider');
goog.require('goog.asserts');
goog.require('goog.dom');
goog.require('goog.math.Rect');
goog.require('goog.style');
goog.require('ol.events');
goog.require('ol.events.Event');
@@ -66,10 +65,16 @@ ol.control.ZoomSlider = function(opt_options) {
this.dragListenerKeys_;
/**
* @type {goog.math.Rect}
* @type {number}
* @private
*/
this.limits_;
this.heightLimit_ = 0;
/**
* @type {number}
* @private
*/
this.widthLimit_ = 0;
/**
* @type {number|undefined}
@@ -180,18 +185,13 @@ ol.control.ZoomSlider.prototype.initSlider_ = function() {
thumbMargins.top + thumbMargins.bottom;
this.thumbSize_ = [thumbWidth, thumbHeight];
var width = containerSize.width - thumbWidth;
var height = containerSize.height - thumbHeight;
var limits;
if (containerSize.width > containerSize.height) {
this.direction_ = ol.control.ZoomSlider.direction.HORIZONTAL;
limits = new goog.math.Rect(0, 0, width, 0);
this.widthLimit_ = containerSize.width - thumbWidth;
} else {
this.direction_ = ol.control.ZoomSlider.direction.VERTICAL;
limits = new goog.math.Rect(0, 0, 0, height);
this.heightLimit_ = containerSize.height - thumbHeight;
}
this.limits_ = limits;
this.sliderInitialized_ = true;
};
@@ -331,10 +331,9 @@ ol.control.ZoomSlider.prototype.setThumbPosition_ = function(res) {
var thumb = goog.dom.getFirstElementChild(this.element);
if (this.direction_ == ol.control.ZoomSlider.direction.HORIZONTAL) {
thumb.style.left = this.limits_.left + this.limits_.width * position + 'px';
thumb.style.left = this.widthLimit_ * position + 'px';
} else {
thumb.style.left = this.limits_.left + 'px';
thumb.style.top = this.limits_.top + this.limits_.height * position + 'px';
thumb.style.top = this.heightLimit_ * position + 'px';
}
};
@@ -350,12 +349,11 @@ ol.control.ZoomSlider.prototype.setThumbPosition_ = function(res) {
* @private
*/
ol.control.ZoomSlider.prototype.getRelativePosition_ = function(x, y) {
var draggerLimits = this.limits_;
var amount;
if (this.direction_ === ol.control.ZoomSlider.direction.HORIZONTAL) {
amount = (x - draggerLimits.left) / draggerLimits.width;
amount = x / this.widthLimit_;
} else {
amount = (y - draggerLimits.top) / draggerLimits.height;
amount = y / this.heightLimit_;
}
return ol.math.clamp(amount, 0, 1);
};