Skip to content

Commit

Permalink
feat(AgmMarker): add clickable support
Browse files Browse the repository at this point in the history
Setting marker clickable property
Closes #994
  • Loading branch information
DimaNikishin authored and sebholstein committed Jun 18, 2017
1 parent 128c8f3 commit fec8b01
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/core/directives/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export class AgmMarker implements OnDestroy, OnChanges, AfterContentInit {
*/
@Input() zIndex: number = 1;

/**
* If true, the marker can be clicked. Default value is true.
*/
// tslint:disable-next-line:no-input-rename
@Input('markerClickable') clickable: boolean = true;

/**
* This event emitter gets emitted when the user clicks on the marker.
*/
Expand Down Expand Up @@ -173,6 +179,9 @@ export class AgmMarker implements OnDestroy, OnChanges, AfterContentInit {
if (changes['zIndex']) {
this._markerManager.updateZIndex(this);
}
if (changes['clickable']) {
this._markerManager.updateClickable(this);
}
}

private _addEventListeners() {
Expand Down
2 changes: 2 additions & 0 deletions src/core/services/google-maps-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface Marker extends MVCObject {
setVisible(visible: boolean): void;
setZIndex(zIndex: number): void;
getLabel(): MarkerLabel;
setClickable(clickable: boolean): void;
}

export interface MarkerOptions {
Expand All @@ -45,6 +46,7 @@ export interface MarkerOptions {
opacity?: number;
visible?: boolean;
zIndex?: number;
clickable: boolean;
}

export interface MarkerLabel {
Expand Down
15 changes: 10 additions & 5 deletions src/core/services/managers/marker-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ describe('MarkerManager', () => {
opacity: 1,
visible: true,
zIndex: 1,
title: undefined
title: undefined,
clickable: true
});
}));
});
Expand Down Expand Up @@ -84,7 +85,8 @@ describe('MarkerManager', () => {
opacity: 1,
visible: true,
zIndex: 1,
title: undefined
title: undefined,
clickable: true
});
const iconUrl = 'http://angular-maps.com/icon.png';
newMarker.iconUrl = iconUrl;
Expand Down Expand Up @@ -116,7 +118,8 @@ describe('MarkerManager', () => {
visible: true,
opacity: 1,
zIndex: 1,
title: undefined
title: undefined,
clickable: true
});
const opacity = 0.4;
newMarker.opacity = opacity;
Expand Down Expand Up @@ -149,7 +152,8 @@ describe('MarkerManager', () => {
visible: false,
opacity: 1,
zIndex: 1,
title: undefined
title: undefined,
clickable: true
});
newMarker.visible = true;
return markerManager.updateVisible(newMarker).then(
Expand Down Expand Up @@ -180,7 +184,8 @@ describe('MarkerManager', () => {
visible: false,
opacity: 1,
zIndex: 1,
title: undefined
title: undefined,
clickable: true
});
const zIndex = 10;
newMarker.zIndex = zIndex;
Expand Down
7 changes: 6 additions & 1 deletion src/core/services/managers/marker-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export class MarkerManager {
return this._markers.get(marker).then((m: Marker) => m.setZIndex(marker.zIndex));
}

updateClickable(marker: AgmMarker): Promise<void> {
return this._markers.get(marker).then((m: Marker) => m.setClickable(marker.clickable));
}

addMarker(marker: AgmMarker) {
const markerPromise = this._mapsWrapper.createMarker({
position: {lat: marker.latitude, lng: marker.longitude},
Expand All @@ -70,7 +74,8 @@ export class MarkerManager {
opacity: marker.opacity,
visible: marker.visible,
zIndex: marker.zIndex,
title: marker.title
title: marker.title,
clickable: marker.clickable
});
this._markers.set(marker, markerPromise);
}
Expand Down

0 comments on commit fec8b01

Please sign in to comment.