Skip to content

Commit 6416bab

Browse files
mbehrlichjelbourn
authored andcommitted
feat(google-maps): add google-map component skeleton (#16623)
1 parent 917871b commit 6416bab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+515
-5
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
/src/material/core/util/** @jelbourn
5959

6060
# Miscellaneous components
61+
/src/google-maps/** @mbehrlich
6162
/src/youtube-player/** @nathantate
6263

6364
# CDK
@@ -141,6 +142,7 @@
141142
/src/dev-app/expansion/** @josephperrott
142143
/src/dev-app/focus-origin/** @mmalerba
143144
/src/dev-app/gestures/** @jelbourn
145+
/src/dev-app/google-map/** @mbehrlich
144146
/src/dev-app/grid-list/** @jelbourn
145147
/src/dev-app/icon/** @jelbourn
146148
/src/dev-app/input/** @mmalerba

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@angular/elements": "^8.1.0",
4747
"@angular/forms": "^8.1.0",
4848
"@angular/platform-browser": "^8.1.0",
49+
"@types/googlemaps": "^3.37.0",
4950
"@types/youtube": "^0.0.38",
5051
"@webcomponents/custom-elements": "^1.1.0",
5152
"core-js": "^2.6.1",

packages.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ MATERIAL_SCSS_LIBS = [
8080
for p in MATERIAL_PACKAGES
8181
]
8282

83+
GOOGLE_MAPS_PACKAGES = [
84+
"google-map",
85+
]
86+
87+
GOOGLE_MAPS_TARGETS = ["//src/google-maps"] + ["//src/google-maps/%s" % p for p in GOOGLE_MAPS_PACKAGES]
88+
8389
MATERIAL_EXPERIMENTAL_PACKAGES = [
8490
"mdc-button",
8591
"mdc-card",
@@ -122,6 +128,7 @@ ROLLUP_GLOBALS = {
122128
"@angular/material": "ng.material",
123129
"@angular/material-experimental": "ng.materialExperimental",
124130
"@angular/youtube-player": "ng.youtubePlayer",
131+
"@angular/google-maps": "ng.googleMaps",
125132
}
126133

127134
# Rollup globals for cdk subpackages in the form of, e.g., {"@angular/cdk/table": "ng.cdk.table"}

src/dev-app/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package(default_visibility = ["//visibility:public"])
22

33
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
4-
load("//:packages.bzl", "CDK_EXPERIMENTAL_TARGETS", "CDK_TARGETS", "MATERIAL_EXPERIMENTAL_SCSS_LIBS", "MATERIAL_EXPERIMENTAL_TARGETS", "MATERIAL_TARGETS")
4+
load("//:packages.bzl", "CDK_EXPERIMENTAL_TARGETS", "CDK_TARGETS", "GOOGLE_MAPS_TARGETS", "MATERIAL_EXPERIMENTAL_SCSS_LIBS", "MATERIAL_EXPERIMENTAL_TARGETS", "MATERIAL_TARGETS")
55
load("//tools:defaults.bzl", "ng_module")
66
load("//tools:sass_generate_binaries.bzl", "sass_generate_binaries")
77

@@ -50,7 +50,7 @@ ng_module(
5050
"//src/material-experimental/mdc-slide-toggle",
5151
"//src/material-experimental/mdc-tabs",
5252
"//src/material-examples:examples",
53-
] + CDK_TARGETS + CDK_EXPERIMENTAL_TARGETS + MATERIAL_TARGETS + MATERIAL_EXPERIMENTAL_TARGETS,
53+
] + CDK_TARGETS + CDK_EXPERIMENTAL_TARGETS + MATERIAL_TARGETS + MATERIAL_EXPERIMENTAL_TARGETS + GOOGLE_MAPS_TARGETS,
5454
)
5555

5656
sass_binary(

src/dev-app/dev-app/dev-app-layout.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class DevAppLayout {
4141
{name: 'Expansion Panel', route: '/expansion'},
4242
{name: 'Focus Origin', route: '/focus-origin'},
4343
{name: 'Gestures', route: '/gestures'},
44+
{name: 'Google Map', route: '/google-map'},
4445
{name: 'Grid List', route: '/grid-list'},
4546
{name: 'Icon', route: '/icon'},
4647
{name: 'Input', route: '/input'},

src/dev-app/dev-app/routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const DEV_APP_ROUTES: Routes = [
4040
loadChildren: 'focus-origin/focus-origin-demo-module#FocusOriginDemoModule'
4141
},
4242
{path: 'gestures', loadChildren: 'gestures/gestures-demo-module#GesturesDemoModule'},
43+
{path: 'google-map', loadChildren: 'google-map/google-map-demo-module#GoogleMapDemoModule'},
4344
{path: 'grid-list', loadChildren: 'grid-list/grid-list-demo-module#GridListDemoModule'},
4445
{path: 'icon', loadChildren: 'icon/icon-demo-module#IconDemoModule'},
4546
{path: 'input', loadChildren: 'input/input-demo-module#InputDemoModule'},
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {CommonModule} from '@angular/common';
10+
import {HttpClientJsonpModule, HttpClientModule} from '@angular/common/http';
11+
import {NgModule} from '@angular/core';
12+
import {GoogleMapModule} from '@angular/google-maps/google-map';
13+
import {RouterModule} from '@angular/router';
14+
15+
import {GoogleMapDemo} from './google-map-demo';
16+
17+
@NgModule({
18+
imports: [
19+
CommonModule,
20+
GoogleMapModule,
21+
HttpClientJsonpModule,
22+
HttpClientModule,
23+
RouterModule.forChild([{path: '', component: GoogleMapDemo}]),
24+
],
25+
declarations: [GoogleMapDemo],
26+
})
27+
export class GoogleMapDemoModule {
28+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<google-map *ngIf="isReady"></google-map>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Component} from '@angular/core';
10+
import {HttpClient} from '@angular/common/http';
11+
12+
/** Demo Component for @angular/google-maps/map */
13+
@Component({
14+
moduleId: module.id,
15+
selector: 'google-map-demo',
16+
templateUrl: 'google-map-demo.html',
17+
})
18+
export class GoogleMapDemo {
19+
isReady = false;
20+
21+
constructor(httpClient: HttpClient) {
22+
httpClient.jsonp('https://maps.googleapis.com/maps/api/js?', 'callback')
23+
.subscribe(() => {
24+
this.isReady = true;
25+
});
26+
}
27+
}

src/dev-app/system-config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ System.config({
153153
'dist/packages/material-experimental/mdc-helpers/index.js',
154154
'@angular/material-experimental/popover-edit':
155155
'dist/packages/material-experimental/popover-edit/index.js',
156+
157+
'@angular/google-maps/google-map':
158+
'dist/packages/google-maps/google-map/index.js',
156159
},
157160
packages: {
158161
// Set the default extension for the root package, because otherwise the dev-app can't

src/dev-app/tsconfig-aot.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@angular/cdk-experimental/*": ["../../dist/releases/cdk-experimental/*"],
2929
"@angular/cdk-experimental": ["../../dist/releases/cdk-experimental"],
3030
"@angular/material-moment-adapter": ["../../dist/releases/material-moment-adapter"],
31+
"@angular/google-maps/*": ["../../dist/releases/google-maps/*"],
3132
"@angular/material-examples": ["../../dist/releases/material-examples"]
3233
}
3334
},

src/dev-app/tsconfig-build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@angular/cdk-experimental/*": ["../../dist/packages/cdk-experimental/*"],
3636
"@angular/cdk-experimental": ["../../dist/packages/cdk-experimental"],
3737
"@angular/material-moment-adapter": ["../../dist/packages/material-moment-adapter"],
38+
"@angular/google-maps/*": ["../../dist/packages/google-maps/*"],
3839
"@angular/material-examples": ["../../dist/packages/material-examples"]
3940
}
4041
},

src/dev-app/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@angular/cdk-experimental/*": ["../cdk-experimental/*"],
1515
"@angular/cdk-experimental": ["../cdk-experimental"],
1616
"@angular/material-moment-adapter": ["../material-moment-adapter/public-api.ts"],
17+
"@angular/google-maps/*": ["../google-maps/*"],
1718
"@angular/material-examples": ["../../dist/packages/material-examples"]
1819
}
1920
},

src/google-maps/BUILD.bazel

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//:packages.bzl", "GOOGLE_MAPS_PACKAGES", "GOOGLE_MAPS_TARGETS", "ROLLUP_GLOBALS")
4+
load("//tools:defaults.bzl", "ng_module", "ng_package")
5+
6+
# Root "@angular/google-maps" entry-point that does not re-export individual entry-points.
7+
ng_module(
8+
name = "google-maps",
9+
srcs = glob(
10+
["*.ts"],
11+
exclude = ["**/*.spec.ts"],
12+
),
13+
module_name = "@angular/google-maps",
14+
deps = ["//src/google-maps/%s" % p for p in GOOGLE_MAPS_PACKAGES] + [
15+
"@npm//@angular/core",
16+
"@npm//@types/googlemaps",
17+
],
18+
)
19+
20+
filegroup(
21+
name = "overviews",
22+
srcs = ["//src/google-maps/%s:overview" % name for name in GOOGLE_MAPS_PACKAGES],
23+
)
24+
25+
# Creates the @angular/google-maps package published to npm
26+
ng_package(
27+
name = "npm_package",
28+
srcs = ["package.json"],
29+
entry_point = ":public-api.ts",
30+
entry_point_name = "google-maps",
31+
globals = ROLLUP_GLOBALS,
32+
deps = GOOGLE_MAPS_TARGETS,
33+
)

src/google-maps/README.md

Whitespace-only changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load(
4+
"//tools:defaults.bzl",
5+
"markdown_to_html",
6+
"ng_module",
7+
"ng_test_library",
8+
"ng_web_test_suite",
9+
)
10+
11+
ng_module(
12+
name = "google-map",
13+
srcs = glob(
14+
["**/*.ts"],
15+
exclude = ["**/*.spec.ts"],
16+
),
17+
module_name = "@angular/google-maps/google-map",
18+
deps = [
19+
"@npm//@angular/core",
20+
"@npm//@types/googlemaps",
21+
"@npm//rxjs",
22+
],
23+
)
24+
25+
ng_test_library(
26+
name = "unit_test_sources",
27+
srcs = glob(
28+
["**/*.spec.ts"],
29+
exclude = ["**/*.e2e.spec.ts"],
30+
),
31+
deps = [
32+
":google-map",
33+
"//src/google-maps/google-map/testing",
34+
"@npm//@angular/platform-browser",
35+
],
36+
)
37+
38+
ng_web_test_suite(
39+
name = "unit_tests",
40+
deps = [":unit_test_sources"],
41+
)
42+
43+
markdown_to_html(
44+
name = "overview",
45+
srcs = [":google-map.md"],
46+
)
47+
48+
filegroup(
49+
name = "source-files",
50+
srcs = glob(["**/*.ts"]),
51+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {NgModule} from '@angular/core';
10+
import {GoogleMap} from './google-map';
11+
12+
@NgModule({
13+
exports: [GoogleMap],
14+
declarations: [GoogleMap],
15+
})
16+
export class GoogleMapModule {}

src/google-maps/google-map/google-map.md

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {Component} from '@angular/core';
2+
import {async, TestBed} from '@angular/core/testing';
3+
import {By} from '@angular/platform-browser';
4+
5+
import {createMapConstructorSpy, createMapSpy} from './testing/fake-google-map-utils';
6+
import {GoogleMapModule} from './index';
7+
8+
const DEFAULT_OPTIONS: google.maps.MapOptions = {
9+
center: {lat: 37.421995, lng: -122.084092},
10+
zoom: 17,
11+
};
12+
13+
describe('GoogleMap', () => {
14+
let mapConstructorSpy: jasmine.Spy;
15+
let mapSpy: jasmine.SpyObj<google.maps.Map>;
16+
17+
beforeEach(async(() => {
18+
mapSpy = createMapSpy(DEFAULT_OPTIONS);
19+
mapConstructorSpy = createMapConstructorSpy(mapSpy);
20+
21+
TestBed.configureTestingModule({
22+
imports: [GoogleMapModule],
23+
declarations: [TestApp],
24+
});
25+
}));
26+
27+
beforeEach(() => {
28+
TestBed.compileComponents();
29+
});
30+
31+
it('initializes a Google map', () => {
32+
const fixture = TestBed.createComponent(TestApp);
33+
const container = fixture.debugElement.query(By.css('div'));
34+
fixture.detectChanges();
35+
36+
expect(mapConstructorSpy).toHaveBeenCalledWith(container.nativeElement, DEFAULT_OPTIONS);
37+
});
38+
});
39+
40+
@Component({
41+
selector: 'test-app',
42+
template: `<google-map></google-map>`,
43+
})
44+
class TestApp {}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {
2+
ChangeDetectionStrategy,
3+
Component,
4+
ElementRef,
5+
Input,
6+
OnInit,
7+
} from '@angular/core';
8+
import {ReplaySubject} from 'rxjs';
9+
10+
/**
11+
* Angular component that renders a Google Map via the Google Maps JavaScript
12+
* API.
13+
* @see https://developers.google.com/maps/documentation/javascript/reference/
14+
*/
15+
@Component({
16+
selector: 'google-map',
17+
changeDetection: ChangeDetectionStrategy.OnPush,
18+
template: '<div class="map-container"></div>',
19+
})
20+
export class GoogleMap implements OnInit {
21+
// Arbitrarily chosen default size
22+
@Input() height = '500px';
23+
@Input() width = '500px';
24+
25+
// TODO(mbehrlich): add options, handlers, properties, and methods.
26+
27+
private readonly _map$ = new ReplaySubject<google.maps.Map>(1);
28+
29+
constructor(private readonly _elementRef: ElementRef) {}
30+
31+
ngOnInit() {
32+
// default options set to the Googleplex
33+
const options: google.maps.MapOptions = {
34+
center: {lat: 37.421995, lng: -122.084092},
35+
zoom: 17,
36+
};
37+
38+
const mapEl = this._elementRef.nativeElement.querySelector('.map-container');
39+
mapEl.style.height = this.height;
40+
mapEl.style.width = this.width;
41+
const map = new google.maps.Map(mapEl, options);
42+
this._map$.next(map);
43+
}
44+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
export * from './public-api';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
export * from './google-map-module';
10+
export * from './google-map';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//tools:defaults.bzl", "ts_library")
4+
5+
ts_library(
6+
name = "testing",
7+
testonly = 1,
8+
srcs = glob(["**/*.ts"]),
9+
deps = [
10+
"@npm//@types/googlemaps",
11+
"@npm//@types/jasmine",
12+
],
13+
)

0 commit comments

Comments
 (0)