Skip to content

Commit

Permalink
feat(directions): let the layer into the layer list (to be printed) (#…
Browse files Browse the repository at this point in the history
…845)

* feat(directions): let the layer into the layer list (to be printed)

* feat(directionState): store the active route textual directions

* wip

Co-authored-by: Pierre-Étienne Lord <[email protected]>
  • Loading branch information
pelord and Pierre-Étienne Lord authored May 3, 2021
1 parent 5ab57af commit e53721a
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export class DirectionsFormComponent implements OnInit, OnDestroy {
public currentStopIndex: number;
public routesQueries$$: Subscription[] = [];
private search$$: Subscription;
private selectStop;
private translateStop;
private selectedRoute;

private stream$ = new Subject<string>();

Expand All @@ -81,6 +84,7 @@ export class DirectionsFormComponent implements OnInit, OnDestroy {
if (value && this.activeRoute$.getValue() && value.id !== this.activeRoute$.getValue().id) {
this.activeRoute$.next(value);
}
this.activeRouteDescription.emit(this.directionsToText());
}
private _activeRoute: Directions;
public activeRoute$: BehaviorSubject<Directions> = new BehaviorSubject(undefined);
Expand Down Expand Up @@ -128,7 +132,7 @@ export class DirectionsFormComponent implements OnInit, OnDestroy {
*/
@Input() routeStore: FeatureStore;

@Output() submit: EventEmitter<any> = new EventEmitter();
@Output() activeRouteDescription = new EventEmitter<string>();
constructor(
private formBuilder: FormBuilder,
private directionsService: DirectionsService,
Expand Down Expand Up @@ -243,11 +247,14 @@ export class DirectionsFormComponent implements OnInit, OnDestroy {
// STOP STORE
const stopsStore = this.stopsStore;
const stopsLayer = new VectorLayer({
title: 'Directions - stops',
title: this.languageService.translate.instant('igo.geo.directionsForm.stopLayer'),
zIndex: 911,
source: new FeatureDataSource(),
showInLayerList: false,
exportable: false,
showInLayerList: true,
workspace: {
enabled: false,
},
exportable: true,
browsable: false,
style: stopMarker
});
Expand All @@ -257,11 +264,14 @@ export class DirectionsFormComponent implements OnInit, OnDestroy {
// ROUTE AND VERTEX STORE
const routeStore = this.routeStore;
const routeLayer = new VectorLayer({
title: 'Directions - route and vertex',
title: this.languageService.translate.instant('igo.geo.directionsForm.routeLayer'),
zIndex: 910,
source: new FeatureDataSource(),
showInLayerList: false,
exportable: false,
showInLayerList: true,
workspace: {
enabled: false,
},
exportable: true,
browsable: false,
style: stopMarker
});
Expand All @@ -271,7 +281,7 @@ export class DirectionsFormComponent implements OnInit, OnDestroy {

private initOlInteraction() {
let selectedStopFeature;
const selectStop = new olinteraction.Select({
this.selectStop = new olinteraction.Select({
layers: [this.stopsStore.layer.ol],
condition: olcondition.pointerMove,
hitTolerance: 7,
Expand All @@ -280,41 +290,41 @@ export class DirectionsFormComponent implements OnInit, OnDestroy {
}
});

selectStop.on('select', evt => {
this.selectStop.on('select', evt => {
selectedStopFeature = evt.target.getFeatures()[0];
});

const translateStop = new olinteraction.Translate({
this.translateStop = new olinteraction.Translate({
layers: [this.stopsStore.layer.ol],
features: selectedStopFeature
// TODO In Openlayers >= 6.x, filter is now allowed.
});

translateStop.on('translating', evt => {
this.translateStop.on('translating', evt => {
const features = evt.features;
if (features.getLength() === 0) {
return;
}
this.executeTranslation(features, false, 50, true);
});

translateStop.on('translateend', evt => {
this.translateStop.on('translateend', evt => {
const features = evt.features;
if (features.getLength() === 0) {
return;
}
this.executeTranslation(features, true, 0, false);
});

const selectedRoute = new olinteraction.Select({
this.selectedRoute = new olinteraction.Select({
layers: [this.routeStore.layer.ol],
condition: olcondition.click,
hitTolerance: 7,
filter: feature => {
return feature.getId() === 'route';
}
});
selectedRoute.on('select', evt => {
this.selectedRoute.on('select', evt => {
if (this.focusOnStop === false) {
const selectCoordinates = olproj.transform(
(evt as any).mapBrowserEvent.coordinate,
Expand All @@ -326,14 +336,14 @@ export class DirectionsFormComponent implements OnInit, OnDestroy {
this.stops.at(pos).patchValue({ stopCoordinates: selectCoordinates });
this.handleLocationProposals(selectCoordinates, pos);
this.addStopOverlay(selectCoordinates, pos);
selectedRoute.getFeatures().clear();
this.selectedRoute.getFeatures().clear();
}
selectedRoute.getFeatures().clear();
this.selectedRoute.getFeatures().clear();
});

this.map.ol.addInteraction(selectStop);
this.map.ol.addInteraction(translateStop);
this.map.ol.addInteraction(selectedRoute);
this.map.ol.addInteraction(this.selectStop);
this.map.ol.addInteraction(this.translateStop);
this.map.ol.addInteraction(this.selectedRoute);
}

private subscribeToFormChange() {
Expand All @@ -355,8 +365,9 @@ export class DirectionsFormComponent implements OnInit, OnDestroy {
const stopsStore = this.stopsStore;
const routeStore = this.routeStore;

this.map.removeLayer(stopsStore.layer);
this.map.removeLayer(routeStore.layer);
this.map.ol.removeInteraction(this.selectStop);
this.map.ol.removeInteraction(this.translateStop);
this.map.ol.removeInteraction(this.selectedRoute);
stopsStore.deactivateStrategyOfType(FeatureStoreLoadingStrategy);
routeStore.deactivateStrategyOfType(FeatureStoreLoadingStrategy);
}
Expand Down Expand Up @@ -1059,6 +1070,19 @@ export class DirectionsFormComponent implements OnInit, OnDestroy {
}

copyDirectionsToClipboard() {
const directionsBody = this.directionsToText();
const successful = Clipboard.copy(directionsBody);
if (successful) {
const translate = this.languageService.translate;
const title = translate.instant(
'igo.geo.directionsForm.dialog.copyTitle'
);
const msg = translate.instant('igo.geo.directionsForm.dialog.copyMsg');
this.messageService.success(msg, title);
}
}

private directionsToText() {
const indent = '\t';
let activeRouteDirective =
this.languageService.translate.instant(
Expand Down Expand Up @@ -1137,15 +1161,7 @@ export class DirectionsFormComponent implements OnInit, OnDestroy {
const directionsBody =
summary + wayPointList + '\n' + url + '\n\n' + activeRouteDirective;

const successful = Clipboard.copy(directionsBody);
if (successful) {
const translate = this.languageService.translate;
const title = translate.instant(
'igo.geo.directionsForm.dialog.copyTitle'
);
const msg = translate.instant('igo.geo.directionsForm.dialog.copyMsg');
this.messageService.success(msg, title);
}
return directionsBody;
}

private handleTermChanged(term: string) {
Expand Down
1 change: 0 additions & 1 deletion packages/geo/src/lib/draw/shared/draw-icon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class DrawIconService {
}

getPath(): any {
console.log(this);
return this.config.getConfig('drawingTool.icons') || [];
}

Expand Down
2 changes: 2 additions & 0 deletions packages/geo/src/locale/en.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@
"subtitle": "Subtitle"
},
"directionsForm": {
"stopLayer": "Directions - stops",
"routeLayer": "Directions - route",
"start": "Start",
"intermediate": "Intermediate",
"end": "End",
Expand Down
2 changes: 2 additions & 0 deletions packages/geo/src/locale/fr.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@
"subtitle": "Sous-titre"
},
"directionsForm": {
"stopLayer": "Itinéraire - arrêts",
"routeLayer": "Itinéraire - Tracé",
"start": "Début",
"intermediate": "Intermédiaire",
"end": "Fin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
[stopsStore]="stopsStore"
[routeStore]="routeStore"
[map]="map"
[routeFromFeatureDetail]="routeFromFeatureDetail">
[routeFromFeatureDetail]="routeFromFeatureDetail"
(activeRouteDescription)="onActiveRouteDescriptionChange($event)">
</igo-directions-form>
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ export class DirectionsToolComponent {
private mapState: MapState
) {}

onActiveRouteDescriptionChange(directions) {
this.directionState.activeRouteDescription = directions;
}

}
2 changes: 2 additions & 0 deletions packages/integration/src/lib/directions/directions.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export class DirectionState {
map: this.mapState.map
});

public activeRouteDescription: string;

public routeFromFeatureDetail = false;

constructor(private mapState: MapState) {}
Expand Down

0 comments on commit e53721a

Please sign in to comment.