add mp with icons and update after review
This commit is contained in:
@@ -3,11 +3,13 @@ import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
ElementRef,
|
||||
HostListener,
|
||||
NgZone,
|
||||
OnDestroy,
|
||||
ViewChild,
|
||||
effect,
|
||||
inject,
|
||||
input,
|
||||
signal,
|
||||
} from '@angular/core';
|
||||
import { Geolocation, type Position } from '@capacitor/geolocation';
|
||||
@@ -48,6 +50,7 @@ interface DgMap {
|
||||
): this;
|
||||
getZoom(): number;
|
||||
latLngToContainerPoint(latLng: [number, number]): DgPoint;
|
||||
invalidateSize?(): void;
|
||||
remove(): void;
|
||||
}
|
||||
|
||||
@@ -124,6 +127,9 @@ function loadRasterApi(): Promise<DgApi> {
|
||||
templateUrl: './city-map.html',
|
||||
styleUrl: './city-map.scss',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
host: {
|
||||
'[class.is-fullscreen]': 'fullscreen()',
|
||||
},
|
||||
})
|
||||
export class CityMap implements AfterViewInit, OnDestroy {
|
||||
@ViewChild('map', { static: true })
|
||||
@@ -141,6 +147,9 @@ export class CityMap implements AfterViewInit, OnDestroy {
|
||||
private zoomOnNextPan = true;
|
||||
private destroyed = false;
|
||||
private programmaticMove = false;
|
||||
private resizeObserver: ResizeObserver | null = null;
|
||||
private readonly hostRef = inject(ElementRef<HTMLElement>);
|
||||
private readonly clippedAncestors: HTMLElement[] = [];
|
||||
private readonly markerElements = new Map<string, HTMLElement>();
|
||||
private readonly markers = new Map<string, DgMarker>();
|
||||
private readonly collectedIds = this.store.selectSignal(selectCollectedIdSet);
|
||||
@@ -159,9 +168,12 @@ export class CityMap implements AfterViewInit, OnDestroy {
|
||||
this.programmaticMove = false;
|
||||
};
|
||||
|
||||
readonly embedded = input(false);
|
||||
|
||||
protected readonly city = this.catalog.city;
|
||||
protected readonly selected = signal<Landmark | null>(null);
|
||||
protected readonly following = signal(false);
|
||||
protected readonly fullscreen = signal(false);
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
@@ -171,9 +183,18 @@ export class CityMap implements AfterViewInit, OnDestroy {
|
||||
this.setMarkerIcon(element, ids.has(id));
|
||||
}
|
||||
});
|
||||
|
||||
effect(() => {
|
||||
const active = this.fullscreen();
|
||||
this.setAncestorOverflow(active);
|
||||
requestAnimationFrame(() => this.resizeMap());
|
||||
});
|
||||
}
|
||||
|
||||
async ngAfterViewInit(): Promise<void> {
|
||||
this.resizeObserver = new ResizeObserver(() => this.resizeMap());
|
||||
this.resizeObserver.observe(this.mapElement.nativeElement);
|
||||
|
||||
const api = await loadRasterApi();
|
||||
this.raster = api;
|
||||
|
||||
@@ -214,11 +235,15 @@ export class CityMap implements AfterViewInit, OnDestroy {
|
||||
for (const landmark of this.city.objects) {
|
||||
this.markers.set(landmark.id, this.createMarker(raster, map, landmark));
|
||||
}
|
||||
|
||||
requestAnimationFrame(() => this.resizeMap());
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroyed = true;
|
||||
this.setAncestorOverflow(false);
|
||||
this.resizeObserver?.disconnect();
|
||||
void this.stopWatching();
|
||||
this.map?.off('dragstart', this.stopFollowing);
|
||||
this.map?.off('zoomstart', this.onZoomStart);
|
||||
@@ -227,6 +252,19 @@ export class CityMap implements AfterViewInit, OnDestroy {
|
||||
this.map = null;
|
||||
}
|
||||
|
||||
protected toggleFullscreen(): void {
|
||||
this.fullscreen.update((active) => !active);
|
||||
}
|
||||
|
||||
protected exitFullscreen(): void {
|
||||
this.fullscreen.set(false);
|
||||
}
|
||||
|
||||
@HostListener('document:keydown.escape')
|
||||
protected onEscape(): void {
|
||||
this.exitFullscreen();
|
||||
}
|
||||
|
||||
protected focusCity(): void {
|
||||
this.following.set(false);
|
||||
this.clearSelection();
|
||||
@@ -474,4 +512,30 @@ export class CityMap implements AfterViewInit, OnDestroy {
|
||||
private toLatLng(coordinates: [number, number]): [number, number] {
|
||||
return [coordinates[1], coordinates[0]];
|
||||
}
|
||||
|
||||
private resizeMap(): void {
|
||||
this.map?.invalidateSize?.();
|
||||
}
|
||||
|
||||
private setAncestorOverflow(active: boolean): void {
|
||||
for (const element of this.clippedAncestors) {
|
||||
element.style.overflow = '';
|
||||
}
|
||||
this.clippedAncestors.length = 0;
|
||||
document.body.style.overflow = '';
|
||||
|
||||
if (!active) {
|
||||
return;
|
||||
}
|
||||
|
||||
let node = this.hostRef.nativeElement.parentElement;
|
||||
|
||||
while (node && node !== document.body) {
|
||||
this.clippedAncestors.push(node);
|
||||
node.style.overflow = 'visible';
|
||||
node = node.parentElement;
|
||||
}
|
||||
|
||||
document.body.style.overflow = 'hidden';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user