Skip to content

Commit

Permalink
feat(SebmGoogleMapMarker): add draggable option
Browse files Browse the repository at this point in the history
closes #70
closes #147
  • Loading branch information
sebholstein committed Feb 21, 2016
1 parent 886bb7d commit a8ba736
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/directives/google-map-marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let markerId = 0;
*/
@Directive({
selector: 'sebm-google-map-marker',
inputs: ['latitude', 'longitude', 'title', 'label'],
inputs: ['latitude', 'longitude', 'title', 'label', 'draggable: markerDraggable'],
outputs: ['markerClick']
})
export class SebmGoogleMapMarker implements OnDestroy,
Expand All @@ -55,6 +55,11 @@ export class SebmGoogleMapMarker implements OnDestroy,
*/
label: string;

/**
* If true, the marker can be dragged. Default value is false.
*/
draggable: boolean = false;

/**
* This event emitter gets emitted when the user clicks on the marker.
*/
Expand Down Expand Up @@ -86,6 +91,9 @@ export class SebmGoogleMapMarker implements OnDestroy,
if (changes['label']) {
this._markerManager.updateLabel(this);
}
if (changes['draggable']) {
this._markerManager.updateDraggable(this);
}
}

/** @internal */
Expand Down
2 changes: 2 additions & 0 deletions src/services/google-maps-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface Marker {
setPosition(latLng: LatLng | LatLngLiteral): void;
setTitle(title: string): void;
setLabel(label: string | MarkerLabel): void;
setDraggable(draggable: boolean): void;
getLabel(): MarkerLabel;
addListener(eventType: string, fn: Function): void;
}
Expand All @@ -32,6 +33,7 @@ export interface MarkerOptions {
title?: string;
map?: GoogleMap;
label?: string | MarkerLabel;
draggable?: boolean;
}

export interface MarkerLabel {
Expand Down
11 changes: 9 additions & 2 deletions src/services/marker-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ export class MarkerManager {
return this._markers.get(marker).then((m: Marker) => { m.setLabel(marker.label); });
}

updateDraggable(marker: SebmGoogleMapMarker): Promise<void> {
return this._markers.get(marker).then((m: Marker) => m.setDraggable(marker.draggable));
}

addMarker(marker: SebmGoogleMapMarker) {
const markerPromise = this._mapsWrapper.createMarker(
{position: {lat: marker.latitude, lng: marker.longitude}, label: marker.label});
const markerPromise = this._mapsWrapper.createMarker({
position: {lat: marker.latitude, lng: marker.longitude},
label: marker.label,
draggable: marker.draggable
});
this._markers.set(marker, markerPromise);
}

Expand Down
2 changes: 1 addition & 1 deletion test/services/marker-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function main() {
markerManager.addMarker(newMarker);

expect(apiWrapper.createMarker)
.toHaveBeenCalledWith({position: {lat: 34.4, lng: 22.3}, label: 'A'});
.toHaveBeenCalledWith({position: {lat: 34.4, lng: 22.3}, label: 'A', draggable: false});
}));
});

Expand Down

0 comments on commit a8ba736

Please sign in to comment.