Skip to content

Commit a2c9337

Browse files
committed
fix conflicts of InfoWindow's autoOpenOn and autoCloseOn
1 parent ae27ba8 commit a2c9337

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/ui/InfoWindow.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,13 @@ class InfoWindow extends UIComponent {
219219

220220
_onAutoOpen(e) {
221221
const owner = this.getOwner();
222-
if (owner instanceof Marker) {
223-
this.show(owner.getCoordinates());
224-
} else {
225-
this.show(e.coordinate);
226-
}
222+
setTimeout(() => {
223+
if (owner instanceof Marker) {
224+
this.show(owner.getCoordinates());
225+
} else {
226+
this.show(e.coordinate);
227+
}
228+
}, 1);
227229
}
228230

229231
_getWindowWidth() {

test/geometry/ui/Geometry.InfowindowSpec.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('Geometry.InfoWindow', function () {
6868
expect(position.round().toArray()).to.be.eql([633, 25]);
6969
});
7070

71-
it('autoOpen on click', function () {
71+
it('autoOpen on click', function (done) {
7272
var marker = new maptalks.Marker(center);
7373
marker.addTo(layer);
7474
var options = {
@@ -79,9 +79,12 @@ describe('Geometry.InfoWindow', function () {
7979
};
8080
marker.setInfoWindow(options);
8181
marker._fireEvent('click');
82-
var w = marker.getInfoWindow();
83-
var position = w._getViewPoint();
84-
expect(position.round().toArray()).to.be.eql([400, 300]);
82+
setTimeout(function () {
83+
var w = marker.getInfoWindow();
84+
var position = w._getViewPoint();
85+
expect(position.round().toArray()).to.be.eql([400, 300]);
86+
done();
87+
}, 2);
8588
});
8689

8790
it('close when layer is removed', function () {
@@ -124,7 +127,7 @@ describe('Geometry.InfoWindow', function () {
124127
expect(w.isVisible()).not.to.be.ok();
125128
});
126129

127-
it('reopen infowindow at right position', function () {
130+
it('reopen infowindow at right position', function (done) {
128131
var marker = new maptalks.Marker(center);
129132
marker.addTo(layer);
130133
var options = {
@@ -141,9 +144,12 @@ describe('Geometry.InfoWindow', function () {
141144

142145
marker.setCoordinates(map.containerPointToCoord(new maptalks.Point(20, 20)));
143146
marker.fire('click');
144-
var pos2 = w.getPosition().toArray();
145-
expect(pos2[0] < pos[0] - 100).to.be.ok();
146-
expect(pos2[1] < pos[1] - 100).to.be.ok();
147+
setTimeout(function () {
148+
var pos2 = w.getPosition().toArray();
149+
expect(pos2[0] < pos[0] - 100).to.be.ok();
150+
expect(pos2[1] < pos[1] - 100).to.be.ok();
151+
done();
152+
}, 2);
147153
});
148154

149155
it('auto close infowindow on touchstart', function () {
@@ -489,7 +495,7 @@ describe('Geometry.InfoWindow', function () {
489495
var infoWindow2 = new maptalks.ui.InfoWindow(options);
490496
var geo2 = new maptalks.Marker(map.getExtent().getMin());
491497
layer.addGeometry(geo, geo2);
492-
498+
493499
infoWindow1.addTo(geo).show();
494500
infoWindow2.addTo(geo2);
495501

0 commit comments

Comments
 (0)