Skip to content

Commit 3488a67

Browse files
committed
feat(google-maps): Add MapPolyline component
Change component to a directive.
1 parent 3774940 commit 3488a67

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

src/google-maps/map-polyline/map-polyline.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('MapPolyline', () => {
8888

8989
const fixture = TestBed.createComponent(TestApp);
9090
const polylineComponent =
91-
fixture.debugElement.query(By.directive(MapPolyline)).componentInstance;
91+
fixture.debugElement.query(By.directive(MapPolyline))!.injector.get<MapPolyline>(MapPolyline);
9292
fixture.detectChanges();
9393

9494
polylineSpy.getDraggable.and.returnValue(true);

src/google-maps/map-polyline/map-polyline.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010
/// <reference types="googlemaps" />
1111

1212
import {
13-
ChangeDetectionStrategy,
14-
Component,
13+
Directive,
1514
EventEmitter,
1615
Input,
1716
OnDestroy,
1817
OnInit,
1918
Output,
20-
ViewEncapsulation
2119
} from '@angular/core';
2220
import {BehaviorSubject, combineLatest, Observable, Subject} from 'rxjs';
2321
import {map, take, takeUntil} from 'rxjs/operators';
@@ -28,12 +26,8 @@ import {GoogleMap} from '../google-map/google-map';
2826
* Angular component that renders a Google Maps Polyline via the Google Maps JavaScript API.
2927
* @see developers.google.com/maps/documentation/javascript/reference/polygon#Polyline
3028
*/
31-
@Component({
32-
moduleId: module.id,
29+
@Directive({
3330
selector: 'map-polyline',
34-
template: '<ng-content></ng-content>',
35-
changeDetection: ChangeDetectionStrategy.OnPush,
36-
encapsulation: ViewEncapsulation.None,
3731
})
3832
export class MapPolyline implements OnInit, OnDestroy {
3933
@Input()
@@ -107,7 +101,7 @@ export class MapPolyline implements OnInit, OnDestroy {
107101
new BehaviorSubject<google.maps.MVCArray<google.maps.LatLng>|google.maps.LatLng[]|
108102
google.maps.LatLngLiteral[]|undefined>(undefined);
109103

110-
private readonly _destroy = new Subject<void>();
104+
private readonly _destroyed = new Subject<void>();
111105

112106
private readonly _listeners: google.maps.MapsEventListener[] = [];
113107

@@ -129,8 +123,8 @@ export class MapPolyline implements OnInit, OnDestroy {
129123
}
130124

131125
ngOnDestroy() {
132-
this._destroy.next();
133-
this._destroy.complete();
126+
this._destroyed.next();
127+
this._destroyed.complete();
134128
for (let listener of this._listeners) {
135129
listener.remove();
136130
}
@@ -177,13 +171,13 @@ export class MapPolyline implements OnInit, OnDestroy {
177171
}
178172

179173
private _watchForOptionsChanges() {
180-
this._options.pipe(takeUntil(this._destroy)).subscribe(options => {
174+
this._options.pipe(takeUntil(this._destroyed)).subscribe(options => {
181175
this._polyline.setOptions(options);
182176
});
183177
}
184178

185179
private _watchForPathChanges() {
186-
this._path.pipe(takeUntil(this._destroy)).subscribe(path => {
180+
this._path.pipe(takeUntil(this._destroyed)).subscribe(path => {
187181
if (path) {
188182
this._polyline.setPath(path);
189183
}

0 commit comments

Comments
 (0)