Skip to content

Commit

Permalink
feat(MarkerManager): set a visible option to marker.
Browse files Browse the repository at this point in the history
  • Loading branch information
TSHiYK committed Aug 8, 2016
1 parent 468a1a8 commit 373d605
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/core/directives/google-map-marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let markerId = 0;
@Directive({
selector: 'sebm-google-map-marker',
inputs: [
'latitude', 'longitude', 'title', 'label', 'draggable: markerDraggable', 'iconUrl',
'latitude', 'longitude', 'title', 'label', 'draggable: markerDraggable', 'iconUrl', 'visible',
'openInfoWindow', 'fitBounds'
],
outputs: ['markerClick', 'dragEnd']
Expand Down Expand Up @@ -73,6 +73,11 @@ export class SebmGoogleMapMarker implements OnDestroy, OnChanges, AfterContentIn
*/
iconUrl: string;

/**
* If true, the marker is visible
*/
visible: boolean;

/**
* Whether to automatically open the child info window when the marker is clicked.
*/
Expand Down Expand Up @@ -129,6 +134,9 @@ export class SebmGoogleMapMarker implements OnDestroy, OnChanges, AfterContentIn
if (changes['iconUrl']) {
this._markerManager.updateIcon(this);
}
if (changes['visible']) {
this._markerManager.updateVisible(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 @@ -27,6 +27,7 @@ export interface Marker extends MVCObject {
setLabel(label: string|MarkerLabel): void;
setDraggable(draggable: boolean): void;
setIcon(icon: string): void;
setVisible(visible: boolean): void;
getLabel(): MarkerLabel;
}

Expand All @@ -37,6 +38,7 @@ export interface MarkerOptions {
label?: string|MarkerLabel;
draggable?: boolean;
icon?: string;
visible?: boolean;
}

export interface MarkerLabel {
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 @@ -49,12 +49,17 @@ export class MarkerManager {
return this._markers.get(marker).then((m: Marker) => m.setIcon(marker.iconUrl));
}

updateVisible(marker: SebmGoogleMapMarker): Promise<void> {
return this._markers.get(marker).then((m: Marker) => m.setVisible(marker.visible));
}

addMarker(marker: SebmGoogleMapMarker) {
const markerPromise = this._mapsWrapper.createMarker({
position: {lat: marker.latitude, lng: marker.longitude},
label: marker.label,
draggable: marker.draggable,
icon: marker.iconUrl
icon: marker.iconUrl,
visible: marker.visible
});
this._markers.set(marker, markerPromise);
}
Expand Down
35 changes: 33 additions & 2 deletions test/services/managers/marker-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export function main() {
position: {lat: 34.4, lng: 22.3},
label: 'A',
draggable: false,
icon: undefined
icon: undefined,
visible: undefined
});
}));
});
Expand Down Expand Up @@ -75,13 +76,43 @@ export function main() {
position: {lat: 34.4, lng: 22.3},
label: 'A',
draggable: false,
icon: undefined
icon: undefined,
visible: undefined
});
const iconUrl = 'http://angular-maps.com/icon.png';
newMarker.iconUrl = iconUrl;
return markerManager.updateIcon(newMarker).then(
() => { expect(markerInstance.setIcon).toHaveBeenCalledWith(iconUrl); });
})));
});

describe('set marker icon', () => {
it('should update that marker via setVisible method when the visible changes',
async(inject(
[MarkerManager, GoogleMapsAPIWrapper],
(markerManager: MarkerManager, apiWrapper: GoogleMapsAPIWrapper) => {
const newMarker = new SebmGoogleMapMarker(markerManager);
newMarker.latitude = 34.4;
newMarker.longitude = 22.3;
newMarker.label = 'A';

const markerInstance: Marker =
jasmine.createSpyObj('Marker', ['setMap', 'setVisible']);
(<any>apiWrapper.createMarker).and.returnValue(Promise.resolve(markerInstance));

markerManager.addMarker(newMarker);
expect(apiWrapper.createMarker).toHaveBeenCalledWith({
position: {lat: 34.4, lng: 22.3},
label: 'A',
draggable: false,
icon: undefined,
visible: undefined
});
const visible = false;
newMarker.visible = visible;
return markerManager.updateIcon(newMarker).then(
() => { expect(markerInstance.setVisible).toHaveBeenCalledWith(visible); });
})));
});
});
}

0 comments on commit 373d605

Please sign in to comment.