diff --git a/debug/map/popup.html b/debug/map/popup.html index a177fefa..25cd792f 100644 --- a/debug/map/popup.html +++ b/debug/map/popup.html @@ -36,25 +36,23 @@ var features = new L.FeatureGroup(); - for (var i = 0; i < 10000; i++) { - var marker = L.marker(getRandomLatLng(map)).addTo(features); - } + var marker = L.marker(getRandomLatLng(map)).addTo(features); - // var line = L.polyline([ - // getRandomLatLng(map), - // getRandomLatLng(map), - // getRandomLatLng(map) - // ]).addTo(features); + var line = L.polyline([ + getRandomLatLng(map), + getRandomLatLng(map), + getRandomLatLng(map) + ]).addTo(features); - // var poly = L.polygon([ - // getRandomLatLng(map), - // getRandomLatLng(map), - // getRandomLatLng(map), - // getRandomLatLng(map) - // ]).addTo(features); + var poly = L.polygon([ + getRandomLatLng(map), + getRandomLatLng(map), + getRandomLatLng(map), + getRandomLatLng(map) + ]).addTo(features); features.bindPopup(function(layer){ - return layer._leaflet_id + 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.
Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. Aenean dignissim pellentesque.'; + return 'Leaflet ID is ' + layer._leaflet_id; }).addTo(map); L.DomUtil.get('change').onclick = function(){ diff --git a/spec/suites/layer/PopupSpec.js b/spec/suites/layer/PopupSpec.js index 09e8b725..36244754 100644 --- a/spec/suites/layer/PopupSpec.js +++ b/spec/suites/layer/PopupSpec.js @@ -56,9 +56,9 @@ describe('Popup', function () { happen.click(c); // toggle open popup - sinon.spy(marker, "openPopup"); + sinon.spy(marker, "_openPopup"); marker.fire('click'); - expect(marker.openPopup.calledOnce).to.be(true); + expect(marker._openPopup.calledOnce).to.be(true); expect(map.hasLayer(marker._popup)).to.be(true); marker.openPopup.restore(); diff --git a/src/layer/Layer.Popup.js b/src/layer/Layer.Popup.js index db7a0de5..52e0d435 100644 --- a/src/layer/Layer.Popup.js +++ b/src/layer/Layer.Popup.js @@ -79,12 +79,16 @@ L.Layer.include({ }, _openPopup: function (e) { - this._popup.options.offset = this._popupAnchor(e.layer || e.target); - if(typeof this._popup._content === 'function') { + if(this._popup && this._map && this._map.hasLayer(this._popup) && this._popup._source === e.layer){ + this.closePopup(); + } else { + this._popup.options.offset = this._popupAnchor(e.layer || e.target); this._popup._source = e.layer; - this._popup.update(); + if(typeof this._popup._content === 'function') { + this._popup.update(); + } + this._map.openPopup(this._popup, e.latlng); } - this._map.openPopup(this._popup, e.latlng); }, _popupAnchor: function(layer){