From c29d9e5f141593e48a898cef951100e73a4501ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Thu, 3 Oct 2019 10:28:02 -0400 Subject: [PATCH 01/12] fix(direction)Now get the first coord of line/poly --- .../routing-form/routing-form.component.ts | 66 ++++--------------- 1 file changed, 12 insertions(+), 54 deletions(-) diff --git a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts index e76df32e4e..32783a285d 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts @@ -77,40 +77,13 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { // https://stackoverflow.com/questions/46364852/create-input-fields-dynamically-in-angular-2 - @Input() - get term() { - return this._term; - } - set term(value: string) { - this._term = value; - } - private _term = ''; + @Input() term: string; - get debounce() { - return this._debounce; - } - set debounce(value: number) { - this._debounce = value; - } - private _debounce = 200; + @Input() debounce: number = 200; - @Input() - get length() { - return this._length; - } - set length(value: number) { - this._length = value; - } - private _length = 3; + @Input() length: number = 2; - @Input() - get map(): IgoMap { - return this._map; - } - set map(value: IgoMap) { - this._map = value; - } - private _map: IgoMap; + @Input() map: IgoMap; @Output() submit: EventEmitter = new EventEmitter(); @@ -235,7 +208,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { this.routesQueries$$.push( this.stopsForm.statusChanges - .pipe(debounceTime(this._debounce)) + .pipe(debounceTime(this.debounce)) .subscribe(val => this.onFormChange()) ); @@ -277,7 +250,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { this.routesQueries$$.push( this.stream$ .pipe( - debounceTime(this._debounce), + debounceTime(this.debounce), distinctUntilChanged() ) .subscribe((term: string) => this.handleTermChanged(term)) @@ -988,28 +961,13 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { if (geom.type === 'Point') { geomCoord = geom.coordinates; } else if (geom.type.search('Line') >= 0) { - let coordArray = []; - if (geom.coordinates instanceof Array) { - // Middle segment of multilinestring - coordArray = - geom.coordinates[Math.floor(geom.coordinates.length / 2)]; - } else { - coordArray = geom.coordinates; - } - // middle point of coords - geomCoord = coordArray[Math.floor(coordArray.length / 2)]; - } else if (geom.type.search('Polygon') >= 0 && proposal.extent) { - const polygonExtent = proposal.extent; - const long = - polygonExtent[0] + (polygonExtent[2] - polygonExtent[0]) / 2; - const lat = - polygonExtent[1] + (polygonExtent[3] - polygonExtent[1]) / 2; - geomCoord = [long, lat]; - } else if (geom.type.search('Polygon') >= 0 && !proposal.extent) { + const line = (new OlGeoJSON()).readFeatures(geom); + geomCoord = line[0].getGeometry().getFirstCoordinate(); + geomCoord = [geomCoord[0], geomCoord[1]]; + } else if (geom.type.search('Polygon') >= 0) { const poly = (new OlGeoJSON()).readFeatures(geom); - // get the first feature of a multipolygon OR from the single feature of polygon. - geomCoord = poly[0].getGeometry().getInteriorPoints().getCoordinates() || poly.getGeometry().getInteriorPoints().getCoordinates(); - geomCoord = [geomCoord[0][0], geomCoord[0][1]]; + geomCoord = poly[0].getGeometry().getInteriorPoints().getCoordinates(); + geomCoord = [geomCoord[0], geomCoord[1]]; } if (geomCoord !== undefined) { From 87006bab79feb83aceb0308cb1b8225fa6a1baca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Thu, 3 Oct 2019 10:29:14 -0400 Subject: [PATCH 02/12] fix(direction) handle search term subscription --- .../src/lib/routing/routing-form/routing-form.component.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts index 32783a285d..343ded19da 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts @@ -58,6 +58,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { public projection = 'EPSG:4326'; public currentStopIndex: number; private routesQueries$$: Subscription[] = []; + private search$$: Subscription; private stream$ = new Subject(); @@ -896,9 +897,12 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { private handleTermChanged(term: string) { if (term !== undefined || term.length !== 0) { const searchProposals = []; + if (this.search$$) { + this.search$$.unsubscribe(); + } const researches = this.searchService.search(term, {searchType: 'Feature'}); researches.map(res => - this.routesQueries$$.push( + this.search$$ = res.request.subscribe(results => { results .filter(r => r.data.geometry) @@ -919,7 +923,6 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { .patchValue({ stopProposals: searchProposals }); this.changeDetectorRefs.detectChanges(); }) - ) ); } } From e2905b4522d044160c65859806e0d30bcf31d46d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Thu, 3 Oct 2019 11:41:58 -0400 Subject: [PATCH 03/12] refactor(routing) handling search result and title --- .../routing-form/routing-form.component.ts | 32 ++++++++++++------- .../routing-form/routing-form.service.ts | 19 +++++++++-- .../lib/routing/shared/routing.interface.ts | 5 +++ 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts index 343ded19da..034cb9789b 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts @@ -112,14 +112,11 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { this.unsubscribeRoutesQueries(); this.unlistenSingleClick(); this.queryService.queryEnabled = true; - const stopCoordinates = []; - this.stops.value.forEach(stop => { - stopCoordinates.push(stop.stopCoordinates); - }); + this.writeStopsToFormService(); this.routingRoutesOverlayDataSource.ol.clear(); this.routingStopsOverlayDataSource.ol.clear(); - this.routingFormService.setStopsCoordinates(stopCoordinates); + } ngOnInit() { @@ -260,6 +257,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { handleLocationProposals(coordinates: [number, number], stopIndex: number) { const groupedLocations = []; + this.stops.at(stopIndex).patchValue({ stopPoint: coordinates }); this.searchService .reverseSearch(coordinates, { zoom: this.map.getZoom() }) .map(res => @@ -302,6 +300,18 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { } else { // Not moving the translated point Only to suggest value into the UI. } + } else if (results[0].source.getId() === 'coordinatesreverse') { + this.stops.at(stopIndex).patchValue({ + stopPoint: getEntityTitle(results[0]) + }); + if (results[0].data.geometry.type === 'Point') { + this.stops.at(stopIndex).patchValue({ + stopCoordinates: + results[0].data.geometry.coordinates + }); + } else { + // Not moving the translated point Only to suggest value into the UI. + } } } else { this.stops.at(stopIndex).patchValue({ stopPoint: coordinates }); @@ -358,15 +368,14 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { return this.stopsForm.get('stops') as FormArray; } - getStopsCoordinates(): [number, number][] { - const stopCoordinates = []; + private writeStopsToFormService() { + const stops = []; this.stops.value.forEach(stop => { if (stop.stopCoordinates instanceof Array) { - stopCoordinates.push(stop.stopCoordinates); + stops.push(stop.stopCoordinates); } }); - this.routingFormService.setStopsCoordinates(stopCoordinates); - return stopCoordinates; + this.routingFormService.setStops(stops); } addStop(): void { @@ -413,7 +422,8 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { onFormChange() { if (this.stopsForm.valid) { this.routingRoutesOverlayDataSource.ol.clear(); - const coords = this.getStopsCoordinates(); + this.writeStopsToFormService(); + const coords = this.routingFormService.getStopsCoordinates(); if (coords.length >= 2) { this.getRoutes(coords); } else { diff --git a/packages/geo/src/lib/routing/routing-form/routing-form.service.ts b/packages/geo/src/lib/routing/routing-form/routing-form.service.ts index a9c229cfd9..ea07e54f54 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form.service.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form.service.ts @@ -1,17 +1,30 @@ import { Injectable } from '@angular/core'; +import { Stop } from '../shared/routing.interface'; @Injectable() export class RoutingFormService { private stopsCoordinates: [number, number][]; + private stops: Stop[] constructor() {} getStopsCoordinates(): [number, number][] { - return this.stopsCoordinates; + const stopsCoordinates = []; + if (this.stops) { + this.stops.forEach(stop => { + stopsCoordinates.push(stop.coords) + }); + } + return stopsCoordinates; } - setStopsCoordinates(stopsCoordinates) { - this.stopsCoordinates = stopsCoordinates; + + setStops(stops: Stop[]) { + this.stops = stops; + } + + getStops() { + return this.stops; } } diff --git a/packages/geo/src/lib/routing/shared/routing.interface.ts b/packages/geo/src/lib/routing/shared/routing.interface.ts index 22c4873b5e..19f55648b7 100644 --- a/packages/geo/src/lib/routing/shared/routing.interface.ts +++ b/packages/geo/src/lib/routing/shared/routing.interface.ts @@ -1,6 +1,11 @@ import { GeoJsonGeometryTypes } from 'geojson'; import { RoutingFormat, SourceRoutingType } from './routing.enum'; +export interface Stop { + title?: string; + coords?: [number, number]; +} + export interface Routing { id: string; source: string; From 96781e08941a3986fee7024d45419849e3c83463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Thu, 3 Oct 2019 12:36:19 -0400 Subject: [PATCH 04/12] refactor(direction) Coord rounded to 5 decimal --- .../lib/routing/routing-form/routing-form.component.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts index 034cb9789b..3086ae88a3 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts @@ -257,7 +257,8 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { handleLocationProposals(coordinates: [number, number], stopIndex: number) { const groupedLocations = []; - this.stops.at(stopIndex).patchValue({ stopPoint: coordinates }); + const roundedCoordinates = [coordinates[0].toFixed(5),coordinates[1].toFixed(5)] + this.stops.at(stopIndex).patchValue({ stopPoint: roundedCoordinates }); this.searchService .reverseSearch(coordinates, { zoom: this.map.getZoom() }) .map(res => @@ -302,7 +303,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { } } else if (results[0].source.getId() === 'coordinatesreverse') { this.stops.at(stopIndex).patchValue({ - stopPoint: getEntityTitle(results[0]) + stopPoint: [results[0].data.geometry.coordinates[0].toFixed(5),results[0].data.geometry.coordinates[1].toFixed(5)] }); if (results[0].data.geometry.type === 'Point') { this.stops.at(stopIndex).patchValue({ @@ -314,7 +315,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { } } } else { - this.stops.at(stopIndex).patchValue({ stopPoint: coordinates }); + this.stops.at(stopIndex).patchValue({ stopPoint: roundedCoordinates }); this.stops.at(stopIndex).patchValue({ stopProposals: [] }); } this.changeDetectorRefs.detectChanges(); @@ -372,7 +373,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { const stops = []; this.stops.value.forEach(stop => { if (stop.stopCoordinates instanceof Array) { - stops.push(stop.stopCoordinates); + stops.push({title: stop.stopPoint, coords: stop.stopCoordinates}); } }); this.routingFormService.setStops(stops); From dc8b5a2d27e0de16e875f6c48d31d5a025c8dda5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Thu, 3 Oct 2019 13:15:56 -0400 Subject: [PATCH 05/12] feat(direction) keep stop's title on component change. --- .../routing-form-binding.directive.ts | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts b/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts index e83041d1b5..2b2e5069ac 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts @@ -22,10 +22,9 @@ export class RoutingFormBindingDirective implements AfterViewInit { ) {} ngAfterViewInit(): void { - const storedStopsCoordinates = this.routingFormService.getStopsCoordinates(); + const storedStops = this.routingFormService.getStops(); if ( - !storedStopsCoordinates && - this.route && + !storedStops && this.route && this.route.options.routingCoordKey ) { this.route.queryParams.subscribe(params => { @@ -61,20 +60,17 @@ export class RoutingFormBindingDirective implements AfterViewInit { } } }); - } else if (storedStopsCoordinates) { - for (let i = 0; i < storedStopsCoordinates.length; i++) { - if (i !== 0 && i !== storedStopsCoordinates.length - 1) { + } else if (storedStops) { + for (let i = 0; i < storedStops.length; i++) { + if (i !== 0 && i !== storedStops.length - 1) { this.component.stops.insert(i, this.component.createStop()); } - if (storedStopsCoordinates[i] instanceof Array) { - this.component.addStopOverlay(storedStopsCoordinates[i], i); - this.component.stops - .at(i) - .patchValue({ stopCoordinates: storedStopsCoordinates[i] }); - this.component.stops - .at(i) - .patchValue({ stopPoint: storedStopsCoordinates[i] }); - this.component.handleLocationProposals(storedStopsCoordinates[i], i); + if (storedStops[i].coords instanceof Array) { + this.component.addStopOverlay(storedStops[i].coords, i); + this.component.stops.at(i).patchValue({ stopCoordinates: storedStops[i].coords }); + this.component.stops.at(i).patchValue({ stopPoint: storedStops[i].title }); + this.component.handleLocationProposals(storedStops[i].coords, i); + } } } From 45800b53f93312146cfe4242f0098908d6030414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Thu, 3 Oct 2019 13:17:40 -0400 Subject: [PATCH 06/12] fix(directions) Trigger and show route results on component change --- .../routing-form-binding.directive.ts | 1 + .../routing-form/routing-form.component.ts | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts b/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts index 2b2e5069ac..2c9fd1c665 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts @@ -74,5 +74,6 @@ export class RoutingFormBindingDirective implements AfterViewInit { } } } + this.component.onFormChange(); } } diff --git a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts index 3086ae88a3..7237c4e342 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts @@ -66,6 +66,8 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { public RoutingOverlayStyle: olstyle.Style; public routingStopsOverlayDataSource: FeatureDataSource; public routingRoutesOverlayDataSource: FeatureDataSource; + private stopsLayer + private routesLayer public routesResults: Routing[] | Message[]; public activeRoute: Routing; @@ -116,6 +118,8 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { this.writeStopsToFormService(); this.routingRoutesOverlayDataSource.ol.clear(); this.routingStopsOverlayDataSource.ol.clear(); + this.map.removeLayer(this.stopsLayer); + this.map.removeLayer(this.routesLayer); } @@ -139,47 +143,47 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { ngAfterViewInit(): void { this.queryService.queryEnabled = false; this.focusOnStop = false; - const stopsLayer = new VectorLayer({ + this.stopsLayer = new VectorLayer({ title: 'routingStopOverlay', zIndex: 999, id: 'routingStops', source: this.routingStopsOverlayDataSource, - showInLayerList: false + showInLayerList: true }); - const routesLayer = new VectorLayer({ + this.routesLayer = new VectorLayer({ title: 'routingRoutesOverlay', zIndex: 999, id: 'routingRoutes', opacity: 0.75, source: this.routingRoutesOverlayDataSource, - showInLayerList: false + showInLayerList: true }); - this.map.addLayer(routesLayer); - this.map.addLayer(stopsLayer); + this.map.addLayer(this.routesLayer); + this.map.addLayer(this.stopsLayer); let selectedStopFeature; const selectStops = new olinteraction.Select({ - layers: [stopsLayer.ol], + layers: [this.stopsLayer.ol], condition: olcondition.pointerMove, hitTolerance: 7 }); const translateStop = new olinteraction.Translate({ - layers: [stopsLayer.ol], + layers: [this.stopsLayer.ol], features: selectedStopFeature }); // TODO: Check to disable pointermove IF a stop is already selected const selectRouteHover = new olinteraction.Select({ - layers: [routesLayer.ol], + layers: [this.routesLayer.ol], condition: olcondition.pointerMove, hitTolerance: 7 }); this.selectRoute = new olinteraction.Select({ - layers: [routesLayer.ol], + layers: [this.routesLayer.ol], hitTolerance: 7 }); From 191fa2c8523d1a83a74ab3518381f458346e800d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Thu, 3 Oct 2019 13:18:15 -0400 Subject: [PATCH 07/12] refactor(direction) show coordinates as string --- .../src/lib/routing/routing-form/routing-form.component.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts index 7237c4e342..f4ff46fd9c 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts @@ -262,7 +262,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { handleLocationProposals(coordinates: [number, number], stopIndex: number) { const groupedLocations = []; const roundedCoordinates = [coordinates[0].toFixed(5),coordinates[1].toFixed(5)] - this.stops.at(stopIndex).patchValue({ stopPoint: roundedCoordinates }); + this.stops.at(stopIndex).patchValue({ stopPoint: roundedCoordinates.join(',') }); this.searchService .reverseSearch(coordinates, { zoom: this.map.getZoom() }) .map(res => @@ -307,7 +307,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { } } else if (results[0].source.getId() === 'coordinatesreverse') { this.stops.at(stopIndex).patchValue({ - stopPoint: [results[0].data.geometry.coordinates[0].toFixed(5),results[0].data.geometry.coordinates[1].toFixed(5)] + stopPoint: [results[0].data.geometry.coordinates[0].toFixed(5),results[0].data.geometry.coordinates[1].toFixed(5)].join(',') }); if (results[0].data.geometry.type === 'Point') { this.stops.at(stopIndex).patchValue({ @@ -319,7 +319,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { } } } else { - this.stops.at(stopIndex).patchValue({ stopPoint: roundedCoordinates }); + this.stops.at(stopIndex).patchValue({ stopPoint: roundedCoordinates.join(',') }); this.stops.at(stopIndex).patchValue({ stopProposals: [] }); } this.changeDetectorRefs.detectChanges(); From d11bf09fd3979ff918e57a5a88664dc93bc1069f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Thu, 3 Oct 2019 13:37:28 -0400 Subject: [PATCH 08/12] lint --- .../routing-form-binding.directive.ts | 1 - .../routing-form/routing-form.component.ts | 55 ++++++++++--------- .../routing-form/routing-form.service.ts | 6 +- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts b/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts index 2c9fd1c665..14e6f000f4 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts @@ -70,7 +70,6 @@ export class RoutingFormBindingDirective implements AfterViewInit { this.component.stops.at(i).patchValue({ stopCoordinates: storedStops[i].coords }); this.component.stops.at(i).patchValue({ stopPoint: storedStops[i].title }); this.component.handleLocationProposals(storedStops[i].coords, i); - } } } diff --git a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts index f4ff46fd9c..aebad192a1 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts @@ -66,8 +66,8 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { public RoutingOverlayStyle: olstyle.Style; public routingStopsOverlayDataSource: FeatureDataSource; public routingRoutesOverlayDataSource: FeatureDataSource; - private stopsLayer - private routesLayer + private stopsLayer; + private routesLayer; public routesResults: Routing[] | Message[]; public activeRoute: Routing; @@ -261,7 +261,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { handleLocationProposals(coordinates: [number, number], stopIndex: number) { const groupedLocations = []; - const roundedCoordinates = [coordinates[0].toFixed(5),coordinates[1].toFixed(5)] + const roundedCoordinates = [coordinates[0].toFixed(5), coordinates[1].toFixed(5)]; this.stops.at(stopIndex).patchValue({ stopPoint: roundedCoordinates.join(',') }); this.searchService .reverseSearch(coordinates, { zoom: this.map.getZoom() }) @@ -307,7 +307,10 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { } } else if (results[0].source.getId() === 'coordinatesreverse') { this.stops.at(stopIndex).patchValue({ - stopPoint: [results[0].data.geometry.coordinates[0].toFixed(5),results[0].data.geometry.coordinates[1].toFixed(5)].join(',') + stopPoint: [ + results[0].data.geometry.coordinates[0].toFixed(5), + results[0].data.geometry.coordinates[1].toFixed(5) + ].join(',') }); if (results[0].data.geometry.type === 'Point') { this.stops.at(stopIndex).patchValue({ @@ -316,7 +319,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { }); } else { // Not moving the translated point Only to suggest value into the UI. - } + } } } else { this.stops.at(stopIndex).patchValue({ stopPoint: roundedCoordinates.join(',') }); @@ -917,27 +920,27 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { } const researches = this.searchService.search(term, {searchType: 'Feature'}); researches.map(res => - this.search$$ = - res.request.subscribe(results => { - results - .filter(r => r.data.geometry) - .forEach(element => { - if ( - searchProposals.filter(r => r.source === element.source) - .length === 0 - ) { - searchProposals.push({ - source: element.source, - meta: element.meta, - results: results.map(r => r.data) - }); - } - }); - this.stops - .at(this.currentStopIndex) - .patchValue({ stopProposals: searchProposals }); - this.changeDetectorRefs.detectChanges(); - }) + this.search$$ = + res.request.subscribe(results => { + results + .filter(r => r.data.geometry) + .forEach(element => { + if ( + searchProposals.filter(r => r.source === element.source) + .length === 0 + ) { + searchProposals.push({ + source: element.source, + meta: element.meta, + results: results.map(r => r.data) + }); + } + }); + this.stops + .at(this.currentStopIndex) + .patchValue({ stopProposals: searchProposals }); + this.changeDetectorRefs.detectChanges(); + }) ); } } diff --git a/packages/geo/src/lib/routing/routing-form/routing-form.service.ts b/packages/geo/src/lib/routing/routing-form/routing-form.service.ts index ea07e54f54..4e96852c2e 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form.service.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form.service.ts @@ -3,8 +3,7 @@ import { Stop } from '../shared/routing.interface'; @Injectable() export class RoutingFormService { - private stopsCoordinates: [number, number][]; - private stops: Stop[] + private stops: Stop[]; constructor() {} @@ -12,13 +11,12 @@ export class RoutingFormService { const stopsCoordinates = []; if (this.stops) { this.stops.forEach(stop => { - stopsCoordinates.push(stop.coords) + stopsCoordinates.push(stop.coords); }); } return stopsCoordinates; } - setStops(stops: Stop[]) { this.stops = stops; } From d3286edb8b2e3bdecf51411105e5e72a980e98e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Thu, 3 Oct 2019 13:43:10 -0400 Subject: [PATCH 09/12] typo --- .../src/lib/routing/routing-form/routing-form.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts index aebad192a1..a2c521fc11 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts @@ -148,7 +148,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { zIndex: 999, id: 'routingStops', source: this.routingStopsOverlayDataSource, - showInLayerList: true + showInLayerList: false }); this.routesLayer = new VectorLayer({ title: 'routingRoutesOverlay', @@ -156,7 +156,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { id: 'routingRoutes', opacity: 0.75, source: this.routingRoutesOverlayDataSource, - showInLayerList: true + showInLayerList: false }); this.map.addLayer(this.routesLayer); From 044c04f110789ad8267bfdd4c92ed7d4d9036597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Thu, 3 Oct 2019 14:34:20 -0400 Subject: [PATCH 10/12] i18n(routing) Wrong language. --- packages/geo/src/locale/en.geo.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/geo/src/locale/en.geo.json b/packages/geo/src/locale/en.geo.json index b954754bae..57edcb07b0 100644 --- a/packages/geo/src/locale/en.geo.json +++ b/packages/geo/src/locale/en.geo.json @@ -194,11 +194,11 @@ } }, "routing": { - "uturn": "demi-tour", - "sharp right": "fortement à droite", + "uturn": "u-turn", + "sharp right": "sharp right", "right": "right", "slight right": "slightly on right", - "sharp left": "fortement à gauche", + "sharp left": "sharp left", "left": "left", "slight left": "slightly on left", "straight": "forward" @@ -207,7 +207,7 @@ "n": "north", "ne": "northeast", "e": "east", - "se": "Southeast", + "se": "southeast", "s": "south", "sw": "southwest", "w": "west", From 99e89f8c9144a61a48681b1e1b03fb128f11e475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Thu, 3 Oct 2019 14:42:10 -0400 Subject: [PATCH 11/12] refactor(directions) keep stop's title on component change --- .../lib/routing/routing-form/routing-form-binding.directive.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts b/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts index 14e6f000f4..52a3ee5941 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts @@ -69,7 +69,6 @@ export class RoutingFormBindingDirective implements AfterViewInit { this.component.addStopOverlay(storedStops[i].coords, i); this.component.stops.at(i).patchValue({ stopCoordinates: storedStops[i].coords }); this.component.stops.at(i).patchValue({ stopPoint: storedStops[i].title }); - this.component.handleLocationProposals(storedStops[i].coords, i); } } } From 8cc3e1928e6366e2e17fa507ddace01cf22a493a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= Date: Thu, 3 Oct 2019 14:55:46 -0400 Subject: [PATCH 12/12] refactor(directions) Stop interface --- .../routing/routing-form/routing-form-binding.directive.ts | 7 +++---- .../src/lib/routing/routing-form/routing-form.component.ts | 2 +- .../src/lib/routing/routing-form/routing-form.service.ts | 2 +- packages/geo/src/lib/routing/shared/routing.interface.ts | 6 ++++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts b/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts index 52a3ee5941..ea0398bdff 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form-binding.directive.ts @@ -65,10 +65,9 @@ export class RoutingFormBindingDirective implements AfterViewInit { if (i !== 0 && i !== storedStops.length - 1) { this.component.stops.insert(i, this.component.createStop()); } - if (storedStops[i].coords instanceof Array) { - this.component.addStopOverlay(storedStops[i].coords, i); - this.component.stops.at(i).patchValue({ stopCoordinates: storedStops[i].coords }); - this.component.stops.at(i).patchValue({ stopPoint: storedStops[i].title }); + if (storedStops[i].stopCoordinates instanceof Array) { + this.component.addStopOverlay(storedStops[i].stopCoordinates, i); + this.component.stops.at(i).patchValue(storedStops[i] ); } } } diff --git a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts index a2c521fc11..800710233d 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts @@ -380,7 +380,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { const stops = []; this.stops.value.forEach(stop => { if (stop.stopCoordinates instanceof Array) { - stops.push({title: stop.stopPoint, coords: stop.stopCoordinates}); + stops.push(stop); } }); this.routingFormService.setStops(stops); diff --git a/packages/geo/src/lib/routing/routing-form/routing-form.service.ts b/packages/geo/src/lib/routing/routing-form/routing-form.service.ts index 4e96852c2e..f8bece6bd2 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form.service.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form.service.ts @@ -11,7 +11,7 @@ export class RoutingFormService { const stopsCoordinates = []; if (this.stops) { this.stops.forEach(stop => { - stopsCoordinates.push(stop.coords); + stopsCoordinates.push(stop.stopCoordinates); }); } return stopsCoordinates; diff --git a/packages/geo/src/lib/routing/shared/routing.interface.ts b/packages/geo/src/lib/routing/shared/routing.interface.ts index 19f55648b7..6298424847 100644 --- a/packages/geo/src/lib/routing/shared/routing.interface.ts +++ b/packages/geo/src/lib/routing/shared/routing.interface.ts @@ -2,8 +2,10 @@ import { GeoJsonGeometryTypes } from 'geojson'; import { RoutingFormat, SourceRoutingType } from './routing.enum'; export interface Stop { - title?: string; - coords?: [number, number]; + stopPoint?: string; + stopProposals?: []; + routingText?: string; + stopCoordinates?: [number, number]; } export interface Routing {