-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(google-maps): Add Layer components. #19604
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
5 commits
Select commit
Hold shift + click to select a range
b84ec37
feat(google-maps): Add Layer components.
mbehrlich a3e9cb7
feat(google-maps): Add Layer components.
mbehrlich f83a42f
feat(google-maps): Add layer components
mbehrlich c1149af
feat(google-maps): Add Layer components.
mbehrlich 4dfc334
feat(google-maps): Add Layer components
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @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 | ||
*/ | ||
|
||
// Workaround for: https://github.com/bazelbuild/rules_nodejs/issues/1265 | ||
/// <reference types="googlemaps" /> | ||
|
||
import {Directive, NgZone, OnDestroy, OnInit} from '@angular/core'; | ||
|
||
import {GoogleMap} from './google-map/google-map'; | ||
|
||
@Directive({ | ||
selector: 'map-base-layer', | ||
exportAs: 'mapBaseLayer', | ||
}) | ||
export class MapBaseLayer implements OnInit, OnDestroy { | ||
constructor(protected readonly _map: GoogleMap, protected readonly _ngZone: NgZone) {} | ||
|
||
ngOnInit() { | ||
if (this._map._isBrowser) { | ||
this._ngZone.runOutsideAngular(() => { | ||
this._initializeObject(); | ||
}); | ||
this._assertInitialized(); | ||
this._setMap(); | ||
} | ||
} | ||
|
||
ngOnDestroy() { | ||
this._unsetMap(); | ||
} | ||
|
||
private _assertInitialized() { | ||
if (!this._map.googleMap) { | ||
throw Error( | ||
'Cannot access Google Map information before the API has been initialized. ' + | ||
'Please wait for the API to load before trying to interact with it.'); | ||
} | ||
} | ||
|
||
protected _initializeObject() {} | ||
protected _setMap() {} | ||
protected _unsetMap() {} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/google-maps/map-bicycling-layer/map-bicycling-layer.spec.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,54 @@ | ||
import {Component} from '@angular/core'; | ||
import {async, TestBed} from '@angular/core/testing'; | ||
|
||
import {DEFAULT_OPTIONS} from '../google-map/google-map'; | ||
import {GoogleMapsModule} from '../google-maps-module'; | ||
import { | ||
createBicyclingLayerConstructorSpy, | ||
createBicyclingLayerSpy, | ||
createMapConstructorSpy, | ||
createMapSpy, | ||
} from '../testing/fake-google-map-utils'; | ||
|
||
describe('MapBicyclingLayer', () => { | ||
let mapSpy: jasmine.SpyObj<google.maps.Map>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [GoogleMapsModule], | ||
declarations: [TestApp], | ||
}); | ||
})); | ||
|
||
beforeEach(() => { | ||
TestBed.compileComponents(); | ||
|
||
mapSpy = createMapSpy(DEFAULT_OPTIONS); | ||
createMapConstructorSpy(mapSpy).and.callThrough(); | ||
}); | ||
|
||
afterEach(() => { | ||
delete window.google; | ||
}); | ||
|
||
it('initializes a Google Map Bicycling Layer', () => { | ||
const bicyclingLayerSpy = createBicyclingLayerSpy(); | ||
const bicyclingLayerConstructorSpy = | ||
createBicyclingLayerConstructorSpy(bicyclingLayerSpy).and.callThrough(); | ||
|
||
const fixture = TestBed.createComponent(TestApp); | ||
fixture.detectChanges(); | ||
|
||
expect(bicyclingLayerConstructorSpy).toHaveBeenCalled(); | ||
expect(bicyclingLayerSpy.setMap).toHaveBeenCalledWith(mapSpy); | ||
}); | ||
}); | ||
|
||
@Component({ | ||
selector: 'test-app', | ||
template: `<google-map> | ||
<map-bicycling-layer></map-bicycling-layer> | ||
</google-map>`, | ||
}) | ||
class TestApp { | ||
} |
55 changes: 55 additions & 0 deletions
55
src/google-maps/map-bicycling-layer/map-bicycling-layer.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,55 @@ | ||
/** | ||
* @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 | ||
*/ | ||
|
||
// Workaround for: https://github.com/bazelbuild/rules_nodejs/issues/1265 | ||
/// <reference types="googlemaps" /> | ||
|
||
import {Directive} from '@angular/core'; | ||
|
||
import {MapBaseLayer} from '../map-base-layer'; | ||
|
||
/** | ||
* Angular component that renders a Google Maps Bicycling Layer via the Google Maps JavaScript API. | ||
* | ||
* See developers.google.com/maps/documentation/javascript/reference/map#BicyclingLayer | ||
*/ | ||
@Directive({ | ||
selector: 'map-bicycling-layer', | ||
exportAs: 'mapBicyclingLayer', | ||
}) | ||
export class MapBicyclingLayer extends MapBaseLayer { | ||
/** | ||
* The underlying google.maps.BicyclingLayer object. | ||
* | ||
* See developers.google.com/maps/documentation/javascript/reference/map#BicyclingLayer | ||
*/ | ||
bicyclingLayer?: google.maps.BicyclingLayer; | ||
|
||
protected _initializeObject() { | ||
this.bicyclingLayer = new google.maps.BicyclingLayer(); | ||
} | ||
|
||
protected _setMap() { | ||
this._assertLayerInitialized(); | ||
this.bicyclingLayer.setMap(this._map.googleMap!); | ||
} | ||
|
||
protected _unsetMap() { | ||
if (this.bicyclingLayer) { | ||
this.bicyclingLayer.setMap(null); | ||
} | ||
} | ||
|
||
private _assertLayerInitialized(): asserts this is {bicyclingLayer: google.maps.BicyclingLayer} { | ||
if (!this.bicyclingLayer) { | ||
throw Error( | ||
'Cannot interact with a Google Map Bicycling Layer before it has been initialized. ' + | ||
'Please wait for the Transit Layer to load before trying to interact with it.'); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/google-maps/map-traffic-layer/map-traffic-layer.spec.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,58 @@ | ||
import {Component} from '@angular/core'; | ||
import {async, TestBed} from '@angular/core/testing'; | ||
|
||
import {DEFAULT_OPTIONS} from '../google-map/google-map'; | ||
import {GoogleMapsModule} from '../google-maps-module'; | ||
import { | ||
createMapConstructorSpy, | ||
createMapSpy, | ||
createTrafficLayerConstructorSpy, | ||
createTrafficLayerSpy, | ||
} from '../testing/fake-google-map-utils'; | ||
|
||
describe('MapTrafficLayer', () => { | ||
let mapSpy: jasmine.SpyObj<google.maps.Map>; | ||
const trafficLayerOptions: google.maps.TrafficLayerOptions = {autoRefresh: false}; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [GoogleMapsModule], | ||
declarations: [TestApp], | ||
}); | ||
})); | ||
|
||
beforeEach(() => { | ||
TestBed.compileComponents(); | ||
|
||
mapSpy = createMapSpy(DEFAULT_OPTIONS); | ||
createMapConstructorSpy(mapSpy).and.callThrough(); | ||
}); | ||
|
||
afterEach(() => { | ||
delete window.google; | ||
}); | ||
|
||
it('initializes a Google Map Traffic Layer', () => { | ||
const trafficLayerSpy = createTrafficLayerSpy(trafficLayerOptions); | ||
const trafficLayerConstructorSpy = | ||
createTrafficLayerConstructorSpy(trafficLayerSpy).and.callThrough(); | ||
|
||
const fixture = TestBed.createComponent(TestApp); | ||
fixture.componentInstance.autoRefresh = false; | ||
fixture.detectChanges(); | ||
|
||
expect(trafficLayerConstructorSpy).toHaveBeenCalledWith(trafficLayerOptions); | ||
expect(trafficLayerSpy.setMap).toHaveBeenCalledWith(mapSpy); | ||
}); | ||
}); | ||
|
||
@Component({ | ||
selector: 'test-app', | ||
template: `<google-map> | ||
<map-traffic-layer [autoRefresh]="autoRefresh"> | ||
</map-traffic-layer> | ||
</google-map>`, | ||
}) | ||
class TestApp { | ||
autoRefresh?: boolean; | ||
} |
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.