<commit_before>import {AfterViewInit, Component, EventEmitter, Input, NgZone, OnChanges, Output, SimpleChanges} from '@angular/core';
import {FieldDocument, FieldResource, FieldGeometry} from 'idai-components-2';
import {FieldPolyline} from './field-polyline';
import {FieldPolygon} from './field-polygon';
import {FieldMarker} from './field-marker';
import {CoordinatesUtility} from './coordinates-utility';
import {ProjectConfiguration} from '../../../../core/configuration/project-configuration';
import {Category} from '../../../../core/configuration/model/category';


@Component({
    selector: 'map',
    template: '<div id="map-container"></div>'
})

/**
 * @author <NAME>
 */
export class MapComponent implements AfterViewInit, OnChanges {

    @Input() documents: Array<FieldDocument>;
    @Input() selectedDocument: FieldDocument;
    @Input() parentDocument: FieldDocument;
    @Input() coordinateReferenceSystem: string;
    @Input() update: boolean;

    @Output() onSelectDocument: EventEmitter<FieldDocument|undefined>
        = new EventEmitter<FieldDocument|undefined>();

    protected map: any;
    protected polygons: { [resourceId: string]: Array<FieldPolygon> } = {};
    protected polylines: { [resourceId: string]: Array<FieldPolyline> } = {};
    protected markers: { [resourceId: string]: Array<FieldMarker> } = {};

    protected bounds: any[] = []; // in fact L.LatLng[], but leaflet typings are incomplete
    protected categoryColors: { [categoryName: string]: string } = {};


    constructor(projectConfiguration: ProjectConfiguration,
                protected zone: NgZone) {

        this.categoryColors = projectConfiguration.getCategoryColors();
    }


    public ngAfterViewInit() {

        this.zone.runOutsideAngular(() => {
            if (this.map) this.map.invalidateSize(false);
        });
    }


    public ngOnChanges(changes: SimpleChanges) {

        this.zone.runOutsideAngular(() => {
            if (!this.map) this.map = this.createMap();

            // The promise is necessary to make sure the map is updated based on the current map container size
            Promise.resolve().then(() => this.updateMap(changes));
        });
    }


    protected createMap(): L.Map {

        const mapOptions: L.MapOptions = {
            crs: this.getCoordinateReferenceSystem(),
            attributionControl: false,
            preferCanvas: true,
            minZoom: -20,
            maxZoom: 30,
            maxBoundsViscosity: 0.7
        };

        const map: L.Map = L.map('map-container', mapOptions);<commit_msg>Remove unneeded map option<commit_after>import {AfterViewInit, Component, EventEmitter, Input, NgZone, OnChanges, Output, SimpleChanges} from '@angular/core';
import {FieldDocument, FieldResource, FieldGeometry} from 'idai-components-2';
import {FieldPolyline} from './field-polyline';
import {FieldPolygon} from './field-polygon';
import {FieldMarker} from './field-marker';
import {CoordinatesUtility} from './coordinates-utility';
import {ProjectConfiguration} from '../../../../core/configuration/project-configuration';
import {Category} from '../../../../core/configuration/model/category';


@Component({
    selector: 'map',
    template: '<div id="map-container"></div>'
})

/**
 * @author <NAME>
 */
export class MapComponent implements AfterViewInit, OnChanges {

    @Input() documents: Array<FieldDocument>;
    @Input() selectedDocument: FieldDocument;
    @Input() parentDocument: FieldDocument;
    @Input() coordinateReferenceSystem: string;
    @Input() update: boolean;

    @Output() onSelectDocument: EventEmitter<FieldDocument|undefined>
        = new EventEmitter<FieldDocument|undefined>();

    protected map: any;
    protected polygons: { [resourceId: string]: Array<FieldPolygon> } = {};
    protected polylines: { [resourceId: string]: Array<FieldPolyline> } = {};
    protected markers: { [resourceId: string]: Array<FieldMarker> } = {};

    protected bounds: any[] = []; // in fact L.LatLng[], but leaflet typings are incomplete
    protected categoryColors: { [categoryName: string]: string } = {};


    constructor(projectConfiguration: ProjectConfiguration,
                protected zone: NgZone) {

        this.categoryColors = projectConfiguration.getCategoryColors();
    }


    public ngAfterViewInit() {

        this.zone.runOutsideAngular(() => {
            if (this.map) this.map.invalidateSize(false);
        });
    }


    public ngOnChanges(changes: SimpleChanges) {

        this.zone.runOutsideAngular(() => {
            if (!this.map) this.map = this.createMap();

            // The promise is necessary to make sure the map is updated based on the current map container size
            Promise.resolve().then(() => this.updateMap(changes));
        });
    }


    protected createMap(): L.Map {

        const mapOptions: L.MapOptions = {
            crs: this.getCoordinateReferenceSystem(),
            attributionControl: false,
            preferCanvas: true,
            minZoom: -20,
            maxZoom: 30
        };

        const map: L.Map = L.map('map-container', mapOptions);
{'fraction_non_alphanumeric': 0.1368606013276064, 'fraction_numerical': 0.0023428348301444747, 'mean_word_length': 3.2373862696443343, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, 'https://': 0, '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': '1786513', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1342, 'n_words': 346}