Skip to content

SuperClusterViewportAlgorithm: fails with empty markers array #1129

@HusamElbashir

Description

@HusamElbashir

Related Issue

This is similar to #991. The fix in PR #1014 was applied to SuperClusterAlgorithm but not to SuperClusterViewportAlgorithm.

Environment details

  1. @googlemaps/markerclusterer: 2.6.2
  2. macOS 15.5 / Chrome 143.0.0.0 (arm64)

Steps to reproduce

  1. Create a MarkerClusterer using SuperClusterViewportAlgorithm as the algorithm
  2. Initialize with an empty markers array, or call clearMarkers()

Code example

import { MarkerClusterer, SuperClusterViewportAlgorithm } from "@googlemaps/markerclusterer";

const algorithm = new SuperClusterViewportAlgorithm({});
const clusterer = new MarkerClusterer({
  map,
  algorithm,
  markers: [], // empty array triggers the bug
});

Stack trace

Uncaught TypeError: Cannot read properties of undefined (reading 'range')
    at Supercluster.getClusters (index.js:105:26)
    at SuperClusterViewportAlgorithm.cluster (superviewport.ts:114:8)
    at SuperClusterViewportAlgorithm.calculate (superviewport.ts:102:28)
    at MarkerClusterer.render (markerclusterer.ts:177:52)
    at MarkerClusterer.onAdd (markerclusterer.ts:235:10)

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions