update for 2gis

This commit is contained in:
Artem
2026-09-30 10:38:43 +03:00
parent 7e8cb26ddd
commit deceebd899
13 changed files with 296 additions and 253 deletions
+9 -24
View File
@@ -3,7 +3,7 @@
"version": 1,
"newProjectRoot": "projects",
"projects": {
"maps": {
"gorodar-front": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
@@ -18,15 +18,11 @@
"builder": "@angular/build:application",
"options": {
"browser": "src/main.ts",
"polyfills": [
"zone.js"
],
"polyfills": ["zone.js"],
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"stylePreprocessorOptions": {
"includePaths": [
"src/assets/styles"
]
"includePaths": ["src/assets/styles"]
},
"assets": [
{
@@ -34,10 +30,7 @@
"input": "public"
}
],
"styles": [
"@angular/material/prebuilt-themes/magenta-violet.css",
"src/styles.scss"
]
"styles": ["@angular/material/prebuilt-themes/magenta-violet.css", "src/styles.scss"]
},
"configurations": {
"production": {
@@ -68,10 +61,10 @@
"builder": "@angular/build:dev-server",
"configurations": {
"production": {
"buildTarget": "maps:build:production"
"buildTarget": "gorodar-front:build:production"
},
"development": {
"buildTarget": "maps:build:development"
"buildTarget": "gorodar-front:build:development"
}
},
"defaultConfiguration": "development"
@@ -82,16 +75,11 @@
"test": {
"builder": "@angular/build:karma",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"polyfills": ["zone.js", "zone.js/testing"],
"tsConfig": "tsconfig.spec.json",
"inlineStyleLanguage": "scss",
"stylePreprocessorOptions": {
"includePaths": [
"src/assets/styles"
]
"includePaths": ["src/assets/styles"]
},
"assets": [
{
@@ -99,10 +87,7 @@
"input": "public"
}
],
"styles": [
"@angular/material/prebuilt-themes/magenta-violet.css",
"src/styles.scss"
]
"styles": ["@angular/material/prebuilt-themes/magenta-violet.css", "src/styles.scss"]
}
}
}
+21 -26
View File
@@ -1,13 +1,14 @@
{
"name": "maps",
"name": "gorodar-front",
"version": "0.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "maps",
"name": "gorodar-front",
"version": "0.0.0",
"dependencies": {
"@2gis/mapgl": "^1.78.1",
"@angular/animations": "^20.3.32",
"@angular/cdk": "^20.2.14",
"@angular/common": "^20.3.0",
@@ -35,7 +36,6 @@
"@angular/compiler-cli": "^20.3.0",
"@capacitor/cli": "^6.2.2",
"@types/jasmine": "~5.1.0",
"@yandex/ymaps3-types": "^1.0.21108841",
"jasmine-core": "~5.9.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
@@ -45,6 +45,18 @@
"typescript": "~5.9.2"
}
},
"node_modules/@2gis/mapgl": {
"version": "1.78.1",
"resolved": "https://registry.npmjs.org/@2gis/mapgl/-/mapgl-1.78.1.tgz",
"integrity": "sha512-SkbrqwBMPTLV4hihV+BgAtftIfyMeSru6yqlVF0IJEE6jaGQ8LFq0NJb1TTaXt3I1t3q8sjvU7X/hhHpxo5JXQ==",
"license": "BSD-2-Clause",
"dependencies": {
"@types/geojson": "^7946.0.7"
},
"engines": {
"node": ">=16.0.0"
}
},
"node_modules/@algolia/abtesting": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@algolia/abtesting/-/abtesting-1.1.0.tgz",
@@ -4536,6 +4548,12 @@
"@types/node": "*"
}
},
"node_modules/@types/geojson": {
"version": "7946.0.16",
"resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.16.tgz",
"integrity": "sha512-6C8nqWur3j98U6+lXDfTUWIfgvZU+EumvpHKcYjujKH7woYyLj2sUmff0tRhrqM7BohUw7Pz3ZB1jj2gW9Fvmg==",
"license": "MIT"
},
"node_modules/@types/jasmine": {
"version": "5.1.15",
"resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-5.1.15.tgz",
@@ -4593,29 +4611,6 @@
"node": ">=14.6"
}
},
"node_modules/@yandex/ymaps3-types": {
"version": "1.0.21108841",
"resolved": "https://registry.npmjs.org/@yandex/ymaps3-types/-/ymaps3-types-1.0.21108841.tgz",
"integrity": "sha512-ZUUjQ2sgVQZE+Alt7d1u2oVvHhDNlq1YrVqlqadiqvotkOWT5kIKWoWv+qsMoCsriObtYh1jRtAyXzOqAsFyRg==",
"dev": true,
"license": "Apache-2.0",
"peerDependencies": {
"@types/react": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
"@types/react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
"@vue/runtime-core": "3"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
},
"@vue/runtime-core": {
"optional": true
}
}
},
"node_modules/@yarnpkg/lockfile": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz",
+2 -2
View File
@@ -1,5 +1,5 @@
{
"name": "maps",
"name": "gorodar-front",
"version": "0.0.0",
"scripts": {
"ng": "ng",
@@ -22,6 +22,7 @@
},
"private": true,
"dependencies": {
"@2gis/mapgl": "^1.78.1",
"@angular/animations": "^20.3.32",
"@angular/cdk": "^20.2.14",
"@angular/common": "^20.3.0",
@@ -49,7 +50,6 @@
"@angular/compiler-cli": "^20.3.0",
"@capacitor/cli": "^6.2.2",
"@types/jasmine": "~5.1.0",
"@yandex/ymaps3-types": "^1.0.21108841",
"jasmine-core": "~5.9.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
-1
View File
@@ -10,7 +10,6 @@
>
<app-icon name="pin" [size]="18" />
<span>{{ city.name }}</span>
<app-icon name="chevron-down" [size]="18" />
</button>
<button
+1 -1
View File
@@ -43,7 +43,7 @@
.city-map__chip {
gap: 8px;
padding: 0 12px 0 16px;
padding: 0 16px;
font: inherit;
font-size: 16px;
font-weight: 600;
+127 -84
View File
@@ -10,6 +10,7 @@ import {
inject,
signal,
} from '@angular/core';
import { load } from '@2gis/mapgl';
import { Geolocation, type Position } from '@capacitor/geolocation';
import { Store } from '@ngrx/store';
@@ -19,11 +20,16 @@ import type { Landmark } from '../../data/nizhny-novgorod';
import { Icon } from '../../shared/icon/icon';
import { selectCollectedIdSet } from '../../state';
declare global {
interface Window {
ymaps3: any;
}
}
const MAPGL_KEY = 'bf0a466f-43a6-48c7-b274-7fea5952957b';
const MAP_STYLE_NIGHT = 'e05ac437-fcc2-4845-ad74-b1de9ce07555';
const CITY_ZOOM = 13;
const USER_ZOOM = 16;
const LANDMARK_SIZE = 40;
const USER_SIZE = 32;
type MapglApi = Awaited<ReturnType<typeof load>>;
type MapglMap = InstanceType<MapglApi['Map']>;
type MapglHtmlMarker = InstanceType<MapglApi['HtmlMarker']>;
@Component({
selector: 'app-city-map',
@@ -39,14 +45,16 @@ export class CityMap implements AfterViewInit, OnDestroy {
private readonly catalog = inject(CityCatalogService);
private readonly store = inject(Store);
private readonly zone = inject(NgZone);
private map: any;
private userMarker: any;
private mapgl: MapglApi | null = null;
private map: MapglMap | null = null;
private userMarker: MapglHtmlMarker | null = null;
private userMarkerElement: HTMLElement | null = null;
private watchId: string | null = null;
private lastPosition: Position | null = null;
private zoomOnNextPan = true;
private currentZoom = 13;
private destroyed = false;
private readonly markerElements = new Map<string, HTMLElement>();
private readonly markers = new Map<string, MapglHtmlMarker>();
private readonly collectedIds = this.store.selectSignal(selectCollectedIdSet);
protected readonly city = this.catalog.city;
@@ -64,71 +72,64 @@ export class CityMap implements AfterViewInit, OnDestroy {
}
async ngAfterViewInit(): Promise<void> {
await window.ymaps3.ready;
const mapgl = await load();
const {
YMap,
YMapDefaultSchemeLayer,
YMapDefaultFeaturesLayer,
YMapMarker,
YMapListener,
} = window.ymaps3;
const center = this.city.center;
this.map = new YMap(this.mapElement.nativeElement, {
location: {
center,
zoom: 13,
},
theme: 'dark',
distribution: false,
});
this.map.addChild(new YMapDefaultSchemeLayer({ theme: 'dark' }));
this.map.addChild(new YMapDefaultFeaturesLayer());
if (YMapListener) {
this.map.addChild(
new YMapListener({
onActionStart: (event: { type?: string }) => {
if (event?.type === 'drag' || event?.type === 'scrollZoom' || event?.type === 'pinchZoom') {
this.zone.run(() => this.following.set(false));
}
},
onUpdate: ({ location }: { location?: { zoom?: number } }) => {
if (location?.zoom == null) {
if (this.destroyed) {
return;
}
this.currentZoom = location.zoom;
this.syncRadiusSize();
},
}),
);
this.mapgl = mapgl;
this.zone.runOutsideAngular(() => {
if (this.destroyed) {
return;
}
for (const landmark of this.city.objects) {
this.map.addChild(this.createMarker(YMapMarker, landmark));
const map = new mapgl.Map(this.mapElement.nativeElement, {
center: this.city.center,
zoom: CITY_ZOOM,
key: MAPGL_KEY,
lang: 'ru',
style: MAP_STYLE_NIGHT,
defaultBackgroundColor: '#12110f',
zoomControl: false,
disablePitchByUserInteraction: true,
disableRotationByUserInteraction: true,
enableTrackResize: true,
});
if (this.destroyed) {
map.destroy();
return;
}
this.map = map;
map.on('movestart', (event) => {
if (!event.isUser) {
return;
}
this.zone.run(() => this.following.set(false));
});
map.on('move', () => this.syncRadiusSize());
for (const landmark of this.city.objects) {
this.markers.set(landmark.id, this.createMarker(mapgl, map, landmark));
}
});
}
ngOnDestroy(): void {
this.destroyed = true;
void this.stopWatching();
this.map?.destroy();
this.map = null;
}
protected focusCity(): void {
if (!this.map) {
return;
}
this.following.set(false);
this.clearSelection();
this.map.setLocation({
center: this.city.center,
zoom: 13,
duration: 500,
});
this.moveMap(this.city.center, CITY_ZOOM, 500);
}
protected async locate(): Promise<void> {
@@ -173,21 +174,35 @@ export class CityMap implements AfterViewInit, OnDestroy {
}
private updateUserPosition(position: Position, pan: boolean): void {
const map = this.map;
if (!map) {
return;
}
this.lastPosition = position;
const coordinates: [number, number] = [position.coords.longitude, position.coords.latitude];
const heading = position.coords.heading;
if (!this.userMarker) {
const { YMapMarker } = window.ymaps3;
if (!this.userMarker && this.mapgl) {
const markerElement = document.createElement('div');
markerElement.className = 'city-map__user';
markerElement.innerHTML =
'<span class="city-map__user-body"><span class="city-map__user-heading"></span><span class="city-map__user-dot"></span></span>';
this.userMarkerElement = markerElement;
this.userMarker = new YMapMarker({ coordinates, dx: -16, dy: -16 }, markerElement);
this.map.addChild(this.userMarker);
this.userMarker = new this.mapgl.HtmlMarker(map, {
coordinates,
html: markerElement,
anchor: [USER_SIZE / 2, USER_SIZE / 2],
interactive: false,
preventMapInteractions: false,
disableRounding: true,
labeling: { type: 'none' },
zIndex: 3,
});
this.userMarker.getContent().style.overflow = 'visible';
} else {
this.userMarker.update({ coordinates });
this.userMarker?.setCoordinates(coordinates);
}
if (heading != null && !Number.isNaN(heading) && this.userMarkerElement) {
@@ -196,11 +211,7 @@ export class CityMap implements AfterViewInit, OnDestroy {
}
if (pan) {
this.map.setLocation({
center: coordinates,
...(this.zoomOnNextPan ? { zoom: 16 } : {}),
duration: 400,
});
this.moveMap(coordinates, this.zoomOnNextPan ? USER_ZOOM : null, 400);
this.zoomOnNextPan = false;
}
}
@@ -214,7 +225,7 @@ export class CityMap implements AfterViewInit, OnDestroy {
this.watchId = null;
}
private createMarker(YMapMarker: any, landmark: Landmark): any {
private createMarker(mapgl: MapglApi, map: MapglMap, landmark: Landmark): MapglHtmlMarker {
const markerElement = document.createElement('button');
markerElement.type = 'button';
markerElement.className = 'city-map__marker';
@@ -234,14 +245,18 @@ export class CityMap implements AfterViewInit, OnDestroy {
this.zone.run(() => this.selectLandmark(landmark));
});
return new YMapMarker(
{
const marker = new mapgl.HtmlMarker(map, {
coordinates: landmark.coordinates,
dx: -20,
dy: -20,
},
markerElement,
);
html: markerElement,
anchor: [LANDMARK_SIZE / 2, LANDMARK_SIZE / 2],
interactive: true,
disableRounding: true,
labeling: { type: 'none' },
zIndex: 1,
});
marker.getContent().style.overflow = 'visible';
return marker;
}
private setMarkerIcon(element: HTMLElement, collected: boolean): void {
@@ -251,9 +266,7 @@ export class CityMap implements AfterViewInit, OnDestroy {
return;
}
const src = collected
? '/assets/icons/check-marker.svg'
: '/assets/icons/lock-marker.svg';
const src = collected ? '/assets/icons/check-marker.svg' : '/assets/icons/lock-marker.svg';
if (img.getAttribute('src') !== src) {
img.setAttribute('src', src);
@@ -278,14 +291,17 @@ export class CityMap implements AfterViewInit, OnDestroy {
const selectedId = this.selected()?.id;
for (const [id, element] of this.markerElements) {
element.classList.toggle('city-map__marker--active', id === selectedId);
const active = id === selectedId;
element.classList.toggle('city-map__marker--active', active);
this.markers.get(id)?.setZIndex(active ? 2 : 1);
}
}
private syncRadiusSize(): void {
const selected = this.selected();
const map = this.map;
if (!selected) {
if (!selected || !map) {
return;
}
@@ -295,14 +311,41 @@ export class CityMap implements AfterViewInit, OnDestroy {
return;
}
const diameter = this.metersToPixels(selected.geoRadiusMeters, selected.coordinates[1]) * 2;
const diameter = this.metersToPixels(map, selected.geoRadiusMeters, selected.coordinates) * 2;
element.style.setProperty('--radius-px', `${diameter}px`);
}
private metersToPixels(meters: number, latitude: number): number {
const metersPerPixel =
(156543.03392 * Math.cos((latitude * Math.PI) / 180)) / 2 ** this.currentZoom;
private metersToPixels(
map: MapglMap,
meters: number,
coordinates: [number, number],
): number {
const [longitude, latitude] = coordinates;
const origin = map.project(coordinates);
const metersPerDegree = 111_320 * Math.cos((latitude * Math.PI) / 180);
const shifted = map.project([
longitude + meters / Math.max(metersPerDegree, 1),
latitude,
]);
return meters / Math.max(metersPerPixel, 0.01);
return Math.hypot(shifted[0] - origin[0], shifted[1] - origin[1]);
}
private moveMap(center: [number, number], zoom: number | null, duration: number): void {
const map = this.map;
if (!map) {
return;
}
map.setCenter(center, { duration, easing: 'easeOutCubic' });
if (zoom != null) {
map.setZoom(zoom, {
duration,
easing: 'easeOutCubic',
useHeightForAnimation: true,
});
}
}
}
+16 -4
View File
@@ -41,8 +41,10 @@
<ol class="facts">
@for (fact of item.facts; track fact; let index = $index) {
<li>
<span>{{ index + 1 }}</span>
<span class="facts__number">{{ index + 1 }}</span>
<span class="facts__value">
{{ fact }}
</span>
</li>
}
</ol>
@@ -52,13 +54,18 @@
<section>
<h2>Ваше фото</h2>
<button class="owned-photo" type="button" (click)="openPhoto()">
<img [src]="userPhoto() ?? '/assets/illustrations/photo-day.svg'" alt="Ваше фото объекта" />
<img
[src]="userPhoto() ?? '/assets/illustrations/photo-day.svg'"
alt="Ваше фото объекта"
/>
<span class="owned-photo__badge">
<app-icon name="check" [size]="14" />
Подтверждено
</span>
</button>
<p class="object__hint">Этот объект уже в вашей коллекции. Повторно его получить нельзя.</p>
<p class="object__hint">
Этот объект уже в вашей коллекции. Повторно его получить нельзя.
</p>
</section>
<a class="object__map" routerLink="/map">
@@ -105,7 +112,12 @@
@if (photoOpen()) {
@if (userPhoto(); as image) {
<div class="photo-viewer" (click)="closePhoto()">
<button class="photo-viewer__close" type="button" aria-label="Закрыть" (click)="closePhoto()">
<button
class="photo-viewer__close"
type="button"
aria-label="Закрыть"
(click)="closePhoto()"
>
<app-icon name="chevron-left" [size]="22" />
</button>
<img [src]="image" alt="Ваше фото объекта" (click)="$event.stopPropagation()" />
+11 -2
View File
@@ -78,12 +78,19 @@
.object__intro h1,
.object__body h2,
.facts span {
.facts {
margin: 0;
&__number {
font-family: var(--font-display);
font-weight: 700;
}
&__value {
margin: 0;
}
}
.object__intro h1 {
font-size: clamp(26px, 6.5vw, 32px);
line-height: 1.12;
@@ -220,12 +227,14 @@
line-height: 1.5;
}
.facts span {
.facts {
&__number {
min-width: 18px;
color: var(--color-accent);
font-size: 24px;
line-height: 1;
}
}
.object__hint {
margin: 10px 0 0;
+4
View File
@@ -0,0 +1,4 @@
pwa-camera-modal-instance {
--inset-width: var(--camera-width);
--inset-height: var(--camera-height);
}
+2 -8
View File
@@ -140,13 +140,7 @@
}
}
.city-map__canvas [class*='distribution'],
.city-map__canvas [class*='Distribution'],
.city-map__canvas .ymaps3--open-maps-button,
.city-map__canvas .ymaps3--controls_bottom {
display: none !important;
}
.city-map__canvas :has(> .city-map__marker) {
.city-map__canvas :has(> .city-map__marker),
.city-map__canvas :has(> .city-map__user) {
overflow: visible !important;
}
+2
View File
@@ -16,4 +16,6 @@
--page-max-width: 560px;
--radius-card: 24px;
--radius-pill: 999px;
--camera-width: 100%;
--camera-height: 100%;
}
+1
View File
@@ -6,3 +6,4 @@
@use 'map';
@use 'object';
@use 'collection';
@use 'camera';
-1
View File
@@ -21,7 +21,6 @@
href="https://fonts.googleapis.com/css2?family=Onest:wght@400;500;600;700&family=Playfair+Display:wght@700&display=swap"
rel="stylesheet"
/>
<script src="https://api-maps.yandex.ru/v3/?apikey=ea28b13d-e359-4f13-8020-1b492d5ddc8f&lang=ru_RU"></script>
</head>
<body>
<app-root></app-root>