-
Notifications
You must be signed in to change notification settings - Fork 817
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): Support for Bicycling Layer (#1678)
- Added a single service to manage all map layers like transit and bicycling layers
- Loading branch information
Showing
12 changed files
with
277 additions
and
188 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Directive, Input, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core'; | ||
import { LayerManager } from '../services/managers/layer-manager'; | ||
|
||
let layerId = 0; | ||
|
||
/* | ||
* This directive adds a bicycling layer to a google map instance | ||
* <agm-bicycling-layer [visible]="true|false"> <agm-bicycling-layer> | ||
* */ | ||
@Directive({ | ||
selector: 'agm-bicycling-layer' | ||
}) | ||
|
||
export class AgmBicyclingLayer implements OnInit, OnChanges, OnDestroy{ | ||
private _addedToManager: boolean = false; | ||
private _id: string = (layerId++).toString(); | ||
|
||
/** | ||
* Hide/show bicycling layer | ||
*/ | ||
@Input() visible: boolean = true; | ||
|
||
constructor( private _manager: LayerManager ) {} | ||
|
||
ngOnInit() { | ||
if (this._addedToManager) { | ||
return; | ||
} | ||
this._manager.addBicyclingLayer(this, {visible: this.visible}); | ||
this._addedToManager = true; | ||
} | ||
|
||
ngOnChanges(changes: SimpleChanges) { | ||
if (!this._addedToManager) { | ||
return; | ||
} | ||
if (changes['visible'] != null) { | ||
this._manager.toggleLayerVisibility(this, {visible: changes['visible'].currentValue}); | ||
} | ||
} | ||
|
||
/** @internal */ | ||
id(): string { return this._id; } | ||
|
||
/** @internal */ | ||
toString(): string { return `AgmBicyclingLayer-${this._id.toString()}`; } | ||
|
||
/** @internal */ | ||
ngOnDestroy() { | ||
this._manager.deleteLayer(this); | ||
} | ||
|
||
} |
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,116 @@ | ||
import {NgZone} from '@angular/core'; | ||
import {TestBed, inject, fakeAsync} from '@angular/core/testing'; | ||
import {AgmTransitLayer} from '../../directives/transit-layer'; | ||
import {GoogleMapsAPIWrapper} from '../../services/google-maps-api-wrapper'; | ||
import {LayerManager} from './layer-manager'; | ||
import {AgmBicyclingLayer} from '../../directives/bicycling-layer'; | ||
|
||
describe('LayerManager', () => { | ||
beforeAll(() => { | ||
(<any>window).google = { | ||
maps: { | ||
TransitLayer: class TransitLayer { | ||
setMap = jest.fn(); | ||
getMap = jest.fn(); | ||
constructor() { | ||
|
||
} | ||
}, | ||
|
||
BicyclingLayer: class BicyclingLayer { | ||
setMap = jest.fn(); | ||
getMap = jest.fn(); | ||
constructor() { | ||
|
||
} | ||
}, | ||
} | ||
}; | ||
}); | ||
|
||
beforeEach(() => { | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{provide: NgZone, useFactory: () => new NgZone({enableLongStackTrace: true})}, | ||
{ | ||
provide: GoogleMapsAPIWrapper, | ||
useValue: { | ||
getNativeMap: () => Promise.resolve(), | ||
createTransitLayer: jest.fn(), | ||
createBicyclingLayer: jest.fn() | ||
|
||
} | ||
}, | ||
LayerManager, | ||
|
||
] | ||
}); | ||
}); // end beforeEach | ||
|
||
describe('Create a new transit layer', () => { | ||
|
||
it('should call mapsApiWrapper when creating a new transit layer', | ||
fakeAsync(inject( | ||
[LayerManager, GoogleMapsAPIWrapper], | ||
(layerManager: LayerManager, apiWrapper: GoogleMapsAPIWrapper) => { | ||
const transitLayer = new AgmTransitLayer(layerManager); | ||
const opt = {visible: false}; | ||
layerManager.addTransitLayer(transitLayer, opt); | ||
expect(apiWrapper.createTransitLayer).toHaveBeenCalledWith(opt); | ||
}) | ||
) | ||
); | ||
}); | ||
|
||
describe('Create a new bicycling layer', () => { | ||
|
||
it('should call mapsApiWrapper when creating a new bicycling layer', | ||
fakeAsync(inject( | ||
[LayerManager, GoogleMapsAPIWrapper], | ||
(layerManager: LayerManager, apiWrapper: GoogleMapsAPIWrapper) => { | ||
const bicyclingLayer = new AgmBicyclingLayer(layerManager); | ||
const opt = {visible: true}; | ||
layerManager.addBicyclingLayer(bicyclingLayer, opt); | ||
expect(apiWrapper.createBicyclingLayer).toHaveBeenCalledWith(opt); | ||
|
||
}) | ||
) | ||
); | ||
}); | ||
|
||
describe('Toggling visibility of a MapLayer', () => { | ||
|
||
it('should update the visibility of a map layer when the visibility option changes', fakeAsync( | ||
|
||
inject( | ||
[LayerManager, GoogleMapsAPIWrapper], | ||
(layerManager: LayerManager, | ||
apiWrapper: GoogleMapsAPIWrapper) => { | ||
const newLayer = new AgmTransitLayer(layerManager); | ||
newLayer.visible = true; | ||
|
||
const transitLayerInstance: any = { | ||
setMap: jest.fn(), | ||
getMap: jest.fn(), | ||
}; | ||
|
||
(<jest.Mock>apiWrapper.createTransitLayer).mockReturnValue( | ||
Promise.resolve(transitLayerInstance) | ||
); | ||
|
||
layerManager.addTransitLayer(newLayer, {visible: true}); | ||
expect(apiWrapper.createTransitLayer).toHaveBeenCalledWith({visible: true}); | ||
|
||
newLayer.visible = false; | ||
layerManager.toggleLayerVisibility(newLayer, {visible: false}).then(() => { | ||
expect(transitLayerInstance.setMap).toHaveBeenCalledWith(null); | ||
}); | ||
} | ||
) | ||
|
||
)); | ||
|
||
}); | ||
|
||
}); |
Oops, something went wrong.