Skip to content
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

feat(SebmGoogleMap): support bounds_changed event #450

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/core/directives/google-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Subscription} from 'rxjs/Subscription';
import {MouseEvent} from '../events';
import {GoogleMapsAPIWrapper} from '../services/google-maps-api-wrapper';
import {LatLng, LatLngLiteral} from '../services/google-maps-types';
import {MapTypeStyle} from '../services/google-maps-types';
import {LatLngBounds, MapTypeStyle} from '../services/google-maps-types';
import {CircleManager} from '../services/managers/circle-manager';
import {InfoWindowManager} from '../services/managers/info-window-manager';
import {MarkerManager} from '../services/managers/marker-manager';
Expand Down Expand Up @@ -42,7 +42,7 @@ import {MarkerManager} from '../services/managers/marker-manager';
'backgroundColor', 'draggableCursor', 'draggingCursor', 'keyboardShortcuts', 'zoomControl',
'styles', 'usePanning', 'streetViewControl'
],
outputs: ['mapClick', 'mapRightClick', 'mapDblClick', 'centerChange', 'idle'],
outputs: ['mapClick', 'mapRightClick', 'mapDblClick', 'centerChange', 'idle', 'boundsChange'],
host: {'[class.sebm-google-map-container]': 'true'},
styles: [`
.sebm-google-map-container-inner {
Expand Down Expand Up @@ -179,6 +179,11 @@ export class SebmGoogleMap implements OnChanges,
*/
centerChange: EventEmitter<LatLngLiteral> = new EventEmitter<LatLngLiteral>();

/**
* This event is fired when the viewport bounds have changed.
*/
boundsChange: EventEmitter<LatLngBounds> = new EventEmitter<LatLngBounds>();

/**
* This event is fired when the map becomes idle after panning or zooming.
*/
Expand Down Expand Up @@ -209,6 +214,7 @@ export class SebmGoogleMap implements OnChanges,
this._handleMapCenterChange();
this._handleMapZoomChange();
this._handleMapMouseEvents();
this._handleBoundsChange();
this._handleIdleEvent();
}

Expand Down Expand Up @@ -274,6 +280,13 @@ export class SebmGoogleMap implements OnChanges,
this._observableSubscriptions.push(s);
}

private _handleBoundsChange() {
const s = this._mapsWrapper.subscribeToMapEvent<void>('bounds_changed').subscribe(() => {
this._mapsWrapper.getBounds().then((bounds: LatLngBounds) => this.boundsChange.emit(bounds));
});
this._observableSubscriptions.push(s);
}

private _handleMapZoomChange() {
const s = this._mapsWrapper.subscribeToMapEvent<void>('zoom_changed').subscribe(() => {
this._mapsWrapper.getZoom().then((z: number) => this.zoom = z);
Expand Down
3 changes: 3 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export * from './directives';
export * from './services';
export * from './events';

// Google Maps types
export {LatLngBounds, LatLng, LatLngLiteral, MapTypeStyle} from './services/google-maps-types';

export const GOOGLE_MAPS_PROVIDERS: any[] = [
BROWSER_GLOBALS_PROVIDERS,
provide(MapsAPILoader, {useClass: LazyMapsAPILoader}),
Expand Down
4 changes: 4 additions & 0 deletions src/core/services/google-maps-api-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export class GoogleMapsAPIWrapper {

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

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

setZoom(zoom: number): Promise<void> {
return this._map.then((map: mapTypes.GoogleMap) => map.setZoom(zoom));
}
Expand Down
1 change: 1 addition & 0 deletions src/core/services/google-maps-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface GoogleMap {
addListener(eventName: string, fn: Function): void;
getCenter(): LatLng;
setCenter(latLng: LatLng|LatLngLiteral): void;
getBounds(): LatLngBounds;
getZoom(): number;
setOptions(options: MapOptions): void;
}
Expand Down