Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(google-maps): Add support for SuperClusterAlgorithm customized options from @googlemaps/markerclusterer #30466

Open
xbit18 opened this issue Feb 10, 2025 · 0 comments
Labels
area: google-maps P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@xbit18
Copy link

xbit18 commented Feb 10, 2025

Feature Description

Hello, I hope this is useful to someone:
I recently started using the angular-google-maps library to draw a Google Map with about 4000 advanced markers.
For this I obviously needed to use the MapMarkerClusterer component, but found it nearly impossible to customize the SuperClusterAlgorithm options, since the library only allows to add a maxZoom parameter if I'm not mistaken.

I tried creating a SuperClusterAlgorithm from @googlemaps/markerclusterer, but got an error that said

NG2: Type 'SuperClusterAlgorithm' is not assignable to type 'Algorithm_2'.
  The types of 'calculate(...).clusters' are incompatible between these types.
    Type 'import("C:/Users/g.sfratato/Documents/ProgettiGit/DebugAngular/DebugQ8/node_modules/@googlemaps/markerclusterer/dist/cluster").Cluster[]' is not assignable to type 'import("C:/Users/g.sfratato/Documents/ProgettiGit/DebugAngular/DebugQ8/node_modules/@angular/google-maps/index").Cluster[]'.
      Type 'import("C:/Users/g.sfratato/Documents/ProgettiGit/DebugAngular/DebugQ8/node_modules/@googlemaps/markerclusterer/dist/cluster").Cluster' is not assignable to type 'import("C:/Users/g.sfratato/Documents/ProgettiGit/DebugAngular/DebugQ8/node_modules/@angular/google-maps/index").Cluster'.
        Property '_position' is protected but type 'Cluster' is not a class derived from 'Cluster'.

For this reason I tried to solve the problem by changing the source code: in the index.d.ts file, I added this import

import { AbstractAlgorithm as Algorithm_2} from '@googlemaps/markerclusterer'

and commented out the Algorithm_2 interface definition.

After this, I could use the SuperClusterAlgorithm from @googlemaps/markerclusterer with no problems.

I have no idea if this is ok to do nor if it is feasable but wanted to share this with the community, thanks!

Use Case

In my use case I specifically wanted to change the radius parameter of the algorithm. After the fix, I could provide this algorithm object

algorithm = new SuperClusterAlgorithm({
        maxZoom: 10,
        radius: 100
    })

to the MapMarkerClusterer like this

<map-marker-clusterer [algorithm]="algorithm">
    @for (markerPosition of markerPositions; track $index) {
      <map-advanced-marker [position]="markerPosition"/>
    }
  </map-marker-clusterer>
@xbit18 xbit18 added feature This issue represents a new feature or feature request rather than a bug or bug fix needs triage This issue needs to be triaged by the team labels Feb 10, 2025
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent area: google-maps and removed needs triage This issue needs to be triaged by the team feature This issue represents a new feature or feature request rather than a bug or bug fix labels Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: google-maps P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests

2 participants