Skip to content

Commit

Permalink
Allow setting popup before LngLat
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Dec 19, 2017
1 parent dcb94f0 commit 9a5af4e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ui/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class Marker {
popup.options.offset = this._offset;
}
this._popup = popup;
this._popup.setLngLat(this._lngLat);
if (this._lngLat) this._popup.setLngLat(this._lngLat);
}

return this;
Expand Down
12 changes: 12 additions & 0 deletions test/unit/ui/marker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const window = require('../../../src/util/window');
const Map = require('../../../src/ui/map');
const Marker = require('../../../src/ui/marker');
const Popup = require('../../../src/ui/popup');
const LngLat = require('../../../src/geo/lng_lat');

function createMap() {
const container = window.document.createElement('div');
Expand Down Expand Up @@ -63,6 +64,17 @@ test('Marker', (t) => {
t.end();
});

t.test('popups can be set before LngLat', (t) => {
const map = createMap();
const popup = new Popup();
const marker = new Marker(window.document.createElement('div'))
.setPopup(popup)
.setLngLat([-77.01866, 38.888])
.addTo(map);
t.deepEqual(popup.getLngLat(), new LngLat(-77.01866, 38.888));
t.end();
});

t.test('marker centered by default', (t) => {
const map = createMap();
const element = window.document.createElement('div');
Expand Down

0 comments on commit 9a5af4e

Please sign in to comment.