Skip to content

Commit

Permalink
Fix marker popup location (#8523)
Browse files Browse the repository at this point in the history
Co-authored-by: Jon Koops <jonkoops@gmail.com>
  • Loading branch information
raychanks and jonkoops committed Oct 4, 2022
1 parent bbda3d7 commit 0877196
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions spec/suites/layer/PopupSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,20 @@ describe('Popup', function () {
done();
}, 800);
});

it("shows the popup at the correct location when multiple markers are registered", function () {
var popup = L.popup();
var marker1 = L.marker([86, 32]).bindPopup(popup).addTo(map);
var marker2 = L.marker([26.3, 83.9]).bindPopup(popup).addTo(map);

expect(popup.getLatLng()).to.be(undefined);

marker1.openPopup();
expect(popup.getLatLng()).to.be.nearLatLng([86, 32]);

marker2.openPopup();
expect(popup.getLatLng()).to.be.nearLatLng([26.3, 83.9]);
});
});

describe('L.Layer#_popup', function () {
Expand Down
3 changes: 2 additions & 1 deletion src/layer/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ Layer.include({
// @method openPopup(latlng?: LatLng): this
// Opens the bound popup at the specified `latlng` or at the default popup anchor if no `latlng` is passed.
openPopup: function (latlng) {
if (this._popup && this._popup._prepareOpen(latlng)) {
if (this._popup && this._popup._prepareOpen(latlng || this._latlng)) {

// open the popup on the map
this._popup.openOn(this._map);
}
Expand Down

0 comments on commit 0877196

Please sign in to comment.