<commit_before>import { Component, ElementRef, EventEmitter, Input, NgZone, Output, ViewChild } from "@angular/core";
import {} from "@types/googlemaps";

import { ConfigurationService } from "../configuration.service";
import { I18nService } from "../i18n.service";
import { InfoWindowViewService } from "../info-window-view.service";
import { Location } from "../model/location";
import { LocalStorageService } from "../local-storage.service";

@Component({
    selector: "app-google-map",
    template: `<div #mapDiv></div>`,
    styles: [ `div { width: 100%; height: 100%; }` ],
})
export class GoogleMapComponent {

    constructor(
        private readonly configurationService: ConfigurationService,
        private readonly i18nService: I18nService,
        private readonly infoWindowViewService: InfoWindowViewService,
        private readonly localStorageService: LocalStorageService,
        private readonly ngZone: NgZone,
    ) {}

    @Input() set locations(locations: Location[]) {
        this._locations = locations;

        for (const [marker, location] of this.markersToLocations.entries()) {
            const map = locations.includes(location) ? this.map : null;
            if (marker.getMap() !== map) {
                marker.setMap(map);
            }
        }
    }

    get locations(): Location[] {
        return this._locations;
    }

    private _locations: Location[];

    @Input() set coordinates(coordinates: Coordinates | null) {
        this._coordinates = coordinates;

        if (coordinates) {
            const position = new google.maps.LatLng(coordinates.latitude, coordinates.longitude);

            if (this.coordinatesMarker) {
                this.coordinatesMarker.setPosition(position);
            } else {
                this.coordinatesMarker = new google.maps.Marker({
                    map: this.map,
                    position: position,
                    title: this.i18n.geolocation.currentPosition,
                    icon: this.configurationService.getIconUrlForCoordinates()
                });

                google.maps.event.addListener(this.coordinatesMarker, "click", () => {
                    this.map.setCenter(this.coordinatesMarker.getPosition());
                    this.infoWindow.setContent(this.coordinatesMarker.getTitle());
                    this.infoWindow.open(this.map, this.coordinatesMarker);
                });
            }
        } else if (this.coordinatesMarker) {
            this.coordinatesMarker.setMap(null);
            delete this.coordinatesMarker;
        }
    }

    get coordinates(): Coordinates | null {
        return this._coordinates;
    }

    private _coordinates: Coordinates | null;

    @Output() readonly locationSelect = new EventEmitter<Location | null>();

    @ViewChild("mapDiv") mapDiv: ElementRef;

    private map: google.maps.Map;
    private coordinatesMarker: google.maps.Marker;
    private readonly markersToLocations = new Map<google.maps.Marker, Location>();
    private readonly locationsToMarkers = new Map<Location, google.maps.Marker>();
    private readonly infoWindow = new google.maps.InfoWindow();
    private readonly i18n = this.i18nService.getI18n();

    init(locations: Location[]) {
        const center = this.configurationService.mapCenter;
        const mapOptions: google.maps.MapOptions = {
            zoom: 12,
            center: new google.maps.LatLng(center.lat, center.lng),
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            gestureHandling: "greedy",
        };

        this.map = new google.maps.Map(this.mapDiv.nativeElement, mapOptions);

        for (const location of locations) {
            this.createMarker(location);
        }
    }

