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

Commit c16e666

Browse files
DefJunxdoom777
authored andcommitted
feat(AgmMarker): add dblclick observable (#1739)
add and manage double click event for marker fixes #1601
1 parent 8abe038 commit c16e666

1 file changed

Lines changed: 37 additions & 27 deletions

File tree

packages/core/directives/marker.ts

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ let markerId = 0;
3434
@Directive({
3535
selector: 'agm-marker',
3636
providers: [
37-
{provide: FitBoundsAccessor, useExisting: forwardRef(() => AgmMarker)},
37+
{ provide: FitBoundsAccessor, useExisting: forwardRef(() => AgmMarker) },
3838
],
3939
inputs: [
4040
'latitude', 'longitude', 'title', 'label', 'draggable: markerDraggable', 'iconUrl',
@@ -121,6 +121,11 @@ export class AgmMarker implements OnDestroy, OnChanges, AfterContentInit, FitBou
121121
*/
122122
@Output() markerClick: EventEmitter<AgmMarker> = new EventEmitter<AgmMarker>();
123123

124+
/**
125+
* This event emitter gets emitted when the user clicks twice on the marker.
126+
*/
127+
@Output() markerDblClick: EventEmitter<AgmMarker> = new EventEmitter<AgmMarker>();
128+
124129
/**
125130
* This event is fired when the user rightclicks on the marker.
126131
*/
@@ -178,7 +183,7 @@ export class AgmMarker implements OnDestroy, OnChanges, AfterContentInit, FitBou
178183
}
179184

180185
/** @internal */
181-
ngOnChanges(changes: {[key: string]: SimpleChange}) {
186+
ngOnChanges(changes: { [key: string]: SimpleChange }) {
182187
if (typeof this.latitude === 'string') {
183188
this.latitude = Number(this.latitude);
184189
}
@@ -234,7 +239,7 @@ export class AgmMarker implements OnDestroy, OnChanges, AfterContentInit, FitBou
234239
}
235240

236241
protected _updateFitBoundsDetails() {
237-
this._fitBoundsDetails$.next({latLng: {lat: this.latitude, lng: this.longitude}});
242+
this._fitBoundsDetails$.next({ latLng: { lat: this.latitude, lng: this.longitude } });
238243
}
239244

240245
private _addEventListeners() {
@@ -246,51 +251,56 @@ export class AgmMarker implements OnDestroy, OnChanges, AfterContentInit, FitBou
246251
});
247252
this._observableSubscriptions.push(cs);
248253

254+
const dcs = this._markerManager.createEventObservable('dblclick', this).subscribe(() => {
255+
this.markerDblClick.emit(null);
256+
});
257+
this._observableSubscriptions.push(dcs);
258+
249259
const rc = this._markerManager.createEventObservable('rightclick', this).subscribe(() => {
250260
this.markerRightClick.emit(null);
251261
});
252262
this._observableSubscriptions.push(rc);
253263

254264
const ds =
255-
this._markerManager.createEventObservable<mapTypes.MouseEvent>('dragstart', this)
256-
.subscribe((e: mapTypes.MouseEvent) => {
257-
this.dragStart.emit({coords: {lat: e.latLng.lat(), lng: e.latLng.lng()}} as MouseEvent);
258-
});
265+
this._markerManager.createEventObservable<mapTypes.MouseEvent>('dragstart', this)
266+
.subscribe((e: mapTypes.MouseEvent) => {
267+
this.dragStart.emit({ coords: { lat: e.latLng.lat(), lng: e.latLng.lng() } } as MouseEvent);
268+
});
259269
this._observableSubscriptions.push(ds);
260270

261271
const d =
262-
this._markerManager.createEventObservable<mapTypes.MouseEvent>('drag', this)
263-
.subscribe((e: mapTypes.MouseEvent) => {
264-
this.drag.emit({coords: {lat: e.latLng.lat(), lng: e.latLng.lng()}} as MouseEvent);
265-
});
272+
this._markerManager.createEventObservable<mapTypes.MouseEvent>('drag', this)
273+
.subscribe((e: mapTypes.MouseEvent) => {
274+
this.drag.emit({ coords: { lat: e.latLng.lat(), lng: e.latLng.lng() } } as MouseEvent);
275+
});
266276
this._observableSubscriptions.push(d);
267277

268278
const de =
269-
this._markerManager.createEventObservable<mapTypes.MouseEvent>('dragend', this)
270-
.subscribe((e: mapTypes.MouseEvent) => {
271-
this.dragEnd.emit({coords: {lat: e.latLng.lat(), lng: e.latLng.lng()}} as MouseEvent);
272-
});
279+
this._markerManager.createEventObservable<mapTypes.MouseEvent>('dragend', this)
280+
.subscribe((e: mapTypes.MouseEvent) => {
281+
this.dragEnd.emit({ coords: { lat: e.latLng.lat(), lng: e.latLng.lng() } } as MouseEvent);
282+
});
273283
this._observableSubscriptions.push(de);
274284

275285
const mover =
276-
this._markerManager.createEventObservable<mapTypes.MouseEvent>('mouseover', this)
277-
.subscribe((e: mapTypes.MouseEvent) => {
278-
this.mouseOver.emit({coords: {lat: e.latLng.lat(), lng: e.latLng.lng()}} as MouseEvent);
279-
});
286+
this._markerManager.createEventObservable<mapTypes.MouseEvent>('mouseover', this)
287+
.subscribe((e: mapTypes.MouseEvent) => {
288+
this.mouseOver.emit({ coords: { lat: e.latLng.lat(), lng: e.latLng.lng() } } as MouseEvent);
289+
});
280290
this._observableSubscriptions.push(mover);
281291

282292
const mout =
283-
this._markerManager.createEventObservable<mapTypes.MouseEvent>('mouseout', this)
284-
.subscribe((e: mapTypes.MouseEvent) => {
285-
this.mouseOut.emit({coords: {lat: e.latLng.lat(), lng: e.latLng.lng()}} as MouseEvent);
286-
});
293+
this._markerManager.createEventObservable<mapTypes.MouseEvent>('mouseout', this)
294+
.subscribe((e: mapTypes.MouseEvent) => {
295+
this.mouseOut.emit({ coords: { lat: e.latLng.lat(), lng: e.latLng.lng() } } as MouseEvent);
296+
});
287297
this._observableSubscriptions.push(mout);
288298

289299
const anChng =
290-
this._markerManager.createEventObservable<void>('animation_changed', this)
291-
.subscribe(() => {
292-
this.animationChange.emit(this.animation);
293-
});
300+
this._markerManager.createEventObservable<void>('animation_changed', this)
301+
.subscribe(() => {
302+
this.animationChange.emit(this.animation);
303+
});
294304
this._observableSubscriptions.push(anChng);
295305
}
296306

0 commit comments

Comments
 (0)