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

Commit a8ba736

Browse files
committed
feat(SebmGoogleMapMarker): add draggable option
closes #70 closes #147
1 parent 886bb7d commit a8ba736

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

src/directives/google-map-marker.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let markerId = 0;
3030
*/
3131
@Directive({
3232
selector: 'sebm-google-map-marker',
33-
inputs: ['latitude', 'longitude', 'title', 'label'],
33+
inputs: ['latitude', 'longitude', 'title', 'label', 'draggable: markerDraggable'],
3434
outputs: ['markerClick']
3535
})
3636
export class SebmGoogleMapMarker implements OnDestroy,
@@ -55,6 +55,11 @@ export class SebmGoogleMapMarker implements OnDestroy,
5555
*/
5656
label: string;
5757

58+
/**
59+
* If true, the marker can be dragged. Default value is false.
60+
*/
61+
draggable: boolean = false;
62+
5863
/**
5964
* This event emitter gets emitted when the user clicks on the marker.
6065
*/
@@ -86,6 +91,9 @@ export class SebmGoogleMapMarker implements OnDestroy,
8691
if (changes['label']) {
8792
this._markerManager.updateLabel(this);
8893
}
94+
if (changes['draggable']) {
95+
this._markerManager.updateDraggable(this);
96+
}
8997
}
9098

9199
/** @internal */

src/services/google-maps-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface Marker {
2323
setPosition(latLng: LatLng | LatLngLiteral): void;
2424
setTitle(title: string): void;
2525
setLabel(label: string | MarkerLabel): void;
26+
setDraggable(draggable: boolean): void;
2627
getLabel(): MarkerLabel;
2728
addListener(eventType: string, fn: Function): void;
2829
}
@@ -32,6 +33,7 @@ export interface MarkerOptions {
3233
title?: string;
3334
map?: GoogleMap;
3435
label?: string | MarkerLabel;
36+
draggable?: boolean;
3537
}
3638

3739
export interface MarkerLabel {

src/services/marker-manager.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,16 @@ export class MarkerManager {
3939
return this._markers.get(marker).then((m: Marker) => { m.setLabel(marker.label); });
4040
}
4141

42+
updateDraggable(marker: SebmGoogleMapMarker): Promise<void> {
43+
return this._markers.get(marker).then((m: Marker) => m.setDraggable(marker.draggable));
44+
}
45+
4246
addMarker(marker: SebmGoogleMapMarker) {
43-
const markerPromise = this._mapsWrapper.createMarker(
44-
{position: {lat: marker.latitude, lng: marker.longitude}, label: marker.label});
47+
const markerPromise = this._mapsWrapper.createMarker({
48+
position: {lat: marker.latitude, lng: marker.longitude},
49+
label: marker.label,
50+
draggable: marker.draggable
51+
});
4552
this._markers.set(marker, markerPromise);
4653
}
4754

test/services/marker-manager.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function main() {
2828
markerManager.addMarker(newMarker);
2929

3030
expect(apiWrapper.createMarker)
31-
.toHaveBeenCalledWith({position: {lat: 34.4, lng: 22.3}, label: 'A'});
31+
.toHaveBeenCalledWith({position: {lat: 34.4, lng: 22.3}, label: 'A', draggable: false});
3232
}));
3333
});
3434

0 commit comments

Comments
 (0)