From 7a800d4b3944ce9779280c2237411f7ff41a8157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bobo=20H=C3=A4ggstr=C3=B6m?= Date: Thu, 19 Oct 2017 15:11:49 +0200 Subject: [PATCH] Add support to specify CSS class name when creating ol.Overlay --- externs/olx.js | 9 ++++++++- src/ol/overlay.js | 3 ++- test/spec/ol/overlay.test.js | 6 ++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/externs/olx.js b/externs/olx.js index c4a5ebb218..e83a92d11b 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -521,7 +521,8 @@ olx.AtPixelOptions.prototype.hitTolerance; * insertFirst: (boolean|undefined), * autoPan: (boolean|undefined), * autoPanAnimation: (olx.OverlayPanOptions|undefined), - * autoPanMargin: (number|undefined)}} + * autoPanMargin: (number|undefined), + * className: (string|undefined)}} */ olx.OverlayOptions; @@ -623,6 +624,12 @@ olx.OverlayOptions.prototype.autoPanAnimation; */ olx.OverlayOptions.prototype.autoPanMargin; +/** + * CSS class name. Default is `ol-overlay-container ol-selectable`. + * @type {string|undefined} + * @api + */ +olx.OverlayOptions.prototype.className; /** * @typedef {{ diff --git a/src/ol/overlay.js b/src/ol/overlay.js index 8d3efda52c..e555b8c3d4 100644 --- a/src/ol/overlay.js +++ b/src/ol/overlay.js @@ -59,7 +59,8 @@ ol.Overlay = function(options) { * @type {Element} */ this.element_ = document.createElement('DIV'); - this.element_.className = 'ol-overlay-container ' + ol.css.CLASS_SELECTABLE; + this.element_.className = options.className !== undefined ? + options.className : 'ol-overlay-container ' + ol.css.CLASS_SELECTABLE; this.element_.style.position = 'absolute'; /** diff --git a/test/spec/ol/overlay.test.js b/test/spec/ol/overlay.test.js index bfe615bb22..a6c3fe002d 100644 --- a/test/spec/ol/overlay.test.js +++ b/test/spec/ol/overlay.test.js @@ -44,6 +44,12 @@ describe('ol.Overlay', function() { expect(instance).to.be.an(ol.Overlay); }); + it('can be constructed with className', function() { + var instance = new ol.Overlay({className: 'my-class'}); + expect(instance).to.be.an(ol.Overlay); + expect(instance.element_.className).to.be('my-class'); + }); + }); describe('#getId()', function() {