From ec963a5025e316774863f46a3a26fb9e3c44ff73 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Sun, 21 May 2023 14:21:39 -0700 Subject: [PATCH] refactor(Cluster): cleanup --- src/cluster.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cluster.ts b/src/cluster.ts index 2684264c..5cbcb0ef 100644 --- a/src/cluster.ts +++ b/src/cluster.ts @@ -22,7 +22,7 @@ export interface ClusterOptions { } export class Cluster { - public marker: Marker; + public marker?: Marker; public readonly markers?: Marker[]; protected _position: google.maps.LatLng; @@ -40,12 +40,14 @@ export class Cluster { public get bounds(): google.maps.LatLngBounds | undefined { if (this.markers.length === 0 && !this._position) { - return undefined; + return; } - return this.markers.reduce((bounds, marker) => { - return bounds.extend(MarkerUtils.getPosition(marker)); - }, new google.maps.LatLngBounds(this._position, this._position)); + const bounds = new google.maps.LatLngBounds(this._position, this._position); + for (const marker of this.markers) { + bounds.extend(MarkerUtils.getPosition(marker)); + } + return bounds; } public get position(): google.maps.LatLng { @@ -72,7 +74,7 @@ export class Cluster { public delete(): void { if (this.marker) { MarkerUtils.setMap(this.marker, null); - delete this.marker; + this.marker = undefined; } this.markers.length = 0; }