Skip to content

Commit 07169c1

Browse files
committed
feat(google): Expose the underlying Google Maps objects
Fix merge conflicts and update the Circle component with changes.
1 parent 207d4ee commit 07169c1

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Component, ViewChild} from '@angular/core';
22
import {async, TestBed} from '@angular/core/testing';
33
import {By} from '@angular/platform-browser';
44

5-
import {DEFAULT_OPTIONS, UpdatedGoogleMap} from '../google-map/google-map';
5+
import {DEFAULT_OPTIONS} from '../google-map/google-map';
66
import {GoogleMapsModule} from '../google-maps-module';
77
import {
88
createCircleConstructorSpy,
@@ -15,7 +15,7 @@ import {
1515
import {MapCircle} from './map-circle';
1616

1717
describe('MapCircle', () => {
18-
let mapSpy: jasmine.SpyObj<UpdatedGoogleMap>;
18+
let mapSpy: jasmine.SpyObj<google.maps.Map>;
1919
let circleCenter: google.maps.LatLngLiteral;
2020
let circleRadius: number;
2121
let circleOptions: google.maps.CircleOptions;

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

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class MapCircle implements OnInit, OnDestroy {
3737
*
3838
* @see developers.google.com/maps/documentation/javascript/reference/polygon#Circle
3939
*/
40-
circle: google.maps.Circle; // initialized in ngOnInit
40+
circle?: google.maps.Circle; // initialized in ngOnInit
4141

4242
@Input()
4343
set options(options: google.maps.CircleOptions) {
@@ -167,7 +167,8 @@ export class MapCircle implements OnInit, OnDestroy {
167167
this._ngZone.runOutsideAngular(() => {
168168
this.circle = new google.maps.Circle(options);
169169
});
170-
this.circle.setMap(this._map._googleMap);
170+
this._assertInitialized();
171+
this.circle!.setMap(this._map.googleMap!);
171172
this._eventManager.setTarget(this.circle);
172173
});
173174

@@ -181,7 +182,6 @@ export class MapCircle implements OnInit, OnDestroy {
181182
this._eventManager.destroy();
182183
this._destroyed.next();
183184
this._destroyed.complete();
184-
185185
if (this.circle) {
186186
this.circle.setMap(null);
187187
}
@@ -192,47 +192,53 @@ export class MapCircle implements OnInit, OnDestroy {
192192
* developers.google.com/maps/documentation/javascript/reference/polygon#Circle.getBounds
193193
*/
194194
getBounds(): google.maps.LatLngBounds {
195-
return this.circle.getBounds();
195+
this._assertInitialized();
196+
return this.circle!.getBounds();
196197
}
197198

198199
/**
199200
* @see
200201
* developers.google.com/maps/documentation/javascript/reference/polygon#Circle.getCenter
201202
*/
202203
getCenter(): google.maps.LatLng {
203-
return this.circle.getCenter();
204+
this._assertInitialized();
205+
return this.circle!.getCenter();
204206
}
205207

206208
/**
207209
* @see
208210
* developers.google.com/maps/documentation/javascript/reference/polygon#Circle.getDraggable
209211
*/
210212
getDraggable(): boolean {
211-
return this.circle.getDraggable();
213+
this._assertInitialized();
214+
return this.circle!.getDraggable();
212215
}
213216

214217
/**
215218
* @see
216219
* developers.google.com/maps/documentation/javascript/reference/polygon#Circle.getEditable
217220
*/
218221
getEditable(): boolean {
219-
return this.circle.getEditable();
222+
this._assertInitialized();
223+
return this.circle!.getEditable();
220224
}
221225

222226
/**
223227
* @see
224228
* developers.google.com/maps/documentation/javascript/reference/polygon#Circle.getCenter
225229
*/
226230
getRadius(): number {
227-
return this.circle.getRadius();
231+
this._assertInitialized();
232+
return this.circle!.getRadius();
228233
}
229234

230235
/**
231236
* @see
232237
* developers.google.com/maps/documentation/javascript/reference/polygon#Circle.getVisible
233238
*/
234239
getVisible(): boolean {
235-
return this.circle.getVisible();
240+
this._assertInitialized();
241+
return this.circle!.getVisible();
236242
}
237243

238244
private _combineOptions(): Observable<google.maps.CircleOptions> {
@@ -249,23 +255,39 @@ export class MapCircle implements OnInit, OnDestroy {
249255

250256
private _watchForOptionsChanges() {
251257
this._options.pipe(takeUntil(this._destroyed)).subscribe(options => {
252-
this.circle.setOptions(options);
258+
this._assertInitialized();
259+
this.circle!.setOptions(options);
253260
});
254261
}
255262

256263
private _watchForCenterChanges() {
257264
this._center.pipe(takeUntil(this._destroyed)).subscribe(center => {
258265
if (center) {
259-
this.circle.setCenter(center);
266+
this._assertInitialized();
267+
this.circle!.setCenter(center);
260268
}
261269
});
262270
}
263271

264272
private _watchForRadiusChanges() {
265273
this._radius.pipe(takeUntil(this._destroyed)).subscribe(radius => {
266274
if (radius !== undefined) {
267-
this.circle.setRadius(radius);
275+
this._assertInitialized();
276+
this.circle!.setRadius(radius);
268277
}
269278
});
270279
}
280+
281+
private _assertInitialized() {
282+
if (!this._map.googleMap) {
283+
throw Error(
284+
'Cannot access Google Map information before the API has been initialized. ' +
285+
'Please wait for the API to load before trying to interact with it.');
286+
}
287+
if (!this.circle) {
288+
throw Error(
289+
'Cannot interact with a Google Map Circle before it has been ' +
290+
'initialized. Please wait for the Circle to load before trying to interact with it.');
291+
}
292+
}
271293
}

0 commit comments

Comments
 (0)