From 333899ca518b6ad7080e7e9ddb0492d4ba4c5d51 Mon Sep 17 00:00:00 2001 From: mourner Date: Mon, 14 Jan 2013 00:23:45 +0200 Subject: [PATCH] add Popup zoomAnimation option, fix #999 --- src/layer/Popup.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/layer/Popup.js b/src/layer/Popup.js index 5e23ce80..d94e9002 100644 --- a/src/layer/Popup.js +++ b/src/layer/Popup.js @@ -17,13 +17,15 @@ L.Popup = L.Class.extend({ closeButton: true, offset: new L.Point(0, 6), autoPanPadding: new L.Point(5, 5), - className: '' + className: '', + zoomAnimation: true }, initialize: function (options, source) { L.setOptions(this, options); this._source = source; + this._animated = L.Browser.any3d && this.options.zoomAnimation; }, onAdd: function (map) { @@ -43,7 +45,7 @@ L.Popup = L.Class.extend({ map.on('viewreset', this._updatePosition, this); - if (L.Browser.any3d) { + if (this._animated) { map.on('zoomanim', this._zoomAnimation, this); } @@ -112,7 +114,8 @@ L.Popup = L.Class.extend({ _initLayout: function () { var prefix = 'leaflet-popup', - containerClass = prefix + ' ' + this.options.className + ' leaflet-zoom-animated', + containerClass = prefix + ' ' + this.options.className + ' leaflet-zoom-' + + (this._animated ? 'animated' : 'hide'), container = this._container = L.DomUtil.create('div', containerClass), closeButton; @@ -198,15 +201,15 @@ L.Popup = L.Class.extend({ if (!this._map) { return; } var pos = this._map.latLngToLayerPoint(this._latlng), - is3d = L.Browser.any3d, + animated = this._animated, offset = this.options.offset; - if (is3d) { + if (animated) { L.DomUtil.setPosition(this._container, pos); } - this._containerBottom = -offset.y - (is3d ? 0 : pos.y); - this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x + (is3d ? 0 : pos.x); + this._containerBottom = -offset.y - (animated ? 0 : pos.y); + this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x + (animated ? 0 : pos.x); //Bottom position the popup in case the height of the popup changes (images loading etc) this._container.style.bottom = this._containerBottom + 'px'; @@ -228,7 +231,7 @@ L.Popup = L.Class.extend({ layerPos = new L.Point(this._containerLeft, -containerHeight - this._containerBottom); - if (L.Browser.any3d) { + if (this._animated) { layerPos._add(L.DomUtil.getPosition(this._container)); }