-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(google-maps): add google-map component skeleton (#16623)
- Loading branch information
Showing
42 changed files
with
515 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @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 | ||
*/ | ||
|
||
import {CommonModule} from '@angular/common'; | ||
import {HttpClientJsonpModule, HttpClientModule} from '@angular/common/http'; | ||
import {NgModule} from '@angular/core'; | ||
import {GoogleMapModule} from '@angular/google-maps/google-map'; | ||
import {RouterModule} from '@angular/router'; | ||
|
||
import {GoogleMapDemo} from './google-map-demo'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
GoogleMapModule, | ||
HttpClientJsonpModule, | ||
HttpClientModule, | ||
RouterModule.forChild([{path: '', component: GoogleMapDemo}]), | ||
], | ||
declarations: [GoogleMapDemo], | ||
}) | ||
export class GoogleMapDemoModule { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<google-map *ngIf="isReady"></google-map> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @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 | ||
*/ | ||
|
||
import {Component} from '@angular/core'; | ||
import {HttpClient} from '@angular/common/http'; | ||
|
||
/** Demo Component for @angular/google-maps/map */ | ||
@Component({ | ||
moduleId: module.id, | ||
selector: 'google-map-demo', | ||
templateUrl: 'google-map-demo.html', | ||
}) | ||
export class GoogleMapDemo { | ||
isReady = false; | ||
|
||
constructor(httpClient: HttpClient) { | ||
httpClient.jsonp('https://maps.googleapis.com/maps/api/js?', 'callback') | ||
.subscribe(() => { | ||
this.isReady = true; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("//:packages.bzl", "GOOGLE_MAPS_PACKAGES", "GOOGLE_MAPS_TARGETS", "ROLLUP_GLOBALS") | ||
load("//tools:defaults.bzl", "ng_module", "ng_package") | ||
|
||
# Root "@angular/google-maps" entry-point that does not re-export individual entry-points. | ||
ng_module( | ||
name = "google-maps", | ||
srcs = glob( | ||
["*.ts"], | ||
exclude = ["**/*.spec.ts"], | ||
), | ||
module_name = "@angular/google-maps", | ||
deps = ["//src/google-maps/%s" % p for p in GOOGLE_MAPS_PACKAGES] + [ | ||
"@npm//@angular/core", | ||
"@npm//@types/googlemaps", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "overviews", | ||
srcs = ["//src/google-maps/%s:overview" % name for name in GOOGLE_MAPS_PACKAGES], | ||
) | ||
|
||
# Creates the @angular/google-maps package published to npm | ||
ng_package( | ||
name = "npm_package", | ||
srcs = ["package.json"], | ||
entry_point = ":public-api.ts", | ||
entry_point_name = "google-maps", | ||
globals = ROLLUP_GLOBALS, | ||
deps = GOOGLE_MAPS_TARGETS, | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load( | ||
"//tools:defaults.bzl", | ||
"markdown_to_html", | ||
"ng_module", | ||
"ng_test_library", | ||
"ng_web_test_suite", | ||
) | ||
|
||
ng_module( | ||
name = "google-map", | ||
srcs = glob( | ||
["**/*.ts"], | ||
exclude = ["**/*.spec.ts"], | ||
), | ||
module_name = "@angular/google-maps/google-map", | ||
deps = [ | ||
"@npm//@angular/core", | ||
"@npm//@types/googlemaps", | ||
"@npm//rxjs", | ||
], | ||
) | ||
|
||
ng_test_library( | ||
name = "unit_test_sources", | ||
srcs = glob( | ||
["**/*.spec.ts"], | ||
exclude = ["**/*.e2e.spec.ts"], | ||
), | ||
deps = [ | ||
":google-map", | ||
"//src/google-maps/google-map/testing", | ||
"@npm//@angular/platform-browser", | ||
], | ||
) | ||
|
||
ng_web_test_suite( | ||
name = "unit_tests", | ||
deps = [":unit_test_sources"], | ||
) | ||
|
||
markdown_to_html( | ||
name = "overview", | ||
srcs = [":google-map.md"], | ||
) | ||
|
||
filegroup( | ||
name = "source-files", | ||
srcs = glob(["**/*.ts"]), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @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 | ||
*/ | ||
|
||
import {NgModule} from '@angular/core'; | ||
import {GoogleMap} from './google-map'; | ||
|
||
@NgModule({ | ||
exports: [GoogleMap], | ||
declarations: [GoogleMap], | ||
}) | ||
export class GoogleMapModule {} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {Component} from '@angular/core'; | ||
import {async, TestBed} from '@angular/core/testing'; | ||
import {By} from '@angular/platform-browser'; | ||
|
||
import {createMapConstructorSpy, createMapSpy} from './testing/fake-google-map-utils'; | ||
import {GoogleMapModule} from './index'; | ||
|
||
const DEFAULT_OPTIONS: google.maps.MapOptions = { | ||
center: {lat: 37.421995, lng: -122.084092}, | ||
zoom: 17, | ||
}; | ||
|
||
describe('GoogleMap', () => { | ||
let mapConstructorSpy: jasmine.Spy; | ||
let mapSpy: jasmine.SpyObj<google.maps.Map>; | ||
|
||
beforeEach(async(() => { | ||
mapSpy = createMapSpy(DEFAULT_OPTIONS); | ||
mapConstructorSpy = createMapConstructorSpy(mapSpy); | ||
|
||
TestBed.configureTestingModule({ | ||
imports: [GoogleMapModule], | ||
declarations: [TestApp], | ||
}); | ||
})); | ||
|
||
beforeEach(() => { | ||
TestBed.compileComponents(); | ||
}); | ||
|
||
it('initializes a Google map', () => { | ||
const fixture = TestBed.createComponent(TestApp); | ||
const container = fixture.debugElement.query(By.css('div')); | ||
fixture.detectChanges(); | ||
|
||
expect(mapConstructorSpy).toHaveBeenCalledWith(container.nativeElement, DEFAULT_OPTIONS); | ||
}); | ||
}); | ||
|
||
@Component({ | ||
selector: 'test-app', | ||
template: `<google-map></google-map>`, | ||
}) | ||
class TestApp {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
ElementRef, | ||
Input, | ||
OnInit, | ||
} from '@angular/core'; | ||
import {ReplaySubject} from 'rxjs'; | ||
|
||
/** | ||
* Angular component that renders a Google Map via the Google Maps JavaScript | ||
* API. | ||
* @see https://developers.google.com/maps/documentation/javascript/reference/ | ||
*/ | ||
@Component({ | ||
selector: 'google-map', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
template: '<div class="map-container"></div>', | ||
}) | ||
export class GoogleMap implements OnInit { | ||
// Arbitrarily chosen default size | ||
@Input() height = '500px'; | ||
@Input() width = '500px'; | ||
|
||
// TODO(mbehrlich): add options, handlers, properties, and methods. | ||
|
||
private readonly _map$ = new ReplaySubject<google.maps.Map>(1); | ||
|
||
constructor(private readonly _elementRef: ElementRef) {} | ||
|
||
ngOnInit() { | ||
// default options set to the Googleplex | ||
const options: google.maps.MapOptions = { | ||
center: {lat: 37.421995, lng: -122.084092}, | ||
zoom: 17, | ||
}; | ||
|
||
const mapEl = this._elementRef.nativeElement.querySelector('.map-container'); | ||
mapEl.style.height = this.height; | ||
mapEl.style.width = this.width; | ||
const map = new google.maps.Map(mapEl, options); | ||
this._map$.next(map); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* @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 | ||
*/ | ||
|
||
export * from './public-api'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* @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 | ||
*/ | ||
|
||
export * from './google-map-module'; | ||
export * from './google-map'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("//tools:defaults.bzl", "ts_library") | ||
|
||
ts_library( | ||
name = "testing", | ||
testonly = 1, | ||
srcs = glob(["**/*.ts"]), | ||
deps = [ | ||
"@npm//@types/googlemaps", | ||
"@npm//@types/jasmine", | ||
], | ||
) |
Oops, something went wrong.