Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit 34f651b

Browse files
yosigolandoom777
authored andcommitted
feat: Add placeId to map click events
* feat: allow disabling a "point of interest" default info window * feat: Add placeId to map click events when clicking on a point of interest on a map the emiting event will include the `placeId` of the location clicked. allow disabling a "point of interest" default info window. Use it by passing a boolean value to the new property isToShowDefaultInfoWindowForIcons when initializing the map. Default value is `true`. closes issue #691. closes issue #1539.
1 parent 49890c5 commit 34f651b

2 files changed

Lines changed: 56 additions & 34 deletions

File tree

packages/core/directives/map.ts

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import { Component, ElementRef, EventEmitter, OnChanges, OnDestroy, OnInit, SimpleChanges, Input, Output, NgZone } from '@angular/core';
2-
import {Subscription} from 'rxjs';
2+
import { Subscription } from 'rxjs';
33

4-
import {MouseEvent} from '../map-types';
5-
import {GoogleMapsAPIWrapper} from '../services/google-maps-api-wrapper';
4+
import { MouseEvent } from '../map-types';
5+
import { GoogleMapsAPIWrapper } from '../services/google-maps-api-wrapper';
66
import {
77
FullscreenControlOptions, LatLng, LatLngLiteral, MapTypeControlOptions, MapTypeId, PanControlOptions, MapRestriction,
8-
RotateControlOptions, ScaleControlOptions, StreetViewControlOptions, ZoomControlOptions
9-
} from '../services/google-maps-types';
10-
import {LatLngBounds, LatLngBoundsLiteral, MapTypeStyle} from '../services/google-maps-types';
11-
import {CircleManager} from '../services/managers/circle-manager';
12-
import {RectangleManager} from '../services/managers/rectangle-manager';
13-
import {InfoWindowManager} from '../services/managers/info-window-manager';
14-
import {MarkerManager} from '../services/managers/marker-manager';
15-
import {PolygonManager} from '../services/managers/polygon-manager';
16-
import {PolylineManager} from '../services/managers/polyline-manager';
17-
import {KmlLayerManager} from './../services/managers/kml-layer-manager';
18-
import {DataLayerManager} from './../services/managers/data-layer-manager';
19-
import {FitBoundsService} from '../services/fit-bounds';
8+
RotateControlOptions, ScaleControlOptions, StreetViewControlOptions, ZoomControlOptions} from '../services/google-maps-types';
9+
import { LatLngBounds, LatLngBoundsLiteral, MapTypeStyle } from '../services/google-maps-types';
10+
import { CircleManager } from '../services/managers/circle-manager';
11+
import { RectangleManager } from '../services/managers/rectangle-manager';
12+
import { InfoWindowManager } from '../services/managers/info-window-manager';
13+
import { MarkerManager } from '../services/managers/marker-manager';
14+
import { PolygonManager } from '../services/managers/polygon-manager';
15+
import { PolylineManager } from '../services/managers/polyline-manager';
16+
import { KmlLayerManager } from './../services/managers/kml-layer-manager';
17+
import { DataLayerManager } from './../services/managers/data-layer-manager';
18+
import { FitBoundsService } from '../services/fit-bounds';
2019

2120
declare var google: any;
2221

