Compare commits
5 Commits
fc56b58733
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 98f5be7c74 | |||
| 57e3c4d3ad | |||
| 7fb116ab2f | |||
|
|
b1464cc32e | ||
|
|
50b261e8ba |
1657
pnpm-lock.yaml
generated
1657
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,67 +0,0 @@
|
||||
import * as G from 'geojson';
|
||||
|
||||
// Custom GeoJSON style for the building
|
||||
export const buildingSytle = {
|
||||
color: '#d62305', // Red border
|
||||
weight: 2, // Border width
|
||||
fillColor: '#d4caca', // Red fill
|
||||
fillOpacity: 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 buildings: G.FeatureCollection = {
|
||||
type: 'FeatureCollection',
|
||||
features: [
|
||||
{
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
name: 'E',
|
||||
building: 'university',
|
||||
},
|
||||
geometry: {
|
||||
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
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
name: 'F',
|
||||
building: 'university',
|
||||
},
|
||||
geometry: {
|
||||
type: 'Polygon',
|
||||
coordinates: [
|
||||
[
|
||||
[8.3897585, 49.015502], // Southwest corner
|
||||
[8.3904592, 49.0154731], // Southeast corner
|
||||
[8.3904833, 49.0157255], // Northeast corner
|
||||
[8.3897827, 49.0157543], // Northwest corner
|
||||
[8.3897585, 49.015502], // Closing the polygon by repeating the first point
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -1,8 +1,15 @@
|
||||
<div class="map-wrapper">
|
||||
<div
|
||||
class="map-container"
|
||||
[ngClass]="isFullscreen ? 'map-fullscreen' : 'map-details'"
|
||||
leaflet
|
||||
[leafletOptions]="options"
|
||||
(leafletMapReady)="onMapReady($event)"
|
||||
></div>
|
||||
@if (!isFullscreen && details) {
|
||||
<div class="details">
|
||||
<h2>{{ details.name }}</h2>
|
||||
<p>{{ details.building }}</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
.map-container {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
position: absolute;
|
||||
position: fixed;
|
||||
top: 54px;
|
||||
height: calc(100vh - 54px);
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@@ -13,14 +13,14 @@
|
||||
}
|
||||
|
||||
.map-details {
|
||||
left: 10%;
|
||||
width: 90%;
|
||||
left: 25%;
|
||||
width: 75%;
|
||||
}
|
||||
|
||||
.details {
|
||||
position: absolute;
|
||||
position: fixed;
|
||||
top: 54px;
|
||||
left: 0;
|
||||
width: 10%;
|
||||
left: 25px;
|
||||
width: 25%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Component, signal } from '@angular/core';
|
||||
import { Component, signal, OnInit, ChangeDetectorRef } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { LeafletModule } from '@bluehalo/ngx-leaflet';
|
||||
import { center } from '@turf/turf';
|
||||
import { Overpass } from '../overpass';
|
||||
import * as L from 'leaflet';
|
||||
import * as G from 'geojson';
|
||||
|
||||
import * as D from './details';
|
||||
import * as E from './geojson';
|
||||
|
||||
@Component({
|
||||
selector: 'app-map',
|
||||
@@ -14,15 +14,26 @@ 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;
|
||||
details?: D.Details;
|
||||
|
||||
osm?: L.TileLayer;
|
||||
options: L.MapOptions = {};
|
||||
layerControl?: L.Control.Layers;
|
||||
|
||||
isFullscreen = true;
|
||||
|
||||
osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
constructor(
|
||||
private overpass: Overpass,
|
||||
private cdr: ChangeDetectorRef,
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
maxNativeZoom: 19,
|
||||
maxZoom: 21,
|
||||
minZoom: 18,
|
||||
@@ -30,41 +41,42 @@ export class OSMMap {
|
||||
});
|
||||
|
||||
// Define map options
|
||||
options: L.MapOptions = {
|
||||
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
|
||||
};
|
||||
|
||||
layerControl = L.control.layers({
|
||||
this.layerControl = L.control.layers({
|
||||
OpenStreetMap: this.osm,
|
||||
});
|
||||
|
||||
constructor(private overpass: Overpass) {}
|
||||
}
|
||||
|
||||
onMapReady(map: L.Map) {
|
||||
this.map = map;
|
||||
this.layerControl.addTo(this.map);
|
||||
this.loadBuildings().addTo(this.map);
|
||||
this.layerControl?.addTo(this.map);
|
||||
this.queryBuildingData().addTo(this.map);
|
||||
console.log('Map is ready');
|
||||
}
|
||||
|
||||
loadBuildings() {
|
||||
return L.geoJSON(E.buildings, {
|
||||
style: E.buildingSytle,
|
||||
queryBuildingData() {
|
||||
// Query the Overpass API for building data and add it to the map as a GeoJSON layer.
|
||||
|
||||
const buildingLayer = new L.LayerGroup();
|
||||
|
||||
this.overpass.fetchBuildingData().subscribe((data) => {
|
||||
console.log('Received building data:', data);
|
||||
L.geoJSON(this.createFeatureCollection(data), {
|
||||
style: { color: '#d62305', weight: 2, fillColor: '#d4caca', fillOpacity: 1 },
|
||||
onEachFeature: (feature, layer) => {
|
||||
layer.on({
|
||||
click: (e) => {
|
||||
this.isFullscreen = !this.isFullscreen;
|
||||
if (!this.isFullscreen) {
|
||||
this.map?.setView(this.getCenter(feature.geometry), 20);
|
||||
this.buildingLayer = this.queryBuildings(feature.properties.name);
|
||||
this.buildingLayer = this.queryIndoorData(feature.properties.name);
|
||||
this.buildingLayer.addTo(this.map!);
|
||||
this.details = new D.Details(feature.properties.name, feature.properties.building);
|
||||
} else {
|
||||
this.map?.setView(this.getCenter(), 18);
|
||||
if (this.buildingLayer) {
|
||||
@@ -73,6 +85,7 @@ export class OSMMap {
|
||||
}
|
||||
console.log('Set isFullscreen to:', this.isFullscreen);
|
||||
console.log('Clicked on feature:', feature.properties?.name);
|
||||
this.cdr.detectChanges();
|
||||
},
|
||||
});
|
||||
if (feature.properties && feature.properties.name) {
|
||||
@@ -82,17 +95,52 @@ export class OSMMap {
|
||||
});
|
||||
}
|
||||
},
|
||||
}).addTo(buildingLayer);
|
||||
});
|
||||
return buildingLayer;
|
||||
}
|
||||
|
||||
queryBuildings(building_name: string) {
|
||||
queryIndoorData(building_name: string): L.LayerGroup {
|
||||
// Get the building name from the feature properties and query the Overpass API for detailed building data,
|
||||
// including indoor features.
|
||||
|
||||
// Create a new LayerGroup to hold the building polygons
|
||||
const resultingLayer = new L.LayerGroup();
|
||||
this.overpass.fetchBuildings(building_name).subscribe((data) => {
|
||||
console.log('Fetched building data from Overpass API:', data);
|
||||
|
||||
this.overpass.fetchIndoorData(building_name).subscribe((data) => {
|
||||
console.log('Received indoor data for building:', building_name, data);
|
||||
L.geoJSON(this.createFeatureCollection(data), {
|
||||
style: { color: '#999999', fillColor: '#e0e0e0', fillOpacity: 1 },
|
||||
onEachFeature: (feature, layer) => {
|
||||
if (feature.properties) {
|
||||
layer.bindTooltip(feature.properties.ref ?? 'Test', {
|
||||
permanent: false,
|
||||
direction: 'top',
|
||||
});
|
||||
}
|
||||
},
|
||||
}).addTo(resultingLayer);
|
||||
});
|
||||
return resultingLayer;
|
||||
}
|
||||
|
||||
private getCenter(feature?: any): L.LatLng {
|
||||
// Calculate the center of the feature using Turf.js, or use a default center if no feature is provided.
|
||||
let centerPoint: number[] = [];
|
||||
if (feature) {
|
||||
centerPoint = center(feature).geometry.coordinates.reverse();
|
||||
} else {
|
||||
centerPoint = [49.015514096207895, 8.391567600294243];
|
||||
}
|
||||
const result = new L.LatLng(centerPoint[0], centerPoint[1]);
|
||||
return result;
|
||||
}
|
||||
|
||||
private createFeatureCollection(data: any): G.FeatureCollection {
|
||||
const buildingData: G.FeatureCollection = {
|
||||
type: 'FeatureCollection',
|
||||
features: [],
|
||||
};
|
||||
|
||||
// Create a mapping of node IDs to their coordinates
|
||||
const nodes: Map<number, L.LatLng> = new Map();
|
||||
@@ -110,24 +158,23 @@ export class OSMMap {
|
||||
element.nodes.forEach((nodeId: number) => {
|
||||
coordinates.push(nodes.get(nodeId)!);
|
||||
});
|
||||
L.polygon(coordinates, { color: '#999999', fillColor: '#e0e0e0', fillOpacity: 1 }).addTo(
|
||||
resultingLayer,
|
||||
buildingData.features.push(
|
||||
this.createFeature(new Map(Object.entries(element.tags || {})), coordinates),
|
||||
// this.createFeature(new Map(Object.entries({ name: 'Test' })), coordinates),
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
return resultingLayer;
|
||||
return buildingData;
|
||||
}
|
||||
|
||||
private getCenter(feature?: any): L.LatLng {
|
||||
// Calculate the center of the feature using Turf.js, or use a default center if no feature is provided.
|
||||
let centerPoint: number[] = [];
|
||||
if (feature) {
|
||||
centerPoint = center(feature).geometry.coordinates.reverse();
|
||||
} else {
|
||||
centerPoint = [49.015514096207895, 8.391567600294243];
|
||||
}
|
||||
const result = new L.LatLng(centerPoint[0], centerPoint[1]);
|
||||
return result;
|
||||
private createFeature(properties: Map<string, string>, coordinates: L.LatLng[]): G.Feature {
|
||||
return {
|
||||
type: 'Feature',
|
||||
properties: Object.fromEntries(properties),
|
||||
geometry: {
|
||||
type: 'Polygon',
|
||||
coordinates: [coordinates.map((coord) => [coord.lng, coord.lat])],
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,11 @@ export class Overpass {
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
fetchBuildings(building_name: string) {
|
||||
fetchIndoorData(building_name: string) {
|
||||
const header = { 'Content-Type': 'text/plain' };
|
||||
const query = `
|
||||
[out:json][timeout:25];
|
||||
nwr["building"]["operator"="Hochschule Karlsruhe"]["name"="${building_name}"](49.014442, 8.387954, 49.017847, 8.395448)->.building;
|
||||
[out:json][timeout:90];
|
||||
nwr["building"]["operator"="Hochschule Karlsruhe"]["name"="${building_name}"]->.building;
|
||||
(
|
||||
nwr["indoor"="room"](area.building);
|
||||
);
|
||||
@@ -42,4 +42,17 @@ export class Overpass {
|
||||
|
||||
return this.http.post<OverpassResponse>(this.apiUrl, query, { headers: header });
|
||||
}
|
||||
|
||||
fetchBuildingData() {
|
||||
const header = { 'Content-Type': 'text/plain' };
|
||||
const query = `
|
||||
[out:json][timeout:90];
|
||||
(
|
||||
way["building"="university"]["operator"="Hochschule Karlsruhe"];
|
||||
);
|
||||
(._;>;);
|
||||
out body;
|
||||
`;
|
||||
return this.http.post<OverpassResponse>(this.apiUrl, query, { headers: header });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user