Skip to content

Commit

Permalink
#379 planner signals
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarc committed Mar 28, 2024
1 parent 34397f6 commit 88f876d
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class LocationMapService extends OpenlayersMapService {
geoJson: string
): void {
const parameters = signal<MainMapStyleParameters>(
new MainMapStyleParameters('analysis', true, surveyDateValues, null, null, null)
new MainMapStyleParameters('analysis', true, surveyDateValues, null, null)
);
const mainMapStyle = new MainMapStyle(parameters);
const networkLayers = [
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/app/ol/style/main-map-route-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ export class MainMapRouteStyle {
resolution: number
): Style {
const color = this.routeColor(parameters, feature);
const highligthed =
parameters.highlightedRouteId && feature.get('id').startsWith(parameters.highlightedRouteId);
const proposed = feature.get('state') === 'proposed';
return this.routeStyleBuilder.style(color, resolution, highligthed, proposed);
return this.routeStyleBuilder.style(color, resolution, proposed);
}

private initRouteSelectedStyle(): Style {
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/app/ol/style/main-map-style-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export class MainMapStyleParameters {
public showProposed: boolean,
public surveyDateValues: SurveyDateValues,
public selectedRouteId: string,
public selectedNodeId: string,
public highlightedRouteId: string
public selectedNodeId: string
) {}
}
2 changes: 1 addition & 1 deletion frontend/src/app/ol/style/network-nodes-map-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ export class NetworkNodesMapStyle {
const routeId = +featureId.substring(0, featureId.indexOf('-'));
const routeColor = this.networkRouteIds.includes(routeId) ? green : gray;
const proposed = feature.get('state') === 'proposed';
return this.routeStyle.style(routeColor, resolution, false, proposed);
return this.routeStyle.style(routeColor, resolution, proposed);
}
}
2 changes: 1 addition & 1 deletion frontend/src/app/ol/style/node-map-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class NodeMapStyle {
return this.smallNodeStyle;
}

return this.routeStyle.style(green, resolution, false, proposed);
return this.routeStyle.style(green, resolution, proposed);
}
return null;
};
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/app/ol/style/route-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import { green } from './main-style-colors';
export class RouteStyle {
private defaultRouteStyle = this.initRouteStyle();

style(color: Color, resolution: number, highlighted: boolean, proposed: boolean): Style {
style(color: Color, resolution: number, proposed: boolean): Style {
let width: number;
if (resolution > /* zoomLevel 9 */ 305.75) {
width = 1;
} else if (resolution > /* zoomLevel 12 */ 38.219) {
width = 2;
} else {
if (highlighted) {
width = 8;
} else {
width = 4;
}
width = 4;
}

const stroke = this.defaultRouteStyle.getStroke();
Expand Down
20 changes: 0 additions & 20 deletions frontend/src/app/planner/pages/planner/map.service.ts

This file was deleted.

11 changes: 3 additions & 8 deletions frontend/src/app/planner/pages/planner/planner-map.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { effect } from '@angular/core';
import { computed } from '@angular/core';
import { inject } from '@angular/core';
import { Injectable } from '@angular/core';
Expand All @@ -21,18 +20,15 @@ import Overlay from 'ol/Overlay';
import View from 'ol/View';
import { SharedStateService } from '../../../shared/core/shared/shared-state.service';
import { PlannerInteraction } from '../../domain/interaction/planner-interaction';
import { PlannerMapLayerService } from './planner-map-layer.service';
import { PlannerState } from './planner-state';
import { PlannerStateService } from './planner-state.service';
import { PlannerService } from './planner.service';
import { MapService } from './map.service';
import { PlannerState } from './planner-state';
import { PlannerMapLayerService } from './planner-map-layer.service';

@Injectable({
providedIn: 'root',
})
export class PlannerMapService extends OpenlayersMapService {
private readonly mapService = inject(MapService);

private readonly plannerService = inject(PlannerService);
private readonly poiService = inject(PoiService);
private readonly mapZoomService = inject(MapZoomService);
Expand All @@ -58,8 +54,7 @@ export class PlannerMapService extends OpenlayersMapService {
showProposed,
surveyDateValues,
selectedRouteId,
selectedNodeId,
this.mapService.highlightedRouteId()
selectedNodeId
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ import { RouterService } from '../../../shared/services/router.service';
import { PlannerCommandAddPlan } from '../../domain/commands/planner-command-add-plan';
import { PlanBuilder } from '../../domain/plan/plan-builder';
import { PlanUtil } from '../../domain/plan/plan-util';
import { PlannerMapService } from './planner-map.service';
import { PlannerStateService } from './planner-state.service';
import { PlannerService } from './planner.service';
import { MapService } from './map.service';
import { PlannerMapService } from './planner-map.service';

@Injectable()
export class PlannerPageService {
private readonly plannerStateService = inject(PlannerStateService);
private readonly plannerService = inject(PlannerService);
private readonly plannerMapService = inject(PlannerMapService);
private readonly pageService = inject(PageService);
private readonly mapService = inject(MapService);
private readonly dialog = inject(MatDialog);
private readonly apiService = inject(ApiService);
private readonly sharedStateService = inject(SharedStateService);
Expand Down Expand Up @@ -130,7 +128,7 @@ export class PlannerPageService {
geolocation(coordinate: Coordinate): void {
this.plannerMapService.map.getView().setCenter(coordinate);
let zoomLevel = 15;
if ('cycling' === this.mapService.networkType()) {
if ('cycling' === this.plannerStateService.networkType()) {
zoomLevel = 13;
}
this.plannerMapService.map.getView().setZoom(zoomLevel);
Expand Down
17 changes: 0 additions & 17 deletions frontend/src/app/planner/pages/planner/planner.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { inject } from '@angular/core';
import { Injectable } from '@angular/core';
import { PlanRoute } from '@api/common/planner';
import { PreferencesService } from '@app/core';
import { ApiService } from '@app/services';
import { List } from 'immutable';
import Map from 'ol/Map';
import { PlannerContext } from '../../domain/context/planner-context';
import { PlannerCursorImpl } from '../../domain/context/planner-cursor-impl';
Expand All @@ -16,8 +14,6 @@ import { PlannerPopupService } from '../../domain/context/planner-popup-service'
import { PlannerRouteLayerImpl } from '../../domain/context/planner-route-layer-impl';
import { PlannerEngine } from '../../domain/interaction/planner-engine';
import { PlannerEngineImpl } from '../../domain/interaction/planner-engine-impl';
import { PlanUtil } from '../../domain/plan/plan-util';
import { PlannerTranslations } from '../../util/planner-translations';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -55,17 +51,4 @@ export class PlannerService {
this.highlightLayer.addToMap(map);
this.plannerPopupService.addToMap(map);
}

hasColour(planRoute: PlanRoute): boolean {
return planRoute.segments.filter((segment) => !!segment.colour).length > 0;
}

colours(planRoute: PlanRoute): string {
const colourValues = planRoute.segments
.filter((segment) => !!segment.colour)
.map((segment) => segment.colour);
const distinctColours = PlanUtil.distinctColours(List(colourValues));
const colourGroups = distinctColours.map((colour) => PlannerTranslations.colour(colour));
return colourGroups.join(' > ');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ChangeDetectionStrategy } from '@angular/core';
import { inject } from '@angular/core';
import { Component } from '@angular/core';
import { PlannerPopupService } from '../../../domain/context/planner-popup-service';
import { MapPopupRouteComponent } from './map-popup-route.component';
import { PlannerPopupRouteComponent } from './planner-popup-route.component';
import { PlannerPopupNodeComponent } from './planner-popup-node.component';
import { PlannerPopupPoiComponent } from './planner-popup-poi.component';

Expand All @@ -24,7 +24,12 @@ import { PlannerPopupPoiComponent } from './planner-popup-poi.component';
}
`,
standalone: true,
imports: [MapPopupRouteComponent, NgClass, PlannerPopupNodeComponent, PlannerPopupPoiComponent],
imports: [
PlannerPopupRouteComponent,
NgClass,
PlannerPopupNodeComponent,
PlannerPopupPoiComponent,
],
})
export class PlannerPopupContentsComponent {
protected readonly service = inject(PlannerPopupService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { MapZoomService } from '@app/ol/services';
import { ApiService } from '@app/services';
import { Coordinate } from 'ol/coordinate';
import { PlannerPopupService } from '../../../domain/context/planner-popup-service';
import { PlannerStateService } from '../planner-state.service';
import { PlannerService } from '../planner.service';
import { MapService } from '../map.service';

@Component({
selector: 'kpn-planner-popup-node',
Expand Down Expand Up @@ -89,7 +89,7 @@ import { MapService } from '../map.service';
export class PlannerPopupNodeComponent {
private readonly service = inject(PlannerPopupService);
private readonly apiService = inject(ApiService);
private readonly mapService = inject(MapService);
private readonly plannerStateService = inject(PlannerStateService);
private readonly mapZoomService = inject(MapZoomService);
private readonly plannerService = inject(PlannerService);

Expand All @@ -99,7 +99,7 @@ export class PlannerPopupNodeComponent {
effect(() => {
const nodeClick = this.service.nodeClick();
if (nodeClick !== null) {
const networkType = this.mapService.networkType();
const networkType = this.plannerStateService.networkType();
const nodeId = +nodeClick.node.node.nodeId;
this.apiService.mapNodeDetail(networkType, nodeId).subscribe((response) => {
this.response.set(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { ActionButtonRelationComponent } from '../../../../analysis/components/a
import { ActionButtonWayComponent } from '../../../../analysis/components/action/action-button-way.component';
import { PlannerPopupService } from '../../../domain/context/planner-popup-service';
import { PlannerService } from '../planner.service';
import { MapService } from '../map.service';

@Component({
selector: 'kpn-planner-popup-poi',
Expand Down Expand Up @@ -74,7 +73,6 @@ export class PlannerPopupPoiComponent {
private readonly service = inject(PlannerPopupService);
private readonly apiService = inject(ApiService);
private readonly plannerService = inject(PlannerService);
private readonly mapService = inject(MapService);
protected readonly poiClick = this.service.poiClick;

protected response = signal<ApiResponse<PoiPage>>(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { LinkRouteComponent } from '@app/components/shared/link';
import { ApiService } from '@app/services';
import { Coordinate } from 'ol/coordinate';
import { PlannerPopupService } from '../../../domain/context/planner-popup-service';
import { PlannerStateService } from '../planner-state.service';
import { PlannerService } from '../planner.service';
import { MapService } from '../map.service';

@Component({
selector: 'kpn-planner-popup-route',
Expand Down Expand Up @@ -65,14 +65,14 @@ import { MapService } from '../map.service';
standalone: true,
imports: [RouterLink, LinkRouteComponent],
})
export class MapPopupRouteComponent {
export class PlannerPopupRouteComponent {
private readonly service = inject(PlannerPopupService);
private readonly plannerStateService = inject(PlannerStateService);
private readonly apiService = inject(ApiService);
private readonly mapService = inject(MapService);
private readonly plannerService = inject(PlannerService);

protected response = signal<ApiResponse<MapRouteDetail>>(null);
protected networkType = this.mapService.networkType;
protected networkType = this.plannerStateService.networkType;

constructor() {
effect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { inject } from '@angular/core';
import { ChangeDetectionStrategy } from '@angular/core';
import { Component } from '@angular/core';
import { input } from '@angular/core';
import { PlanRoute } from '@api/common/planner';
import { Plan } from '../../../domain/plan/plan';
import { PlannerService } from '../planner.service';
import { PlanRouteColourUtil } from '../../../util/plan-route-colour-util';

@Component({
selector: 'kpn-plan-compact',
Expand Down Expand Up @@ -49,13 +48,11 @@ import { PlannerService } from '../planner.service';
export class PlanCompactComponent {
plan = input.required<Plan>();

private readonly plannerService = inject(PlannerService);

hasColour(planRoute: PlanRoute): boolean {
return this.plannerService.hasColour(planRoute);
return PlanRouteColourUtil.hasColour(planRoute);
}

colours(planRoute: PlanRoute): string {
return this.plannerService.colours(planRoute);
return PlanRouteColourUtil.colours(planRoute);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { inject } from '@angular/core';
import { ChangeDetectionStrategy } from '@angular/core';
import { Component } from '@angular/core';
import { input } from '@angular/core';
import { PlanRoute } from '@api/common/planner';
import { Plan } from '../../../domain/plan/plan';
import { PlannerService } from '../planner.service';
import { PlanRouteColourUtil } from '../../../util/plan-route-colour-util';

@Component({
selector: 'kpn-plan-detailed',
Expand Down Expand Up @@ -111,13 +110,11 @@ import { PlannerService } from '../planner.service';
export class PlanDetailedComponent {
plan = input.required<Plan>();

private readonly plannerService = inject(PlannerService);

hasColour(planRoute: PlanRoute): boolean {
return this.plannerService.hasColour(planRoute);
return PlanRouteColourUtil.hasColour(planRoute);
}

colours(planRoute: PlanRoute): string {
return this.plannerService.colours(planRoute);
return PlanRouteColourUtil.colours(planRoute);
}
}
19 changes: 19 additions & 0 deletions frontend/src/app/planner/util/plan-route-colour-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { PlanRoute } from '@api/common/planner';
import { List } from 'immutable';
import { PlanUtil } from '../domain/plan/plan-util';
import { PlannerTranslations } from './planner-translations';

export class PlanRouteColourUtil {
static hasColour(planRoute: PlanRoute): boolean {
return planRoute.segments.filter((segment) => !!segment.colour).length > 0;
}

static colours(planRoute: PlanRoute): string {
const colourValues = planRoute.segments
.filter((segment) => !!segment.colour)
.map((segment) => segment.colour);
const distinctColours = PlanUtil.distinctColours(List(colourValues));
const colourGroups = distinctColours.map((colour) => PlannerTranslations.colour(colour));
return colourGroups.join(' > ');
}
}

0 comments on commit 88f876d

Please sign in to comment.