From c1afd513b7b628cdbf0cd6e19bd18b026587e4ea Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Mon, 13 Oct 2014 10:13:50 -0600 Subject: [PATCH] Account for the thumb size when handling clicks --- css/ol.css | 7 +++--- examples/zoomslider.html | 2 +- src/ol/control/zoomslidercontrol.js | 39 ++++++++++++++++++----------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/css/ol.css b/css/ol.css index f39721ff8f..ae7397c844 100644 --- a/css/ol.css +++ b/css/ol.css @@ -259,7 +259,7 @@ button.ol-full-screen-true:after { left: .5em; background: #eee; background: rgba(255, 255, 255, 0.4); - width: 1.7em; + width: 24px; height: 200px; } .ol-zoomslider-thumb { @@ -268,10 +268,11 @@ button.ol-full-screen-true:after { background: rgba(0,60,136,0.5); border-radius: 2px; cursor: pointer; - height: 1.1em; - width: 1.6em; + height: 10px; + width: 22px; margin: 3px; } + .ol-touch .ol-zoomslider { top: 5.5em; width: 2.052em; diff --git a/examples/zoomslider.html b/examples/zoomslider.html index 34361ecd87..f5da737e26 100644 --- a/examples/zoomslider.html +++ b/examples/zoomslider.html @@ -14,7 +14,7 @@ * zoom-out buttons. */ #map2 .ol-zoom .ol-zoom-out { - margin-top: 206px; + margin-top: 204px; } #map2 .ol-zoomslider { background-color: transparent; diff --git a/src/ol/control/zoomslidercontrol.js b/src/ol/control/zoomslidercontrol.js index eee1c4bf22..64c89efbe8 100644 --- a/src/ol/control/zoomslidercontrol.js +++ b/src/ol/control/zoomslidercontrol.js @@ -15,6 +15,7 @@ goog.require('goog.math'); goog.require('goog.math.Rect'); goog.require('goog.style'); goog.require('ol'); +goog.require('ol.Size'); goog.require('ol.ViewHint'); goog.require('ol.animation'); goog.require('ol.control.Control'); @@ -57,6 +58,14 @@ ol.control.ZoomSlider = function(opt_options) { */ this.direction_ = ol.control.ZoomSlider.direction.VERTICAL; + /** + * The calculated thumb size (border box plus margins). Set when initSlider_ + * is called. + * @type {ol.Size} + * @private + */ + this.thumbSize_ = null; + /** * Whether the slider is initialized. * @type {boolean} @@ -130,25 +139,26 @@ ol.control.ZoomSlider.prototype.setMap = function(map) { ol.control.ZoomSlider.prototype.initSlider_ = function() { var container = this.element; var containerSize = goog.style.getSize(container); + var thumb = goog.dom.getFirstElementChild(container); - var thumbBounds = goog.style.getBounds(thumb); var thumbMargins = goog.style.getMarginBox(thumb); - var thumbBorderBox = goog.style.getBorderBox(thumb); - var w = containerSize.width - - thumbMargins.left - thumbMargins.right - - thumbBorderBox.left - thumbBorderBox.right - - thumbBounds.width; - var h = containerSize.height - - thumbMargins.top - thumbMargins.bottom - - thumbBorderBox.top - thumbBorderBox.bottom - - thumbBounds.height; + var thumbBorderBoxSize = goog.style.getBorderBoxSize(thumb); + var thumbWidth = thumbBorderBoxSize.width + + thumbMargins.right + thumbMargins.left; + var thumbHeight = thumbBorderBoxSize.height + + 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, w, 0); + limits = new goog.math.Rect(0, 0, width, 0); } else { this.direction_ = ol.control.ZoomSlider.direction.VERTICAL; - limits = new goog.math.Rect(0, 0, 0, h); + limits = new goog.math.Rect(0, 0, 0, height); } this.dragger_.setLimits(limits); this.sliderInitialized_ = true; @@ -182,8 +192,9 @@ ol.control.ZoomSlider.prototype.handleMapPostrender = function(mapEvent) { ol.control.ZoomSlider.prototype.handleContainerClick_ = function(browserEvent) { var map = this.getMap(); var view = map.getView(); - var amountDragged = this.amountDragged_(browserEvent.offsetX, - browserEvent.offsetY); + var amountDragged = this.amountDragged_( + browserEvent.offsetX - this.thumbSize_[0] / 2, + browserEvent.offsetY - this.thumbSize_[1] / 2); var currentResolution = view.getResolution(); goog.asserts.assert(goog.isDef(currentResolution)); map.beforeRender(ol.animation.zoom({