Skip to content

Commit

Permalink
feat(AgmMap): EventEmitter for maptypeid_changed event
Browse files Browse the repository at this point in the history
Add the event emitter for google map's maptypeid_changed event
  • Loading branch information
jgutix authored and sebholstein committed Dec 2, 2017
1 parent e513c57 commit f9c23aa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
19 changes: 17 additions & 2 deletions packages/core/directives/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import {Subscription} from 'rxjs/Subscription';

import {MouseEvent} from '../map-types';
import {GoogleMapsAPIWrapper} from '../services/google-maps-api-wrapper';
import {FullscreenControlOptions, LatLng, LatLngLiteral, MapTypeControlOptions, PanControlOptions,
RotateControlOptions, ScaleControlOptions, StreetViewControlOptions, ZoomControlOptions} from '../services/google-maps-types';
import {
FullscreenControlOptions, LatLng, LatLngLiteral, MapTypeControlOptions, MapTypeId, PanControlOptions,
RotateControlOptions, ScaleControlOptions, StreetViewControlOptions, ZoomControlOptions} from '../services/google-maps-types';
import {LatLngBounds, LatLngBoundsLiteral, MapTypeStyle} from '../services/google-maps-types';
import {CircleManager} from '../services/managers/circle-manager';
import {InfoWindowManager} from '../services/managers/info-window-manager';
Expand Down Expand Up @@ -294,6 +295,11 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
*/
@Output() boundsChange: EventEmitter<LatLngBounds> = new EventEmitter<LatLngBounds>();

/**
* This event is fired when the mapTypeId property changes.
*/
@Output() mapTypeIdChange: EventEmitter<MapTypeId> = new EventEmitter<MapTypeId>();

/**
* This event is fired when the map becomes idle after panning or zooming.
*/
Expand Down Expand Up @@ -360,6 +366,7 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
this._handleMapZoomChange();
this._handleMapMouseEvents();
this._handleBoundsChange();
this._handleMapTypeIdChange();
this._handleIdleEvent();
}

Expand Down Expand Up @@ -462,6 +469,14 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
this._observableSubscriptions.push(s);
}

private _handleMapTypeIdChange() {
const s = this._mapsWrapper.subscribeToMapEvent<void>('maptypeid_changed').subscribe(() => {
this._mapsWrapper.getMapTypeId().then(
(mapTypeId: MapTypeId) => { this.mapTypeIdChange.emit(mapTypeId); });
});
this._observableSubscriptions.push(s);
}

private _handleMapZoomChange() {
const s = this._mapsWrapper.subscribeToMapEvent<void>('zoom_changed').subscribe(() => {
this._mapsWrapper.getZoom().then((z: number) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/services/google-maps-api-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export class GoogleMapsAPIWrapper {
return this._map.then((map: mapTypes.GoogleMap) => map.getBounds());
}

getMapTypeId(): Promise<mapTypes.MapTypeId> {
return this._map.then((map: mapTypes.GoogleMap) => map.getMapTypeId());
}

setZoom(zoom: number): Promise<void> {
return this._map.then((map: mapTypes.GoogleMap) => map.setZoom(zoom));
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/services/google-maps-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface GoogleMap extends MVCObject {
getCenter(): LatLng;
setCenter(latLng: LatLng|LatLngLiteral): void;
getBounds(): LatLngBounds;
getMapTypeId(): MapTypeId;
getZoom(): number;
setOptions(options: MapOptions): void;
panToBounds(latLngBounds: LatLngBounds|LatLngBoundsLiteral): void;
Expand Down Expand Up @@ -401,7 +402,7 @@ export interface Feature extends MVCObject {
properties: any;
}

export interface DataOptions{
export interface DataOptions {
controlPosition?: ControlPosition;
controls?: string[];
drawingMode?: string;
Expand Down

0 comments on commit f9c23aa

Please sign in to comment.