Description
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>