Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand All @@ -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;
}
Expand Down