-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
map-base-layer.ts
53 lines (45 loc) · 1.28 KB
/
map-base-layer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
// Workaround for: https://github.com/bazelbuild/rules_nodejs/issues/1265
/// <reference types="google.maps" preserve="true" />
import {Directive, NgZone, OnDestroy, OnInit} from '@angular/core';
import {GoogleMap} from './google-map/google-map';
@Directive({
selector: 'map-base-layer',
exportAs: 'mapBaseLayer',
standalone: true,
})
export class MapBaseLayer implements OnInit, OnDestroy {
constructor(
protected readonly _map: GoogleMap,
protected readonly _ngZone: NgZone,
) {}
ngOnInit() {
if (this._map._isBrowser) {
this._ngZone.runOutsideAngular(() => {
this._initializeObject();
});
this._assertInitialized();
this._setMap();
}
}
ngOnDestroy() {
this._unsetMap();
}
private _assertInitialized() {
if (!this._map.googleMap) {
throw Error(
'Cannot access Google Map information before the API has been initialized. ' +
'Please wait for the API to load before trying to interact with it.',
);
}
}
protected _initializeObject() {}
protected _setMap() {}
protected _unsetMap() {}
}