From 3fe3beb28a8929c92952c0da08171898a84c2899 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Thu, 13 Mar 2014 15:06:02 +0100 Subject: [PATCH 1/2] Add offsetX and offsetY config options for ol.Overlay --- src/objectliterals.jsdoc | 4 ++++ src/ol/overlay.js | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 5a3586aab8..d992f0cbd8 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -74,6 +74,10 @@ * overlay is placed in the same container as that of the controls (see * the `stopEvent` option) you will probably set `insertFirst` to `true` * so the overlay is displayed below the controls. + * @property {number|undefined} offsetX Horizontal offset in pixels. + * A positive will shift the overlay right. Default is `0`. + * @property {number|undefined} offsetY Vertical offset in pixels. + * A positive will shift the overlay down. Default is `0`. * @todo stability experimental */ diff --git a/src/ol/overlay.js b/src/ol/overlay.js index c2221ee7f2..a7d5f4781e 100644 --- a/src/ol/overlay.js +++ b/src/ol/overlay.js @@ -81,6 +81,18 @@ ol.Overlay = function(options) { */ this.stopEvent_ = goog.isDef(options.stopEvent) ? options.stopEvent : true; + /** + * @private + * @type {number} + */ + this.offsetX_ = goog.isDef(options.offsetX) ? options.offsetX : 0; + + /** + * @private + * @type {number} + */ + this.offsetY_ = goog.isDef(options.offsetY) ? options.offsetY : 0; + /** * @private * @type {Element} @@ -355,7 +367,7 @@ ol.Overlay.prototype.updatePixelPosition_ = function() { if (this.rendered_.right_ !== '') { this.rendered_.right_ = style.right = ''; } - var offsetX = 0; + var offsetX = -this.offsetX_; if (positioning == ol.OverlayPositioning.BOTTOM_CENTER || positioning == ol.OverlayPositioning.CENTER_CENTER || positioning == ol.OverlayPositioning.TOP_CENTER) { @@ -380,7 +392,7 @@ ol.Overlay.prototype.updatePixelPosition_ = function() { if (this.rendered_.bottom_ !== '') { this.rendered_.bottom_ = style.bottom = ''; } - var offsetY = 0; + var offsetY = -this.offsetY_; if (positioning == ol.OverlayPositioning.CENTER_LEFT || positioning == ol.OverlayPositioning.CENTER_CENTER || positioning == ol.OverlayPositioning.CENTER_RIGHT) { From 731e37349e0bd199fd04d5fa5f17fb16c015efc7 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Thu, 13 Mar 2014 15:34:45 +0100 Subject: [PATCH 2/2] Combine offsetX and offsetY with positioning --- src/ol/overlay.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ol/overlay.js b/src/ol/overlay.js index a7d5f4781e..75bdc27980 100644 --- a/src/ol/overlay.js +++ b/src/ol/overlay.js @@ -371,7 +371,7 @@ ol.Overlay.prototype.updatePixelPosition_ = function() { if (positioning == ol.OverlayPositioning.BOTTOM_CENTER || positioning == ol.OverlayPositioning.CENTER_CENTER || positioning == ol.OverlayPositioning.TOP_CENTER) { - offsetX = goog.style.getSize(this.element_).width / 2; + offsetX += goog.style.getSize(this.element_).width / 2; } var left = Math.round(pixel[0] - offsetX) + 'px'; if (this.rendered_.left_ != left) { @@ -396,7 +396,7 @@ ol.Overlay.prototype.updatePixelPosition_ = function() { if (positioning == ol.OverlayPositioning.CENTER_LEFT || positioning == ol.OverlayPositioning.CENTER_CENTER || positioning == ol.OverlayPositioning.CENTER_RIGHT) { - offsetY = goog.style.getSize(this.element_).height / 2; + offsetY += goog.style.getSize(this.element_).height / 2; } var top = Math.round(pixel[1] - offsetY) + 'px'; if (this.rendered_.top_ != top) {