Skip to content

Commit

Permalink
fix(routing) unlisten to singleclick event when leaving component. (#227
Browse files Browse the repository at this point in the history
)
  • Loading branch information
pelord authored and gignacnic committed Nov 8, 2018
1 parent 16d6192 commit 52b043c
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as olstyle from 'ol/style';
import * as olcondition from 'ol/events/condition';
import * as olinteraction from 'ol/interaction';
import * as olextent from 'ol/extent';
import * as olobservable from 'ol/Observable';

import { Clipboard } from '@igo2/utils';
import { Message, LanguageService, MessageService, RouteService } from '@igo2/core';
Expand Down Expand Up @@ -59,6 +60,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy {
private selectRoute;

private focusOnStop = false;
private focusKey = [];
public initialStopsCoords;
private browserLanguage;

Expand Down Expand Up @@ -119,6 +121,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy {

ngOnDestroy(): void {
this.unsubscribeRoutesQueries();
this.unlistenSingleClick();
this.queryService.queryEnabled = true;
const stopCoordinates = [];

Expand Down Expand Up @@ -184,7 +187,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy {
const selectRouteHover = new olinteraction.Select({
layers: [routesLayer.ol],
condition: olcondition.pointerMove,
hitTolerance: 7
hitTolerance: 10
});

this.selectRoute = new olinteraction.Select({
Expand Down Expand Up @@ -793,6 +796,14 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy {
}
}

private unlistenSingleClick() {
if (this.focusKey.length !== 0) {
this.focusKey.forEach(key => {
olobservable.unByKey(key);
});
}
}

private unsubscribeRoutesQueries() {
this.routesQueries$$.forEach((sub: Subscription) => sub.unsubscribe());
this.routesQueries$$ = [];
Expand Down Expand Up @@ -994,12 +1005,13 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy {
}

focus(i) {
this.unlistenSingleClick();
this.currentStopIndex = i;
this.focusOnStop = true;
this.routingFormService.setMapWaitingForRoutingClick();
this.map.ol.once('singleclick', evt => {
this.focusKey.push(this.map.ol.once('singleclick', evt => {
this.handleMapClick(evt, i);
});
}));
}

private handleMapClick(event: olcondition, indexPos?) {
Expand Down

0 comments on commit 52b043c

Please sign in to comment.