77 ViewChild ,
88} from '@angular/core' ;
99import { ReplaySubject } from 'rxjs' ;
10- import { take } from 'rxjs/operators' ;
1110
1211/**
1312 * Angular component that renders a Google Map via the Google Maps JavaScript
@@ -20,30 +19,28 @@ import {take} from 'rxjs/operators';
2019 template : '<div #map></div>' ,
2120} )
2221export class GoogleMap implements OnInit {
22+ // Arbitrarily chosen default size
2323 @Input ( ) height = '500px' ;
2424 @Input ( ) width = '500px' ;
25+
2526 // TODO(mbehrlich): add options, handlers, properties, and methods.
2627
27- @ViewChild ( 'map' , { static : true } ) set mapEl ( mapEl : ElementRef ) {
28- this . _mapEl$ . next ( mapEl ) ;
29- }
28+ @ViewChild ( 'map' , { static : true } ) mapElRef : ElementRef ;
3029
31- private readonly _mapEl$ = new ReplaySubject < ElementRef > ( 1 ) ;
3230 private readonly _map$ = new ReplaySubject < google . maps . Map > ( 1 ) ;
3331
3432 ngOnInit ( ) {
3533 // default options for now
3634 const options : google . maps . MapOptions = {
37- center : { lat : 50 , lng : 50 } ,
38- zoom : 4 ,
35+ center : { lat : 41.890150 , lng : 12.492231 } ,
36+ zoom : 16 ,
3937 } ;
4038
41- this . _mapEl$ . pipe ( take ( 1 ) ) . subscribe ( mapElRef => {
42- const mapEl = mapElRef . nativeElement ;
43- mapEl . style . height = this . height ;
44- mapEl . style . width = this . width ;
45- const map = new google . maps . Map ( mapEl , options ) ;
46- this . _map$ . next ( map ) ;
47- } ) ;
39+
40+ const mapEl = this . mapElRef . nativeElement ;
41+ mapEl . style . height = this . height ;
42+ mapEl . style . width = this . width ;
43+ const map = new google . maps . Map ( mapEl , options ) ;
44+ this . _map$ . next ( map ) ;
4845 }
4946}
0 commit comments