Move initialization into ngOnInit

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
David Sp
2026-04-27 14:08:01 +02:00
parent fc56b58733
commit 50b261e8ba

View File

@@ -1,4 +1,4 @@
import { Component, signal } from '@angular/core';
import { Component, signal, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { LeafletModule } from '@bluehalo/ngx-leaflet';
import { center } from '@turf/turf';
@@ -14,42 +14,50 @@ import * as E from './geojson';
templateUrl: './map.html',
styleUrl: './map.scss',
})
export class OSMMap {
export class OSMMap implements OnInit {
private buildingLayer?: L.LayerGroup;
protected readonly title = signal('HKA-OSM');
map?: L.Map;
osm?: L.TileLayer;
options: L.MapOptions = {};
layerControl?: L.Control.Layers;
isFullscreen = true;
osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxNativeZoom: 19,
maxZoom: 21,
minZoom: 18,
attribution: '© OpenStreetMap contributors',
});
constructor(
private overpass: Overpass
) {}
// Define map options
options: L.MapOptions = {
layers: [this.osm],
zoom: 18, // Zoom level
center: this.getCenter(), // Center of the map
maxBounds: L.latLngBounds(
L.latLng(49.014442, 8.387954), // Southwest corner
L.latLng(49.017847, 8.395448), // Northeast corner
),
maxBoundsViscosity: 1.0, // Prevent panning outside bounds
};
ngOnInit() {
this.osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxNativeZoom: 19,
maxZoom: 21,
minZoom: 18,
attribution: '© OpenStreetMap contributors',
});
layerControl = L.control.layers({
OpenStreetMap: this.osm,
});
// Define map options
this.options = {
layers: [this.osm],
zoom: 18, // Zoom level
center: this.getCenter(), // Center of the map
maxBounds: L.latLngBounds(
L.latLng(49.014442, 8.387954), // Southwest corner
L.latLng(49.017847, 8.395448), // Northeast corner
),
maxBoundsViscosity: 1.0, // Prevent panning outside bounds
};
constructor(private overpass: Overpass) {}
this.layerControl = L.control.layers({
OpenStreetMap: this.osm,
});
}
onMapReady(map: L.Map) {
this.map = map;
this.layerControl.addTo(this.map);
this.layerControl?.addTo(this.map);
this.loadBuildings().addTo(this.map);
console.log('Map is ready');
}