    private createMarker(location: Location) {
        const marker = new google.maps.Marker({
            map: this.map,
            position: new google.maps.LatLng(location.latCoord, location.longCoord),
            title: location.name,
            icon: this.getIcon(location)
        });

        google.maps.event.addListener(marker, "click", () => {
            const mode = this.localStorageService.settings.infoMode === "popUp" ? "full" : "minimal";<commit_msg>Improve accessibility<commit_after>import { Component, ElementRef, EventEmitter, Input, NgZone, Output, ViewChild } from "@angular/core";
import {} from "@types/googlemaps";

import { ConfigurationService } from "../configuration.service";
import { I18nService } from "../i18n.service";
import { InfoWindowViewService } from "../info-window-view.service";
import { Location } from "../model/location";
import { LocalStorageService } from "../local-storage.service";

@Component({
    selector: "app-google-map",
    template: `<div #mapDiv></div>`,
    styles: [ `div { width: 100%; height: 100%; }` ],
})
export class GoogleMapComponent {

    constructor(
        private readonly configurationService: ConfigurationService,
        private readonly i18nService: I18nService,
        private readonly infoWindowViewService: InfoWindowViewService,
        private readonly localStorageService: LocalStorageService,
        private readonly ngZone: NgZone,
    ) {}

    @Input() set locations(locations: Location[]) {
        this._locations = locations;

        for (const [marker, location] of this.markersToLocations.entries()) {
            const map = locations.includes(location) ? this.map : null;
            if (marker.getMap() !== map) {
                marker.setMap(map);
            }
        }
    }

    get locations(): Location[] {
        return this._locations;
    }

    private _locations: Location[];

    @Input() set coordinates(coordinates: Coordinates | null) {
        this._coordinates = coordinates;

        if (coordinates) {
            const position = new google.maps.LatLng(coordinates.latitude, coordinates.longitude);

            if (this.coordinatesMarker) {
                this.coordinatesMarker.setPosition(position);
            } else {
                this.coordinatesMarker = new google.maps.Marker({
                    map: this.map,
                    position: position,
                    title: this.i18n.geolocation.currentPosition,
                    icon: this.configurationService.getIconUrlForCoordinates()
                });

                google.maps.event.addListener(this.coordinatesMarker, "click", () => {
                    this.map.setCenter(this.coordinatesMarker.getPosition());
                    this.infoWindow.setContent(this.coordinatesMarker.getTitle());
                    this.infoWindow.open(this.map, this.coordinatesMarker);
                });
            }
        } else if (this.coordinatesMarker) {
            this.coordinatesMarker.setMap(null);
            delete this.coordinatesMarker;
        }
    }

    get coordinates(): Coordinates | null {
        return this._coordinates;
    }

    private _coordinates: Coordinates | null;

    @Output() readonly locationSelect = new EventEmitter<Location | null>();

    @ViewChild("mapDiv") mapDiv: ElementRef;

    private map: google.maps.Map;
    private coordinatesMarker: google.maps.Marker;
    private readonly markersToLocations = new Map<google.maps.Marker, Location>();
    private readonly locationsToMarkers = new Map<Location, google.maps.Marker>();
    private readonly infoWindow = new google.maps.InfoWindow();
    private readonly i18n = this.i18nService.getI18n();

    init(locations: Location[]) {
        const center = this.configurationService.mapCenter;
        const mapOptions: google.maps.MapOptions = {
            zoom: 12,
            center: new google.maps.LatLng(center.lat, center.lng),
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            gestureHandling: "greedy",
        };

        this.map = new google.maps.Map(this.mapDiv.nativeElement, mapOptions);

        // For accessibility. See https://stackoverflow.com/a/50845779.
        google.maps.event.addListenerOnce(this.map, "idle", () => {
            this.mapDiv.nativeElement.getElementsByTagName("iframe")[0].title = "Google Maps";
        });

        for (const location of locations) {
            this.createMarker(location);
        }
    }

    private createMarker(location: Location) {
        const marker = new google.maps.Marker({
            map: this.map,
            position: new google.maps.LatLng(location.latCoord, location.longCoord),
            title: location.name,
            icon: this.getIcon(location)
        });

        google.maps.event.addListener(marker, "click", () => {
            const mode = this.localStorageService.settings.infoMode === "popUp" ? "full" : "minimal";
{'fraction_non_alphanumeric': 0.11502076603599447, 'fraction_numerical': 0.006575911398246424, 'mean_word_length': 2.4801284624648736, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 18, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1556351', 'n_tokens_mistral': 2338, 'n_tokens_neox': 2223, 'n_words': 485}