Skip to content

Commit 4bd94c2

Browse files
Merge pull request #16 from KonsumGandalf/sim-11
Display cluster of incidents
2 parents eccd03a + 5f04603 commit 4bd94c2

File tree

53 files changed

+2813
-222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2813
-222
lines changed

eslint.base.config.cjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,17 @@ module.exports = [
8383
sourceTag: 'domain:common',
8484
onlyDependOnLibsWithTags: ['domain:common'],
8585
},
86+
{
87+
sourceTag: 'domain:incidents',
88+
onlyDependOnLibsWithTags: ['domain:common', 'domain:incidents'],
89+
},
8690
{
8791
sourceTag: 'domain:rides',
88-
onlyDependOnLibsWithTags: ['domain:common', 'domain:rides'],
92+
onlyDependOnLibsWithTags: ['domain:common', 'domain:rides', 'domain:incidents'],
8993
},
9094
{
9195
sourceTag: 'domain:streets',
9296
onlyDependOnLibsWithTags: ['domain:common', 'domain:incidents', 'domain:rides', 'domain:streets'],
93-
},
94-
{
95-
sourceTag: 'domain:incidents',
96-
onlyDependOnLibsWithTags: ['domain:common', 'domain:incidents'],
9797
}
9898
],
9999
},

libs/common/ui/components/eslint.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ module.exports = [
2525
style: 'kebab-case',
2626
},
2727
],
28+
'@angular-eslint/component-class-suffix': [
29+
'error',
30+
{
31+
suffixes: ['Page', 'Component'],
32+
}
33+
]
2834
},
2935
},
3036
{

libs/common/ui/components/src/lib/templates/map/component/map.component.scss

Lines changed: 0 additions & 8 deletions
This file was deleted.

libs/common/ui/components/src/lib/templates/map/component/map.component.html renamed to libs/common/ui/components/src/lib/templates/map/component/map.page.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<div
2-
class="o-simra-map"
2+
class="w-full h-screen"
33
leaflet
44
[leafletOptions]="initialOptions"
55
[leafletLayersControl]="layerControl"
6-
[leafletLayers]="combinedLayers$()"
6+
[leafletLayers]="overlayLayers()"
77
(leafletMapReady)="onMapReady($event)"
88
(leafletMapZoom)="onMapChange($event)"
99
(leafletMapMoveEnd)="onMapChange($event)"

libs/common/ui/components/src/lib/templates/map/component/map.page.scss

Whitespace-only changes.

libs/common/ui/components/src/lib/templates/map/component/map.component.spec.ts renamed to libs/common/ui/components/src/lib/templates/map/component/map.page.spec.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { provideRouter } from '@angular/router';
23
import { TranslateModule } from '@ngx-translate/core';
3-
import { Layer, tileLayer } from 'leaflet';
4-
import { MapComponent } from './map.component';
4+
import { MapPage } from './map.page';
55
import { Component } from '@angular/core';
66

77
@Component({
88
selector: 't-map-host',
99
template: `
1010
<t-map-componenent></t-map-componenent>`,
1111
standalone: true,
12-
imports: [MapComponent],
12+
imports: [MapPage],
1313
})
1414
class TestHostComponent {
15-
mockOverlayLayers: Layer[] = [
16-
tileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png'),
17-
];
1815
}
1916

2017
describe('Integration Test MapComponent', () => {
@@ -27,6 +24,7 @@ describe('Integration Test MapComponent', () => {
2724

2825
TranslateModule.forRoot()
2926
],
27+
providers: [provideRouter([])]
3028
}).compileComponents();
3129

3230
fixture = TestBed.createComponent(TestHostComponent);
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
import {
22
ChangeDetectionStrategy,
33
Component,
4-
computed,
5-
input,
6-
model,
4+
computed, effect, EventEmitter, inject,
5+
input, Output,
76
Signal,
87
ViewEncapsulation,
98
} from '@angular/core';
109
import { CommonModule } from '@angular/common';
10+
import { toSignal } from '@angular/core/rxjs-interop';
11+
import { ActivatedRoute, Router } from '@angular/router';
1112
import { LeafletControlLayersConfig, LeafletModule } from '@bluehalo/ngx-leaflet';
1213
import {
1314
Control,
14-
icon,
1515
latLng,
1616
Layer,
1717
LeafletEvent,
1818
Map,
1919
MapOptions,
20-
Marker,
21-
tileLayer,
2220
} from 'leaflet';
2321
import { GeoSearchControl, OpenStreetMapProvider } from 'leaflet-geosearch';
2422
import { MapPositionInterface } from '@simra/common-models';
2523
import { PopoverModule } from 'primeng/popover';
24+
import { BERLIN_POSITION, DEFAULT_LAYER_CONFIG } from '../../models/const';
25+
import { EBaseLayerTypes } from '../../models/enums/base-layer-types';
26+
import { BASE_MAP_LAYER } from '../../models/maps/base-map-layer';
2627

2728
/**
2829
* This component allows to interact with the leaflet map smoothly
@@ -31,80 +32,64 @@ import { PopoverModule } from 'primeng/popover';
3132
selector: 't-map-component',
3233
standalone: true,
3334
imports: [CommonModule, LeafletModule, PopoverModule],
34-
templateUrl: './map.component.html',
35-
styleUrl: './map.component.scss',
35+
templateUrl: './map.page.html',
36+
styleUrl: './map.page.scss',
3637
host: {
3738
class: 't-map-component',
3839
},
3940
encapsulation: ViewEncapsulation.None,
4041
changeDetection: ChangeDetectionStrategy.OnPush,
4142
})
42-
export class MapComponent {
43-
public readonly leafletPosition = model<MapPositionInterface>({
44-
lat: 52.522,
45-
lng: 13.413,
46-
zoom: 14
47-
});
43+
export class MapPage {
44+
private readonly route = inject(ActivatedRoute);
45+
private readonly router = inject(Router);
46+
4847
/**
4948
* Represents the layers which should be mapped onto the open street map often those are GeoJSONs as Overlays
5049
*/
5150
public readonly overlayLayers = input.required<Layer[]>();
51+
@Output()
52+
public positionChange = new EventEmitter<MapPositionInterface>();
53+
private map?: Map;
5254

53-
protected readonly initialOptions: MapOptions = {
54-
zoom: this.leafletPosition().zoom,
55-
center: latLng(this.leafletPosition().lat, this.leafletPosition().lng),
56-
preferCanvas: true,
57-
};
55+
constructor() {
56+
effect(() => {
57+
const position = this.leafletPosition();
5858

59-
/**
60-
* The base layer on which other objects are projected to
61-
*/
62-
private readonly _baseLayer: Layer = tileLayer(
63-
'https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
64-
{
65-
maxZoom: 18
66-
},
67-
);
59+
if (this.map) {
60+
this.map.setView(latLng(position.lat, position.lng), position.zoom);
61+
}
6862

69-
/**
70-
* The overall layer containing the base layer with overlays
71-
*/
72-
protected readonly combinedLayers$: Signal<Layer[]> = computed(() => {
73-
return [this._baseLayer, ...(this.overlayLayers() || [])];
63+
this.positionChange.emit(position);
64+
});
65+
66+
}
67+
68+
private queryParams = toSignal(this.route.queryParams);
69+
public readonly leafletPosition: Signal<MapPositionInterface> = computed(() => {
70+
const {
71+
lat = BERLIN_POSITION.lat,
72+
lng = BERLIN_POSITION.lng,
73+
zoom = BERLIN_POSITION.zoom
74+
} = this.queryParams() as MapPositionInterface ?? {};
75+
76+
return { ...BERLIN_POSITION, lat, lng, zoom };
7477
});
7578

7679
/**
77-
* The appearance options the user can choose from when using the map
80+
* Map options which are applied at the start
7881
*/
79-
protected readonly layerControl: LeafletControlLayersConfig = {
80-
baseLayers: {
81-
'Open Cycle Map': tileLayer('https://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png', {
82-
maxZoom: 18,
83-
attribution: '...',
84-
}),
85-
'Osm Liberty': tileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
86-
maxZoom: 30,
87-
minZoom: 12,
88-
}),
89-
google: tileLayer('https://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}', {
90-
maxZoom: 20,
91-
subdomains: ['mt0', 'mt1', 'mt2', 'mt3'],
92-
}),
93-
},
94-
overlays: {},
82+
public readonly initialOptions: MapOptions = {
83+
zoom: this.leafletPosition().zoom,
84+
center: latLng(this.leafletPosition().lat, this.leafletPosition().lng),
85+
layers: [BASE_MAP_LAYER[EBaseLayerTypes.OSM_HOT]],
86+
preferCanvas: true,
9587
};
9688

97-
constructor() {
98-
Marker.prototype.options.icon = icon({
99-
iconUrl: 'assets/leaflet/marker-icon.png',
100-
iconRetinaUrl: 'assets/leaflet/marker-icon-2x.png',
101-
shadowUrl: 'assets/leaflet/marker-shadow.png',
102-
iconSize: [25, 41],
103-
iconAnchor: [12, 41],
104-
popupAnchor: [1, -34],
105-
shadowSize: [41, 41],
106-
});
107-
}
89+
/**
90+
* The appearance options the user can choose from when using the map
91+
*/
92+
protected readonly layerControl: LeafletControlLayersConfig = DEFAULT_LAYER_CONFIG;
10893

10994
onMapReady(map: Map): void {
11095
const provider = new OpenStreetMapProvider();
@@ -118,6 +103,7 @@ export class MapComponent {
118103
});
119104

120105
map.addControl(searchControl);
106+
this.map = map;
121107
}
122108

123109
/**
@@ -126,9 +112,11 @@ export class MapComponent {
126112
* @param event - the leaflet event emitted
127113
*/
128114
onMapChange(event: LeafletEvent): void {
129-
this.leafletPosition.set({
130-
zoom: event.sourceTarget.getZoom(),
131-
...event.sourceTarget.getCenter(),
132-
});
115+
const center = event.sourceTarget.getCenter();
116+
const zoom = event.sourceTarget.getZoom();
117+
this.router.navigate([], {
118+
queryParams: { lat: center.lat, lng: center.lng, zoom },
119+
queryParamsHandling: 'merge',
120+
})
133121
}
134122
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './map.component';
1+
export * from './map.page';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class="h-screen w-full"
2+
leaflet
3+
[leafletLayersControl]="_layerControl"
4+
[leafletOptions]="_mapOptions"
5+
[leafletMarkerCluster]="_markersWithLayer$()"
6+
(leafletMapMoveEnd)="onMapChange($event)"
7+
(leafletMapZoom)="onMapChange($event)">
8+
</div>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.t-marker-cluster-map-page {
2+
.o-simra-marker-cluster-map {
3+
height: 1000px;
4+
width: 100%;
5+
margin: 0;
6+
padding: 0;
7+
}
8+
}

0 commit comments

Comments
 (0)