From 50b261e8ba26c09490613dcf6ada988980e6d291 Mon Sep 17 00:00:00 2001 From: David Sp Date: Mon, 27 Apr 2026 14:08:01 +0200 Subject: [PATCH] Move initialization into ngOnInit Co-authored-by: Copilot --- src/app/map/map.ts | 56 ++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/src/app/map/map.ts b/src/app/map/map.ts index e8df937..88a9d4b 100644 --- a/src/app/map/map.ts +++ b/src/app/map/map.ts @@ -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'); }