From 75b91639b7f8d26403a30828dcffbbe6bc8bc17d Mon Sep 17 00:00:00 2001 From: Sebastian Roehl Date: Sun, 10 Dec 2017 11:32:42 +0100 Subject: [PATCH] add animated movement of map when changing the location. create map-info component. --- web/angular/src/app/app.component.html | 4 +- web/angular/src/app/app.module.ts | 2 + .../src/app/map-info/map-info.component.html | 3 ++ .../src/app/map-info/map-info.component.scss | 0 .../app/map-info/map-info.component.spec.ts | 25 ++++++++++++ .../src/app/map-info/map-info.component.ts | 16 ++++++++ web/angular/src/app/map/map.component.html | 1 - web/angular/src/app/map/map.component.scss | 9 ++--- web/angular/src/app/map/map.component.ts | 38 +++++++++++++++++-- 9 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 web/angular/src/app/map-info/map-info.component.html create mode 100644 web/angular/src/app/map-info/map-info.component.scss create mode 100644 web/angular/src/app/map-info/map-info.component.spec.ts create mode 100644 web/angular/src/app/map-info/map-info.component.ts diff --git a/web/angular/src/app/app.component.html b/web/angular/src/app/app.component.html index 1a9e2ca..e35521f 100644 --- a/web/angular/src/app/app.component.html +++ b/web/angular/src/app/app.component.html @@ -1,6 +1,6 @@ - +
+ -
diff --git a/web/angular/src/app/app.module.ts b/web/angular/src/app/app.module.ts index b8ed434..2ac79ee 100644 --- a/web/angular/src/app/app.module.ts +++ b/web/angular/src/app/app.module.ts @@ -24,6 +24,7 @@ import { DelayInterceptor } from './delay.interceptor'; import { MapComponent } from './map/map.component'; import { RegisterComponent } from './register/register.component'; import { HeaderComponent } from './header/header.component'; +import { MapInfoComponent } from './map-info/map-info.component'; const routes: Routes = [ { path: 'notices', component: NoticesComponent }, @@ -76,6 +77,7 @@ const apisocket: ()=>string = ()=>{ MapComponent, RegisterComponent, HeaderComponent, + MapInfoComponent, ], imports: [ RouterModule.forRoot(routes, { enableTracing: true }), diff --git a/web/angular/src/app/map-info/map-info.component.html b/web/angular/src/app/map-info/map-info.component.html new file mode 100644 index 0000000..5561a53 --- /dev/null +++ b/web/angular/src/app/map-info/map-info.component.html @@ -0,0 +1,3 @@ +

+ map-info works! +

diff --git a/web/angular/src/app/map-info/map-info.component.scss b/web/angular/src/app/map-info/map-info.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/web/angular/src/app/map-info/map-info.component.spec.ts b/web/angular/src/app/map-info/map-info.component.spec.ts new file mode 100644 index 0000000..062c24c --- /dev/null +++ b/web/angular/src/app/map-info/map-info.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { MapInfoComponent } from './map-info.component'; + +describe('MapInfoComponent', () => { + let component: MapInfoComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ MapInfoComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(MapInfoComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/web/angular/src/app/map-info/map-info.component.ts b/web/angular/src/app/map-info/map-info.component.ts new file mode 100644 index 0000000..88c5e14 --- /dev/null +++ b/web/angular/src/app/map-info/map-info.component.ts @@ -0,0 +1,16 @@ +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; + +@Component({ + selector: 'app-map-info', + templateUrl: './map-info.component.html', + styleUrls: ['./map-info.component.scss'], + encapsulation: ViewEncapsulation.None +}) +export class MapInfoComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/web/angular/src/app/map/map.component.html b/web/angular/src/app/map/map.component.html index 3dae213..592d684 100644 --- a/web/angular/src/app/map/map.component.html +++ b/web/angular/src/app/map/map.component.html @@ -1,4 +1,3 @@
-

Map for Share with id {{ currentShare }}

diff --git a/web/angular/src/app/map/map.component.scss b/web/angular/src/app/map/map.component.scss index b0c4e9c..e6dba43 100644 --- a/web/angular/src/app/map/map.component.scss +++ b/web/angular/src/app/map/map.component.scss @@ -1,13 +1,12 @@ .flex-container { - width: 80%; - margin: auto; + width: 100%; display: flex; - flex-direction: column; - justify-content: space-between; + flex-direction: row; + align-content: flex-start; } #map { height: 800px; - max-width: 100%; + width: 100%; border: 1px solid black; } diff --git a/web/angular/src/app/map/map.component.ts b/web/angular/src/app/map/map.component.ts index 58cc8e3..cb1acd7 100644 --- a/web/angular/src/app/map/map.component.ts +++ b/web/angular/src/app/map/map.component.ts @@ -1,7 +1,8 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; -import { Map, TileLayer, LatLng, Marker, Circle, Icon, marker } from 'leaflet'; +import { Map, TileLayer, LatLng, Marker, Circle, Icon, ZoomPanOptions } from 'leaflet'; +import { setInterval } from 'timers'; @Component({ @@ -12,9 +13,27 @@ import { Map, TileLayer, LatLng, Marker, Circle, Icon, marker } from 'leaflet'; }) export class MapComponent implements OnInit { + randomLocations: LatLng[] = [ + new LatLng(51.45165788, 7.00388614), + new LatLng(51.46000194, 7.01869371), + new LatLng(51.45517929, 7.02048384), + new LatLng(51.45978196, 7.01042728), + new LatLng(51.46385009, 7.01619635), + new LatLng(51.44816853, 7.01816195), + new LatLng(51.45525145, 7.00986632), + new LatLng(51.45425852, 7.01005042) + ]; + defaultLocation: LatLng = new LatLng(51.4556, 7.0116); defaultZoom: number = 13; + zoomPanOptions: ZoomPanOptions = { + animate: true, + duration: 2, + easeLinearity: 0.6, + noMoveStart: true + }; + currentShare: number; map: Map; tileLayer: TileLayer; @@ -34,18 +53,29 @@ export class MapComponent implements OnInit { this.currentShare = +this.route.snapshot.paramMap.get('id'); this.map = new Map('map'); - this.setMapPosition(this.defaultLocation, this.defaultZoom); - this.setMapMarker(this.defaultLocation); + this.map.setView(this.defaultLocation, this.defaultZoom); + // this.setMapMarker(this.defaultLocation); // this.map.on('click', (e) => this.setMapMarker(e.latlng)); this.tileLayer = new TileLayer('https://cloud.locoslab.com/carta/restful-services/tile/{z}/{x}/{y}.png', { attribution: 'Maptology', maxZoom: 18 }).addTo(this.map); + + // If there is a given shareId in the URL, fetch the location from the API and + // start to update every x seconds + if (this.currentShare) { + // TODO: Swap with real API call. WebSockets? Or Ajax? + setInterval(() => { + const randomLocationIndex = Math.floor(Math.random() * this.randomLocations.length); + this.setMapPosition(this.randomLocations[randomLocationIndex], 13); + }, 2000); + } } setMapPosition(latLang: LatLng, zoom: number) { - this.map.setView(latLang, zoom); + this.map.panTo(latLang, this.zoomPanOptions); + this.setMapMarker(latLang); } setMapMarker(latLang: LatLng) {