Skip to content

refactor(google-maps): convert to standalone #28153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/dev-app/google-map/google-map-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@
import {CommonModule} from '@angular/common';
import {Component, ViewChild} from '@angular/core';
import {
GoogleMapsModule,
GoogleMap,
MapBicyclingLayer,
MapCircle,
MapDirectionsRenderer,
MapDirectionsService,
MapGroundOverlay,
MapHeatmapLayer,
MapInfoWindow,
MapKmlLayer,
MapMarker,
MapMarkerClusterer,
MapPolygon,
MapPolyline,
MapRectangle,
MapTrafficLayer,
MapTransitLayer,
} from '@angular/google-maps';

const POLYLINE_PATH: google.maps.LatLngLiteral[] = [
Expand Down Expand Up @@ -52,7 +60,24 @@ let apiLoadingPromise: Promise<unknown> | null = null;
templateUrl: 'google-map-demo.html',
styleUrls: ['google-map-demo.css'],
standalone: true,
imports: [CommonModule, GoogleMapsModule],
imports: [
CommonModule,
GoogleMap,
MapBicyclingLayer,
MapCircle,
MapDirectionsRenderer,
MapGroundOverlay,
MapHeatmapLayer,
MapInfoWindow,
MapKmlLayer,
MapMarker,
MapMarkerClusterer,
MapPolygon,
MapPolyline,
MapRectangle,
MapTrafficLayer,
MapTransitLayer,
],
})
export class GoogleMapDemo {
@ViewChild(MapInfoWindow) infoWindow: MapInfoWindow;
Expand Down
4 changes: 2 additions & 2 deletions src/google-maps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ method to make sure that the component doesn't load until after the API has load
// google-maps-demo.module.ts

import { NgModule } from '@angular/core';
import { GoogleMapsModule } from '@angular/google-maps';
import { GoogleMap } from '@angular/google-maps';
import { CommonModule } from '@angular/common';
import { HttpClientModule, HttpClientJsonpModule } from '@angular/common/http';

Expand All @@ -33,7 +33,7 @@ import { GoogleMapsDemoComponent } from './google-maps-demo.component';
],
imports: [
CommonModule,
GoogleMapsModule,
GoogleMap,
HttpClientModule,
HttpClientJsonpModule,
],
Expand Down
6 changes: 2 additions & 4 deletions src/google-maps/google-map/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ The `GoogleMap` component wraps the [`google.maps.Map` class](https://developers
// google-maps-demo.module.ts

import {NgModule} from '@angular/core';
import {GoogleMapsModule} from '@angular/google-maps';
import {GoogleMap} from '@angular/google-maps';

import {GoogleMapDemo} from './google-map-demo';

@NgModule({
imports: [
GoogleMapsModule,
],
imports: [GoogleMap],
declarations: [GoogleMapDemo],
})
export class GoogleMapDemoModule {
Expand Down
3 changes: 1 addition & 2 deletions src/google-maps/google-map/google-map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {Component, ViewChild} from '@angular/core';
import {waitForAsync, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';

import {GoogleMapsModule} from '../google-maps-module';
import {createMapConstructorSpy, createMapSpy} from '../testing/fake-google-map-utils';
import {DEFAULT_HEIGHT, DEFAULT_OPTIONS, DEFAULT_WIDTH, GoogleMap} from './google-map';

Expand All @@ -26,7 +25,7 @@ describe('GoogleMap', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [GoogleMapsModule],
imports: [GoogleMap],
declarations: [TestApp],
});
}));
Expand Down
1 change: 1 addition & 0 deletions src/google-maps/google-map/google-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const DEFAULT_WIDTH = '500px';
@Component({
selector: 'google-map',
exportAs: 'googleMap',
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<div class="map-container"></div><ng-content></ng-content>',
encapsulation: ViewEncapsulation.None,
Expand Down
4 changes: 2 additions & 2 deletions src/google-maps/google-maps-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const COMPONENTS = [
MapCircle,
MapDirectionsRenderer,
MapGroundOverlay,
MapHeatmapLayer,
MapInfoWindow,
MapKmlLayer,
MapMarker,
Expand All @@ -41,11 +42,10 @@ const COMPONENTS = [
MapRectangle,
MapTrafficLayer,
MapTransitLayer,
MapHeatmapLayer,
];

@NgModule({
declarations: COMPONENTS,
imports: COMPONENTS,
exports: COMPONENTS,
})
export class GoogleMapsModule {}
6 changes: 5 additions & 1 deletion src/google-maps/map-base-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ 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) {}
constructor(
protected readonly _map: GoogleMap,
protected readonly _ngZone: NgZone,
) {}

ngOnInit() {
if (this._map._isBrowser) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import {Component} from '@angular/core';
import {waitForAsync, TestBed} from '@angular/core/testing';

import {DEFAULT_OPTIONS} from '../google-map/google-map';
import {GoogleMapsModule} from '../google-maps-module';
import {DEFAULT_OPTIONS, GoogleMap} from '../google-map/google-map';
import {
createBicyclingLayerConstructorSpy,
createBicyclingLayerSpy,
createMapConstructorSpy,
createMapSpy,
} from '../testing/fake-google-map-utils';

import {MapBicyclingLayer} from './map-bicycling-layer';

describe('MapBicyclingLayer', () => {
let mapSpy: jasmine.SpyObj<google.maps.Map>;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [GoogleMapsModule],
imports: [GoogleMap, MapBicyclingLayer],
declarations: [TestApp],
});
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {MapBaseLayer} from '../map-base-layer';
@Directive({
selector: 'map-bicycling-layer',
exportAs: 'mapBicyclingLayer',
standalone: true,
})
export class MapBicyclingLayer extends MapBaseLayer {
/**
Expand Down
5 changes: 2 additions & 3 deletions src/google-maps/map-circle/map-circle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import {Component, ViewChild} from '@angular/core';
import {waitForAsync, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';

import {DEFAULT_OPTIONS} from '../google-map/google-map';
import {GoogleMapsModule} from '../google-maps-module';
import {DEFAULT_OPTIONS, GoogleMap} from '../google-map/google-map';
import {
createCircleConstructorSpy,
createCircleSpy,
Expand All @@ -29,7 +28,7 @@ describe('MapCircle', () => {
strokeOpacity: 0.8,
};
TestBed.configureTestingModule({
imports: [GoogleMapsModule],
imports: [GoogleMap, MapCircle],
declarations: [TestApp],
});
}));
Expand Down
6 changes: 5 additions & 1 deletion src/google-maps/map-circle/map-circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {MapEventManager} from '../map-event-manager';
@Directive({
selector: 'map-circle',
exportAs: 'mapCircle',
standalone: true,
})
export class MapCircle implements OnInit, OnDestroy {
private _eventManager = new MapEventManager(inject(NgZone));
Expand Down Expand Up @@ -147,7 +148,10 @@ export class MapCircle implements OnInit, OnDestroy {
@Output() readonly circleRightclick: Observable<google.maps.MapMouseEvent> =
this._eventManager.getLazyEmitter<google.maps.MapMouseEvent>('rightclick');

constructor(private readonly _map: GoogleMap, private readonly _ngZone: NgZone) {}
constructor(
private readonly _map: GoogleMap,
private readonly _ngZone: NgZone,
) {}

ngOnInit() {
if (this._map._isBrowser) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import {Component, ViewChild} from '@angular/core';
import {TestBed, waitForAsync} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {MapDirectionsRenderer} from './map-directions-renderer';
import {DEFAULT_OPTIONS} from '../google-map/google-map';
import {GoogleMapsModule} from '../google-maps-module';
import {DEFAULT_OPTIONS, GoogleMap} from '../google-map/google-map';
import {
createDirectionsRendererConstructorSpy,
createDirectionsRendererSpy,
Expand All @@ -21,7 +20,7 @@ describe('MapDirectionsRenderer', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [GoogleMapsModule],
imports: [GoogleMap, MapDirectionsRenderer],
declarations: [TestApp],
});
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {MapEventManager} from '../map-event-manager';
@Directive({
selector: 'map-directions-renderer',
exportAs: 'mapDirectionsRenderer',
standalone: true,
})
export class MapDirectionsRenderer implements OnInit, OnChanges, OnDestroy {
private _eventManager = new MapEventManager(inject(NgZone));
Expand Down Expand Up @@ -68,7 +69,10 @@ export class MapDirectionsRenderer implements OnInit, OnChanges, OnDestroy {
/** The underlying google.maps.DirectionsRenderer object. */
directionsRenderer?: google.maps.DirectionsRenderer;

constructor(private readonly _googleMap: GoogleMap, private _ngZone: NgZone) {}
constructor(
private readonly _googleMap: GoogleMap,
private _ngZone: NgZone,
) {}

ngOnInit() {
if (this._googleMap._isBrowser) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {TestBed} from '@angular/core/testing';
import {MapDirectionsResponse, MapDirectionsService} from './map-directions-service';
import {GoogleMapsModule} from '../google-maps-module';
import {
createDirectionsServiceConstructorSpy,
createDirectionsServiceSpy,
Expand All @@ -12,10 +11,6 @@ describe('MapDirectionsService', () => {
let directionsServiceSpy: jasmine.SpyObj<google.maps.DirectionsService>;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [GoogleMapsModule],
});

directionsServiceSpy = createDirectionsServiceSpy();
directionsServiceConstructorSpy =
createDirectionsServiceConstructorSpy(directionsServiceSpy).and.callThrough();
Expand Down
5 changes: 0 additions & 5 deletions src/google-maps/map-geocoder/map-geocoder.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {TestBed} from '@angular/core/testing';
import {MapGeocoderResponse, MapGeocoder} from './map-geocoder';
import {GoogleMapsModule} from '../google-maps-module';
import {createGeocoderConstructorSpy, createGeocoderSpy} from '../testing/fake-google-map-utils';

describe('MapGeocoder', () => {
Expand All @@ -9,10 +8,6 @@ describe('MapGeocoder', () => {
let geocoderSpy: jasmine.SpyObj<google.maps.Geocoder>;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [GoogleMapsModule],
});

geocoderSpy = createGeocoderSpy();
geocoderConstructorSpy = createGeocoderConstructorSpy(geocoderSpy).and.callThrough();
geocoder = TestBed.inject(MapGeocoder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import {Component, ViewChild} from '@angular/core';
import {waitForAsync, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';

import {DEFAULT_OPTIONS} from '../google-map/google-map';
import {GoogleMapsModule} from '../google-maps-module';
import {DEFAULT_OPTIONS, GoogleMap} from '../google-map/google-map';
import {
createGroundOverlayConstructorSpy,
createGroundOverlaySpy,
Expand All @@ -23,7 +22,7 @@ describe('MapGroundOverlay', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [GoogleMapsModule],
imports: [GoogleMap, MapGroundOverlay],
declarations: [TestApp],
});
}));
Expand Down
6 changes: 5 additions & 1 deletion src/google-maps/map-ground-overlay/map-ground-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {MapEventManager} from '../map-event-manager';
@Directive({
selector: 'map-ground-overlay',
exportAs: 'mapGroundOverlay',
standalone: true,
})
export class MapGroundOverlay implements OnInit, OnDestroy {
private _eventManager = new MapEventManager(inject(NgZone));
Expand Down Expand Up @@ -81,7 +82,10 @@ export class MapGroundOverlay implements OnInit, OnDestroy {
@Output() readonly mapDblclick: Observable<google.maps.MapMouseEvent> =
this._eventManager.getLazyEmitter<google.maps.MapMouseEvent>('dblclick');

constructor(private readonly _map: GoogleMap, private readonly _ngZone: NgZone) {}
constructor(
private readonly _map: GoogleMap,
private readonly _ngZone: NgZone,
) {}

ngOnInit() {
if (this._map._isBrowser) {
Expand Down
5 changes: 2 additions & 3 deletions src/google-maps/map-heatmap-layer/map-heatmap-layer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {Component, ViewChild} from '@angular/core';
import {waitForAsync, TestBed} from '@angular/core/testing';

import {DEFAULT_OPTIONS} from '../google-map/google-map';
import {DEFAULT_OPTIONS, GoogleMap} from '../google-map/google-map';

import {GoogleMapsModule} from '../google-maps-module';
import {
createMapConstructorSpy,
createMapSpy,
Expand All @@ -20,7 +19,7 @@ describe('MapHeatmapLayer', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [GoogleMapsModule],
imports: [GoogleMap, MapHeatmapLayer],
declarations: [TestApp],
});
}));
Expand Down
6 changes: 5 additions & 1 deletion src/google-maps/map-heatmap-layer/map-heatmap-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type HeatmapData =
@Directive({
selector: 'map-heatmap-layer',
exportAs: 'mapHeatmapLayer',
standalone: true,
})
export class MapHeatmapLayer implements OnInit, OnChanges, OnDestroy {
/**
Expand Down Expand Up @@ -57,7 +58,10 @@ export class MapHeatmapLayer implements OnInit, OnChanges, OnDestroy {
*/
heatmap?: google.maps.visualization.HeatmapLayer;

constructor(private readonly _googleMap: GoogleMap, private _ngZone: NgZone) {}
constructor(
private readonly _googleMap: GoogleMap,
private _ngZone: NgZone,
) {}

ngOnInit() {
if (this._googleMap._isBrowser) {
Expand Down
5 changes: 2 additions & 3 deletions src/google-maps/map-info-window/map-info-window.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import {Component, ViewChild} from '@angular/core';
import {waitForAsync, TestBed} from '@angular/core/testing';
import {By} from '@angular/platform-browser';

import {DEFAULT_OPTIONS} from '../google-map/google-map';
import {DEFAULT_OPTIONS, GoogleMap} from '../google-map/google-map';

import {GoogleMapsModule} from '../google-maps-module';
import {MapMarker} from '../map-marker/map-marker';
import {
createInfoWindowConstructorSpy,
Expand All @@ -19,7 +18,7 @@ describe('MapInfoWindow', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [GoogleMapsModule],
imports: [GoogleMap, MapInfoWindow],
declarations: [TestApp],
});
}));
Expand Down
Loading