Skip to content

Commit

Permalink
fix(popup): do not send open/close event when moving an opened popup
Browse files Browse the repository at this point in the history
fix #48
  • Loading branch information
Wykks committed Aug 4, 2018
1 parent 4c49629 commit 2b6f712
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions projects/ngx-mapbox-gl/src/lib/map/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,11 @@ export class MapService {
});
}

addPopupToMap(popup: MapboxGl.Popup, lngLat: MapboxGl.LngLatLike) {
addPopupToMap(popup: MapboxGl.Popup, lngLat: MapboxGl.LngLatLike, skipOpenEvent = false) {
return this.zone.runOutsideAngular(() => {
if (skipOpenEvent && (<any>popup)._listeners) {
delete (<any>popup)._listeners['open'];
}
popup.setLngLat(lngLat);
popup.addTo(this.mapInstance);
});
Expand All @@ -341,7 +344,10 @@ export class MapService {
});
}

removePopupFromMap(popup: MapboxGl.Popup) {
removePopupFromMap(popup: MapboxGl.Popup, skipCloseEvent = false) {
if (skipCloseEvent && (<any>popup)._listeners) {
delete (<any>popup)._listeners['close'];
}
this.popupsToRemove.push(popup);
}

Expand Down
4 changes: 2 additions & 2 deletions projects/ngx-mapbox-gl/src/lib/popup/popup.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export class PopupComponent implements OnChanges, OnDestroy, AfterViewInit, OnIn

ngOnChanges(changes: SimpleChanges) {
if (changes.lngLat && !changes.lngLat.isFirstChange()) {
this.MapService.removePopupFromMap(this.popupInstance!);
this.MapService.removePopupFromMap(this.popupInstance!, true);
const popupInstanceTmp = this.createPopup();
this.MapService.addPopupToMap(popupInstanceTmp, changes.lngLat.currentValue);
this.MapService.addPopupToMap(popupInstanceTmp, changes.lngLat.currentValue, this.popupInstance!.isOpen());
this.popupInstance = popupInstanceTmp;
}
if (changes.marker && !changes.marker.isFirstChange()) {
Expand Down

1 comment on commit 2b6f712

@antonsimola
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

Please sign in to comment.