Skip to content

Commit

Permalink
fix: add support for fractional zoom (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoehnelt authored Nov 22, 2021
1 parent 9057fb6 commit 73c0fe6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/algorithms/supercluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,26 @@ test("should not cluster if zoom beyond maxZoom", () => {
expect(changed).toBeFalsy();
expect(clusters).toBe(superCluster["clusters"]);
});

test("should round fractional zoom", () => {
const mapCanvasProjection =
jest.fn() as unknown as google.maps.MapCanvasProjection;
const markers: google.maps.Marker[] = [];

const superCluster = new SuperClusterAlgorithm({});
superCluster["superCluster"].getClusters = jest.fn().mockReturnValue([]);

map.getZoom = jest.fn().mockReturnValue(1.534);
superCluster.cluster({ map, mapCanvasProjection, markers });
expect(superCluster["superCluster"].getClusters).toHaveBeenCalledWith(
[-180, -90, 180, 90],
2
);

map.getZoom = jest.fn().mockReturnValue(3.234);
superCluster.cluster({ map, mapCanvasProjection, markers });
expect(superCluster["superCluster"].getClusters).toHaveBeenCalledWith(
[-180, -90, 180, 90],
3
);
});
2 changes: 1 addition & 1 deletion src/algorithms/supercluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class SuperClusterAlgorithm extends AbstractAlgorithm {

public cluster({ map }: AlgorithmInput): Cluster[] {
return this.superCluster
.getClusters([-180, -90, 180, 90], map.getZoom())
.getClusters([-180, -90, 180, 90], Math.round(map.getZoom()))
.map(this.transformCluster.bind(this));
}

Expand Down

0 comments on commit 73c0fe6

Please sign in to comment.