-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(google-maps): add google-map component #16623
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6b99c61
feat(google-maps): add google-map component
mbehrlich 414e4b7
feat(google-maps): add google-map component
mbehrlich 3622b4f
feat(google-maps): Add google-map component
mbehrlich 54a9ded
feat(google-maps): add google-map component
mbehrlich b36f908
feat(google-maps): add google-map component
mbehrlich 4ed0038
feat(google-maps): add google-map component
mbehrlich 17ab387
feat(google-maps): add google-map component
mbehrlich 4a3eb9c
feat(google-maps): add google-map component
mbehrlich 0c741c1
feat(google-maps): add google-map component
mbehrlich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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'; | ||
mbehrlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Input() width = '500px'; | ||
|
||
// TODO(mbehrlich): add options, handlers, properties, and methods. | ||
Splaktar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private readonly _map$ = new ReplaySubject<google.maps.Map>(1); | ||
Splaktar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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); | ||
Splaktar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.