src/app/ui/map/map.component.ts
encapsulation | ViewEncapsulation.None |
selector | ui-map |
styleUrls | ./map.component.scss |
templateUrl | ./map.component.html |
Properties |
Methods |
|
constructor(store: Store
|
||||||||||||
Defined in src/app/ui/map/map.component.ts:37
|
||||||||||||
Parameters :
|
ngOnInit |
ngOnInit()
|
Defined in src/app/ui/map/map.component.ts:55
|
Returns :
void
|
receiveActions |
receiveActions()
|
Defined in src/app/ui/map/map.component.ts:64
|
Returns :
void
|
sendActions |
sendActions()
|
Defined in src/app/ui/map/map.component.ts:128
|
Returns :
void
|
valueChanges |
valueChanges()
|
Defined in src/app/ui/map/map.component.ts:60
|
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Inherited from
BaseComponent
|
Defined in BaseComponent:13
|
Returns :
void
|
Abstract ngOnInit |
ngOnInit()
|
Inherited from
BaseComponent
|
Defined in BaseComponent:11
|
Returns :
void
|
Abstract receiveActions |
receiveActions()
|
Inherited from
BaseComponent
|
Defined in BaseComponent:27
|
Subscribes to the actions sent by other components.
Returns :
void
|
Abstract sendActions |
sendActions()
|
Inherited from
BaseComponent
|
Defined in BaseComponent:32
|
Subscribes to the actions sent to other components.
Returns :
void
|
Abstract valueChanges |
valueChanges()
|
Inherited from
BaseComponent
|
Defined in BaseComponent:22
|
Subscribes to the form changes.
Returns :
void
|
center |
center:
|
Type : google.maps.LatLngLiteral
|
Defined in src/app/ui/map/map.component.ts:24
|
currentStep |
currentStep:
|
Type : number
|
Defined in src/app/ui/map/map.component.ts:37
|
disableDefaultUI |
disableDefaultUI:
|
Type : boolean
|
Defined in src/app/ui/map/map.component.ts:29
|
disableDoubleClickZoom |
disableDoubleClickZoom:
|
Type : boolean
|
Defined in src/app/ui/map/map.component.ts:30
|
gestureHandling |
gestureHandling:
|
Type : string
|
Defined in src/app/ui/map/map.component.ts:34
|
mapTypeId |
mapTypeId:
|
Type : google.maps.MapTypeId
|
Defined in src/app/ui/map/map.component.ts:31
|
maxZoom |
maxZoom:
|
Type : number
|
Defined in src/app/ui/map/map.component.ts:32
|
minZoom |
minZoom:
|
Type : number
|
Defined in src/app/ui/map/map.component.ts:33
|
styles |
styles:
|
Type : google.maps.MapTypeStyle[]
|
Defined in src/app/ui/map/map.component.ts:35
|
zoom |
zoom:
|
Type : number
|
Defined in src/app/ui/map/map.component.ts:27
|
subscriptions |
subscriptions:
|
Type : Subscription[]
|
Default value : []
|
Inherited from
BaseComponent
|
Defined in BaseComponent:9
|
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { MapService } from './map.service';
import { NetworkService } from '../../network/network.service';
import * as fromUi from '../models/reducers';
import { Step } from '../models/ui-state';
import { mapStyle } from './map.style';
import { OdPair } from '../../network/graph';
import { uiConfig } from '../ui-config';
import { BaseComponent } from '../models/base.component';
@Component({
selector: 'ui-map',
templateUrl: './map.component.html',
styleUrls: ['./map.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class MapComponent extends BaseComponent implements OnInit {
// Center map. Required.
center: google.maps.LatLngLiteral;
// The initial map zoom level. Required.
zoom: number;
disableDefaultUI: boolean;
disableDoubleClickZoom: boolean;
mapTypeId: google.maps.MapTypeId;
maxZoom: number;
minZoom: number;
gestureHandling: string;
styles: google.maps.MapTypeStyle[];
currentStep: number;
constructor(
private store: Store<fromUi.UiState>,
private map: MapService,
private network: NetworkService
) {
super();
// Map options.
this.disableDefaultUI = true;
this.disableDoubleClickZoom = false;
this.mapTypeId = google.maps.MapTypeId.ROADMAP;
this.maxZoom = 18;
this.minZoom = 4;
this.gestureHandling = 'cooperative';
this.styles = mapStyle;
}
ngOnInit(): void {
this.receiveActions();
this.sendActions();
}
valueChanges(): void {
//
}
receiveActions(): void {
this.subscriptions.push(this.store.pipe(select(fromUi.currentStep)).subscribe((currentStep: number) => {
this.currentStep = currentStep;
switch (currentStep) {
case 0:
this.center = uiConfig.map.center;
this.zoom = uiConfig.map.zoom;
break;
case 1:
// Builds & shows initial rectangle.
const bounds: google.maps.LatLngBoundsLiteral = this.map.buildBounds(this.center);
this.map.showRect(bounds);
break;
case 2:
// Hides the rectangle.
this.map.hideRect();
// Shows graph.
this.map.showGraph();
// Sets centroid.
this.map.setCentroid();
// Sets map.
this.map.setCenter(this.map.getCentroid());
this.map.setZoom(17);
break;
case 3:
// Clears nodes actions.
this.map.clearNodesActions();
break;
case 4:
// Hides paths.
this.map.hidePaths();
break;
}
}));
this.subscriptions.push(this.store.pipe(select(fromUi.steps)).subscribe((steps: Step[]) => {
switch (this.currentStep) {
case 0:
if (steps[0]) {
// Updates center map.
this.center = steps[0].data.center;
this.zoom = 16;
} else {
this.center = uiConfig.map.center;
this.zoom = uiConfig.map.zoom;
}
break;
case 2:
if (steps[2]) {
// Shows/hides O/D nodes.
const odPairs: OdPair[] = steps[2].data.odPairs;
this.map.showNodes(odPairs);
}
break;
case 3:
if (steps[3] && steps[3].data.odPairs) {
// Shows/hides O/D paths.
const odPairs = steps[3].data.odPairs;
this.map.showPaths(odPairs);
}
break;
}
}));
}
sendActions(): void {
//
}
}
<google-map [center]="center" [zoom]="zoom" [disableDefaultUI]="disableDefaultUI" [disableDoubleClickZoom]="disableDoubleClickZoom"
[mapTypeId]="mapTypeId" [maxZoom]="maxZoom" [minZoom]="minZoom" [gestureHandling]="gestureHandling" [styles]="styles">
</google-map>
./map.component.scss
#map {
height: 70vh;
}