This commit is contained in:
2026-04-09 14:13:07 +02:00
parent 218523d488
commit 0848edb832
22 changed files with 287 additions and 365 deletions

33
src/app/map/geojson.ts Normal file
View File

@@ -0,0 +1,33 @@
import * as G from 'geojson';
// Custom GeoJSON style for the building
export const buildingSytle = {
color: '#d62305', // Red border
weight: 2, // Border width
fillColor: '#d62305', // Red fill
fillOpacity: 0.1, // Semi-transparent fill
};
// Example GeoJSON data
export const examplePolygon: G.Polygon = {
type: 'Polygon',
coordinates: [
[
[8.3897067, 49.0149349], // Southwest corner
[8.3904111, 49.0149078], // Southeast corner
[8.3904345, 49.0151542], // Northeast corner
[8.3897302, 49.0151832], // Northwest corner
[8.3897067, 49.0149349], // Closing the polygon by repeating the first point
],
],
};
export const buildingE: G.Feature = {
type: 'Feature',
properties: {
name: 'Gebäude E',
building: 'university',
center: [8.39007, 49.015],
},
geometry: examplePolygon,
};

8
src/app/map/map.html Normal file
View File

@@ -0,0 +1,8 @@
<div class="map-wrapper">
<div
class="map-container"
leaflet
[leafletOptions]="options"
(leafletMapReady)="onMapReady($event)"
></div>
</div>

View File

@@ -0,0 +1,8 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
@NgModule({
declarations: [],
imports: [CommonModule],
})
export class MapModule {}

9
src/app/map/map.scss Normal file
View File

@@ -0,0 +1,9 @@
.map-container {
padding: 0;
margin: 0;
position: absolute;
top: 54px;
left: 0;
width: 100%;
height: calc(100vh - 54px);
}

22
src/app/map/map.spec.ts Normal file
View File

@@ -0,0 +1,22 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Map } from './map';
describe('Map', () => {
let component: Map;
let fixture: ComponentFixture<Map>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Map],
}).compileComponents();
fixture = TestBed.createComponent(Map);
component = fixture.componentInstance;
await fixture.whenStable();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

68
src/app/map/map.ts Normal file
View File

@@ -0,0 +1,68 @@
import { Component, signal } from '@angular/core';
import { LeafletModule } from '@bluehalo/ngx-leaflet';
import * as L from 'leaflet';
import * as E from './geojson';
@Component({
selector: 'app-map',
imports: [LeafletModule],
templateUrl: './map.html',
styleUrl: './map.scss',
})
export class Map {
private centerLocation = { lat: 49.015514096207895, lng: 8.391567600294243 };
protected readonly title = signal('HKA-OSM');
map?: L.Map;
isFullscreen = false;
// Define map options
options: L.MapOptions = {
layers: [
// OpenStreetMap tile layer
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxNativeZoom: 19,
maxZoom: 21,
minZoom: 18,
attribution: '© OpenStreetMap contributors',
}),
],
zoom: 18, // Zoom level
center: L.latLng(this.centerLocation.lat, this.centerLocation.lng),
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
};
// Optional: Add markers or other features
onMapReady(map: L.Map) {
this.map = map;
L.geoJSON(E.buildingE, {
style: E.buildingSytle,
onEachFeature: (feature, layer) => {
layer.on({
click: (e) => {
this.map?.setView(
L.latLng(
feature.properties.center[1], // Latitude of the first point
feature.properties.center[0], // Longitude of the first point
),
20,
);
console.log('Clicked on feature:', feature.properties?.name);
},
});
if (feature.properties && feature.properties.name) {
layer.bindTooltip(feature.properties.name, {
permanent: false,
direction: 'top',
});
}
},
}).addTo(this.map);
console.log('Map is ready');
}
}