add animated movement of map when changing the location. create map-info component.
lbs-gitea/maptology/master This commit looks good

This commit is contained in:
Sebastian Roehl
2017-12-10 11:32:42 +01:00
parent eb991a3bbe
commit 75b91639b7
9 changed files with 86 additions and 12 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
<app-header></app-header>
<div>
<app-header></app-header>
<div class="container">
<router-outlet></router-outlet>
<app-console></app-console>
+2
View File
@@ -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 }),
@@ -0,0 +1,3 @@
<p>
map-info works!
</p>
@@ -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<MapInfoComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MapInfoComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(MapInfoComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -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() {
}
}
@@ -1,4 +1,3 @@
<div class="flex-container">
<h3>Map for Share with id {{ currentShare }}</h3>
<div id="map"></div>
</div>
+4 -5
View File
@@ -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;
}
+34 -4
View File
@@ -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) {