@@ -64,10 +63,10 @@ declare var google: any;
6463
}
6564
`],
6665
template: `
67-
<div class='agm-map-container-inner sebm-google-map-container-inner'></div>
68-
<div class='agm-map-content'>
69-
<ng-content></ng-content>
70-
</div>
66+
<div class='agm-map-container-inner sebm-google-map-container-inner'></div>
67+
<div class='agm-map-content'>
68+
<ng-content></ng-content>
69+
</div>
7170
`
7271
})
7372
export class AgmMap implements OnChanges, OnInit, OnDestroy {
@@ -250,6 +249,14 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
250249
*/
251250
@Input() clickableIcons: boolean = true;
252251

252+
/**
253+
* A map icon represents a point of interest, also known as a POI.
254+
* When map icons are clickable by default, an info window is displayed.
255+
* When this property is set to false, the info window will not be shown but the click event
256+
* will still fire
257+
*/
258+
@Input() showDefaultInfoWindow: boolean = true;
259+
253260
/**
254261
* This setting controls how gestures on the map are handled.
255262
* Allowed values:
@@ -345,7 +352,8 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
345352
*/
346353
@Output() mapReady: EventEmitter<any> = new EventEmitter<any>();
347354

348-
constructor(private _elem: ElementRef, private _mapsWrapper: GoogleMapsAPIWrapper, protected _fitBoundsService: FitBoundsService, private _zone: NgZone) {}
355+
constructor(private _elem: ElementRef, private _mapsWrapper: GoogleMapsAPIWrapper, protected _fitBoundsService: FitBoundsService, private _zone: NgZone) {
356+
}
349357

350358
/** @internal */
351359
ngOnInit() {
@@ -422,7 +430,7 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
422430
private _updateMapOptionsChanges(changes: SimpleChanges) {
423431
let options: {[propName: string]: any} = {};
424432
let optionKeys =
425-
Object.keys(changes).filter(k => AgmMap._mapOptionsAttributes.indexOf(k) !== -1);
433+
Object.keys(changes).filter(k => AgmMap._mapOptionsAttributes.indexOf(k) !== -1);
426434
optionKeys.forEach((k) => { options[k] = changes[k].currentValue; });
427435
this._mapsWrapper.setMapOptions(options);
428436
}
@@ -483,14 +491,14 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
483491
switch (this.fitBounds) {
484492
case true:
485493
this._subscribeToFitBoundsUpdates();
486-
break;
494+
break;
487495
case false:
488496
if (this._fitBoundsSubscription) {
489497
this._fitBoundsSubscription.unsubscribe();
490498
}
491-
break;
492-
default:
493-
this._updateBounds(this.fitBounds);
499+
break;
500+
default:
501+
this._updateBounds(this.fitBounds);
494502
}
495503
}
496504

@@ -533,15 +541,15 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
533541
private _handleBoundsChange() {
534542
const s = this._mapsWrapper.subscribeToMapEvent<void>('bounds_changed').subscribe(() => {
535543
this._mapsWrapper.getBounds().then(
536-
(bounds: LatLngBounds) => { this.boundsChange.emit(bounds); });
544+
(bounds: LatLngBounds) => { this.boundsChange.emit(bounds); });
537545
});
538546
this._observableSubscriptions.push(s);
539547
}
540548

541549
private _handleMapTypeIdChange() {
542550
const s = this._mapsWrapper.subscribeToMapEvent<void>('maptypeid_changed').subscribe(() => {
543551
this._mapsWrapper.getMapTypeId().then(
544-
(mapTypeId: MapTypeId) => { this.mapTypeIdChange.emit(mapTypeId); });
552+
(mapTypeId: MapTypeId) => { this.mapTypeIdChange.emit(mapTypeId); });
545553
});
546554
this._observableSubscriptions.push(s);
547555
}
@@ -558,15 +566,16 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
558566

559567
private _handleIdleEvent() {
560568
const s = this._mapsWrapper.subscribeToMapEvent<void>('idle').subscribe(
561-
() => { this.idle.emit(void 0); });
569+
() => { this.idle.emit(void 0); });
562570
this._observableSubscriptions.push(s);
563571
}
564572

565573
private _handleMapMouseEvents() {
566574
interface Emitter {
567575
emit(value: any): void;
568576
}
569-
type Event = {name: string, emitter: Emitter};
577+
578+
type Event = { name: string, emitter: Emitter };
570579

571580
const events: Event[] = [
572581
{name: 'click', emitter: this.mapClick},
@@ -576,10 +585,20 @@ export class AgmMap implements OnChanges, OnInit, OnDestroy {
576585

577586
events.forEach((e: Event) => {
578587
const s = this._mapsWrapper.subscribeToMapEvent<{latLng: LatLng}>(e.name).subscribe(
579-
(event: {latLng: LatLng}) => {
580-
const value = <MouseEvent>{coords: {lat: event.latLng.lat(), lng: event.latLng.lng()}};
581-
e.emitter.emit(value);
582-
});
588+
(event: {latLng: LatLng}) => {
589+
let value: MouseEvent = {
590+
coords: {
591+
lat: event.latLng.lat(),
592+
lng: event.latLng.lng()
593+
},
594+
placeId: (<{latLng: LatLng, placeId: string}>event).placeId
595+
};
596+
// the placeId will be undefined in case the event was not an IconMouseEvent (google types)
597+
if (value.placeId && !this.showDefaultInfoWindow) {
598+
(<any>event).stop();
599+
}
600+
e.emitter.emit(value);
601+
});
583602
this._observableSubscriptions.push(s);
584603
});
585604
}

packages/core/map-types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ export {
1414
/**
1515
* MouseEvent gets emitted when the user triggers mouse events on the map.
1616
*/
17-
export interface MouseEvent { coords: LatLngLiteral; }
17+
export interface MouseEvent {
18+
coords: LatLngLiteral;
19+
placeId?: string;
20+
}

0 commit comments

Comments
 (0)