add new component to seperate content of marker-popup

* ng generate new component
* add dummy binding to give component a bike-station
This commit is contained in:
tim-herbst 2020-12-19 18:53:07 +01:00 committed by Tim Herbst
parent 18ceed31b1
commit 22cd28e2b3
6 changed files with 54 additions and 2 deletions

View File

@ -10,11 +10,13 @@ import {FlexLayoutModule} from '@angular/flex-layout';
import {MatIconModule} from '@angular/material/icon'; import {MatIconModule} from '@angular/material/icon';
import {MatButtonModule} from '@angular/material/button'; import {MatButtonModule} from '@angular/material/button';
import {HttpClientModule} from '@angular/common/http'; import {HttpClientModule} from '@angular/common/http';
import { PopupComponent } from './map/popup/popup.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
AppComponent, AppComponent,
MapComponent MapComponent,
PopupComponent
], ],
imports: [ imports: [
BrowserModule, BrowserModule,

View File

@ -0,0 +1 @@
<b>{{station.commonName}}</b>

View File

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

View File

@ -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);
}
}

View File

@ -3,6 +3,7 @@ import * as L from 'leaflet';
import 'leaflet.markercluster'; import 'leaflet.markercluster';
import {HttpClient} from '@angular/common/http'; import {HttpClient} from '@angular/common/http';
import {environment} from '../../environments/environment'; import {environment} from '../../environments/environment';
import {PopupComponent} from '../map/popup/popup.component';
const dummyData = [ const dummyData = [
{ {
@ -55,7 +56,7 @@ export class MapService {
zoomToBoundsOnClick: true zoomToBoundsOnClick: true
}); });
for (const station of dummyData) { 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); markerClusters.addLayer(marker);
} }
this.map.addLayer(markerClusters); this.map.addLayer(markerClusters);