7
7
*/
8
8
9
9
import {
10
- ChangeDetectionStrategy ,
11
- Component ,
10
+ Directive ,
12
11
ElementRef ,
13
12
EventEmitter ,
14
13
Input ,
15
14
OnDestroy ,
16
15
OnInit ,
17
16
Output ,
18
- ViewChild ,
19
- ViewEncapsulation ,
20
17
} from '@angular/core' ;
21
- import { BehaviorSubject , combineLatest , Observable , ReplaySubject , Subject } from 'rxjs' ;
18
+ import { BehaviorSubject , combineLatest , Observable , Subject } from 'rxjs' ;
22
19
import { map , takeUntil } from 'rxjs/operators' ;
23
20
24
21
import { GoogleMap } from '../google-map/index' ;
@@ -28,17 +25,9 @@ import {MapMarker} from '../map-marker/index';
28
25
* Angular component that renders a Google Maps info window via the Google Maps JavaScript API.
29
26
* @see developers.google.com/maps/documentation/javascript/reference/info-window
30
27
*/
31
- @Component ( {
32
- moduleId : module . id ,
28
+ @Directive ( {
33
29
selector : 'map-info-window' ,
34
- template : `<div class="map-info-window-container">
35
- <div #infoWindowContent class="map-info-window-content">
36
- <ng-content></ng-content>
37
- </div>
38
- </div>` ,
39
- styleUrls : [ './assets/map-info-window.css' ] ,
40
- changeDetection : ChangeDetectionStrategy . OnPush ,
41
- encapsulation : ViewEncapsulation . None ,
30
+ host : { 'style' : 'display: none' } ,
42
31
} )
43
32
export class MapInfoWindow implements OnInit , OnDestroy {
44
33
@Input ( )
@@ -84,22 +73,17 @@ export class MapInfoWindow implements OnInit, OnDestroy {
84
73
*/
85
74
@Output ( ) zindexChanged = new EventEmitter < void > ( ) ;
86
75
87
- @ViewChild ( 'infoWindowContent' , { static : false } )
88
- set content ( content : ElementRef ) {
89
- this . _content . next ( content . nativeElement ) ;
90
- }
91
-
92
76
private readonly _options = new BehaviorSubject < google . maps . InfoWindowOptions > ( { } ) ;
93
77
private readonly _position = new BehaviorSubject < google . maps . LatLngLiteral | undefined > ( undefined ) ;
94
- private readonly _content = new ReplaySubject < Node > ( 1 ) ;
95
78
96
79
private readonly _listeners : google . maps . MapsEventListener [ ] = [ ] ;
97
80
98
81
private readonly _destroy = new Subject < void > ( ) ;
99
82
100
83
private _infoWindow ?: google . maps . InfoWindow ;
101
84
102
- constructor ( private readonly googleMap : GoogleMap ) { }
85
+ constructor ( private readonly googleMap : GoogleMap , private _elementRef : ElementRef < HTMLElement > ) {
86
+ }
103
87
104
88
ngOnInit ( ) {
105
89
this . _combineOptions ( ) . pipe ( takeUntil ( this . _destroy ) ) . subscribe ( options => {
@@ -162,20 +146,20 @@ export class MapInfoWindow implements OnInit, OnDestroy {
162
146
open ( anchor ?: MapMarker ) {
163
147
const marker = anchor ? anchor . _marker : undefined ;
164
148
if ( this . googleMap . _googleMap ) {
149
+ this . _elementRef . nativeElement . style . display = '' ;
165
150
this . _infoWindow ! . open ( this . googleMap . _googleMap , marker ) ;
166
151
}
167
152
}
168
153
169
154
private _combineOptions ( ) : Observable < google . maps . InfoWindowOptions > {
170
- return combineLatest ( this . _options , this . _position , this . _content )
171
- . pipe ( map ( ( [ options , position , content ] ) => {
172
- const combinedOptions : google . maps . InfoWindowOptions = {
173
- ...options ,
174
- position : position || options . position ,
175
- content,
176
- } ;
177
- return combinedOptions ;
178
- } ) ) ;
155
+ return combineLatest ( this . _options , this . _position ) . pipe ( map ( ( [ options , position ] ) => {
156
+ const combinedOptions : google . maps . InfoWindowOptions = {
157
+ ...options ,
158
+ position : position || options . position ,
159
+ content : this . _elementRef . nativeElement ,
160
+ } ;
161
+ return combinedOptions ;
162
+ } ) ) ;
179
163
}
180
164
181
165
private _initializeEventHandlers ( ) {
0 commit comments