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(google-maps): add icon input to marker #22357

Merged
merged 1 commit into from
Apr 2, 2021
Merged
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
5 changes: 5 additions & 0 deletions src/google-maps/map-marker/map-marker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('MapMarker', () => {
title: undefined,
label: undefined,
clickable: undefined,
icon: undefined,
map: mapSpy,
});
});
Expand All @@ -55,6 +56,7 @@ describe('MapMarker', () => {
title: 'marker title',
label: 'marker label',
clickable: false,
icon: 'icon.png',
map: mapSpy,
};
const markerSpy = createMarkerSpy(options);
Expand All @@ -65,6 +67,7 @@ describe('MapMarker', () => {
fixture.componentInstance.title = options.title;
fixture.componentInstance.label = options.label;
fixture.componentInstance.clickable = options.clickable;
fixture.componentInstance.icon = 'icon.png';
fixture.detectChanges();

expect(markerConstructorSpy).toHaveBeenCalledWith(options);
Expand Down Expand Up @@ -221,6 +224,7 @@ describe('MapMarker', () => {
[label]="label"
[clickable]="clickable"
[options]="options"
[icon]="icon"
(mapClick)="handleClick()"
(positionChanged)="handlePositionChanged()">
</map-marker>
Expand All @@ -233,6 +237,7 @@ class TestApp {
label?: string|google.maps.MarkerLabel;
clickable?: boolean;
options?: google.maps.MarkerOptions;
icon?: string;

handleClick() {}

Expand Down
19 changes: 17 additions & 2 deletions src/google-maps/map-marker/map-marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ export class MapMarker implements OnInit, OnChanges, OnDestroy, MapAnchorPoint {
}
private _options: google.maps.MarkerOptions;

/**
* Icon to be used for the marker.
* See: https://developers.google.com/maps/documentation/javascript/reference/marker#Icon
*/
@Input()
set icon(icon: string | google.maps.Icon | google.maps.Symbol) {
this._icon = icon;
}
private _icon: string | google.maps.Icon | google.maps.Symbol;

/**
* See
* developers.google.com/maps/documentation/javascript/reference/marker#Marker.animation_changed
Expand Down Expand Up @@ -276,7 +286,7 @@ export class MapMarker implements OnInit, OnChanges, OnDestroy, MapAnchorPoint {
}

ngOnChanges(changes: SimpleChanges) {
const {marker, _title, _position, _label, _clickable} = this;
const {marker, _title, _position, _label, _clickable, _icon} = this;

if (marker) {
if (changes['options']) {
Expand All @@ -298,6 +308,10 @@ export class MapMarker implements OnInit, OnChanges, OnDestroy, MapAnchorPoint {
if (changes['clickable'] && _clickable !== undefined) {
marker.setClickable(_clickable);
}

if (changes['icon'] && _icon) {
marker.setIcon(_icon);
}
}
}

Expand Down Expand Up @@ -430,8 +444,9 @@ export class MapMarker implements OnInit, OnChanges, OnDestroy, MapAnchorPoint {
title: this._title || options.title,
position: this._position || options.position,
label: this._label || options.label,
clickable: this._clickable !== undefined ? this._clickable : options.clickable,
clickable: this._clickable ?? options.clickable,
map: this._googleMap.googleMap,
icon: this._icon || options.icon
};
}

Expand Down
3 changes: 2 additions & 1 deletion tools/public_api_guard/google-maps/google-maps.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export declare class MapMarker implements OnInit, OnChanges, OnDestroy, MapAncho
cursorChanged: Observable<void>;
draggableChanged: Observable<void>;
flatChanged: Observable<void>;
set icon(icon: string | google.maps.Icon | google.maps.Symbol);
iconChanged: Observable<void>;
set label(label: string | google.maps.MarkerLabel);
mapClick: Observable<google.maps.MapMouseEvent>;
Expand Down Expand Up @@ -272,7 +273,7 @@ export declare class MapMarker implements OnInit, OnChanges, OnDestroy, MapAncho
ngOnChanges(changes: SimpleChanges): void;
ngOnDestroy(): void;
ngOnInit(): void;
static ɵdir: i0.ɵɵDirectiveDefWithMeta<MapMarker, "map-marker", ["mapMarker"], { "title": "title"; "position": "position"; "label": "label"; "clickable": "clickable"; "options": "options"; }, { "animationChanged": "animationChanged"; "mapClick": "mapClick"; "clickableChanged": "clickableChanged"; "cursorChanged": "cursorChanged"; "mapDblclick": "mapDblclick"; "mapDrag": "mapDrag"; "mapDragend": "mapDragend"; "draggableChanged": "draggableChanged"; "mapDragstart": "mapDragstart"; "flatChanged": "flatChanged"; "iconChanged": "iconChanged"; "mapMousedown": "mapMousedown"; "mapMouseout": "mapMouseout"; "mapMouseover": "mapMouseover"; "mapMouseup": "mapMouseup"; "positionChanged": "positionChanged"; "mapRightclick": "mapRightclick"; "shapeChanged": "shapeChanged"; "titleChanged": "titleChanged"; "visibleChanged": "visibleChanged"; "zindexChanged": "zindexChanged"; }, never>;
static ɵdir: i0.ɵɵDirectiveDefWithMeta<MapMarker, "map-marker", ["mapMarker"], { "title": "title"; "position": "position"; "label": "label"; "clickable": "clickable"; "options": "options"; "icon": "icon"; }, { "animationChanged": "animationChanged"; "mapClick": "mapClick"; "clickableChanged": "clickableChanged"; "cursorChanged": "cursorChanged"; "mapDblclick": "mapDblclick"; "mapDrag": "mapDrag"; "mapDragend": "mapDragend"; "draggableChanged": "draggableChanged"; "mapDragstart": "mapDragstart"; "flatChanged": "flatChanged"; "iconChanged": "iconChanged"; "mapMousedown": "mapMousedown"; "mapMouseout": "mapMouseout"; "mapMouseover": "mapMouseover"; "mapMouseup": "mapMouseup"; "positionChanged": "positionChanged"; "mapRightclick": "mapRightclick"; "shapeChanged": "shapeChanged"; "titleChanged": "titleChanged"; "visibleChanged": "visibleChanged"; "zindexChanged": "zindexChanged"; }, never>;
static ɵfac: i0.ɵɵFactoryDef<MapMarker, never>;
}

Expand Down