From 22cd28e2b3149d7fb97bb4ed40e2264aca92b2cf Mon Sep 17 00:00:00 2001 From: tim-herbst Date: Sat, 19 Dec 2020 18:53:07 +0100 Subject: [PATCH] add new component to seperate content of marker-popup * ng generate new component * add dummy binding to give component a bike-station --- .../project-3/frontend/src/app/app.module.ts | 4 ++- .../src/app/map/popup/popup.component.html | 1 + .../src/app/map/popup/popup.component.scss | 0 .../src/app/map/popup/popup.component.spec.ts | 25 +++++++++++++++++++ .../src/app/map/popup/popup.component.ts | 23 +++++++++++++++++ .../frontend/src/app/service/map.service.ts | 3 ++- 6 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 projects/project-3/frontend/src/app/map/popup/popup.component.html create mode 100644 projects/project-3/frontend/src/app/map/popup/popup.component.scss create mode 100644 projects/project-3/frontend/src/app/map/popup/popup.component.spec.ts create mode 100644 projects/project-3/frontend/src/app/map/popup/popup.component.ts diff --git a/projects/project-3/frontend/src/app/app.module.ts b/projects/project-3/frontend/src/app/app.module.ts index fb3ca8c..96b18e2 100644 --- a/projects/project-3/frontend/src/app/app.module.ts +++ b/projects/project-3/frontend/src/app/app.module.ts @@ -10,11 +10,13 @@ import {FlexLayoutModule} from '@angular/flex-layout'; import {MatIconModule} from '@angular/material/icon'; import {MatButtonModule} from '@angular/material/button'; import {HttpClientModule} from '@angular/common/http'; +import { PopupComponent } from './map/popup/popup.component'; @NgModule({ declarations: [ AppComponent, - MapComponent + MapComponent, + PopupComponent ], imports: [ BrowserModule, diff --git a/projects/project-3/frontend/src/app/map/popup/popup.component.html b/projects/project-3/frontend/src/app/map/popup/popup.component.html new file mode 100644 index 0000000..ad61498 --- /dev/null +++ b/projects/project-3/frontend/src/app/map/popup/popup.component.html @@ -0,0 +1 @@ +{{station.commonName}} diff --git a/projects/project-3/frontend/src/app/map/popup/popup.component.scss b/projects/project-3/frontend/src/app/map/popup/popup.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/projects/project-3/frontend/src/app/map/popup/popup.component.spec.ts b/projects/project-3/frontend/src/app/map/popup/popup.component.spec.ts new file mode 100644 index 0000000..fb8e171 --- /dev/null +++ b/projects/project-3/frontend/src/app/map/popup/popup.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PopupComponent } from './popup.component'; + +describe('PopupComponent', () => { + let component: PopupComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ PopupComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(PopupComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/projects/project-3/frontend/src/app/map/popup/popup.component.ts b/projects/project-3/frontend/src/app/map/popup/popup.component.ts new file mode 100644 index 0000000..e3f3a97 --- /dev/null +++ b/projects/project-3/frontend/src/app/map/popup/popup.component.ts @@ -0,0 +1,23 @@ +import {Component, OnInit} from '@angular/core'; +import {BikeStation, IBikeStation} from '../../service/domain/bike-station'; + +@Component({ + selector: 'app-popup', + templateUrl: './popup.component.html', + styleUrls: ['./popup.component.scss'] +}) +export class PopupComponent implements OnInit { + station: IBikeStation; + + constructor() { + } + + ngOnInit(): void { + } + + public bindStation(bikeStation: IBikeStation): void { + this.station = bikeStation; + console.log(this.station); + } + +} diff --git a/projects/project-3/frontend/src/app/service/map.service.ts b/projects/project-3/frontend/src/app/service/map.service.ts index 6e360b2..be18a4e 100644 --- a/projects/project-3/frontend/src/app/service/map.service.ts +++ b/projects/project-3/frontend/src/app/service/map.service.ts @@ -3,6 +3,7 @@ import * as L from 'leaflet'; import 'leaflet.markercluster'; import {HttpClient} from '@angular/common/http'; import {environment} from '../../environments/environment'; +import {PopupComponent} from '../map/popup/popup.component'; const dummyData = [ { @@ -55,7 +56,7 @@ export class MapService { zoomToBoundsOnClick: true }); for (const station of dummyData) { - const marker = L.marker([station.lat, station.lon], {icon: createIcon}); + const marker = L.marker([station.lat, station.lon], {icon: createIcon}).bindPopup(new PopupComponent().bindStation(station)); markerClusters.addLayer(marker); } this.map.addLayer(markerClusters);