Skip to content

Commit

Permalink
feat(perf): new default clustering algo (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
HusamElbashir authored Aug 12, 2023
1 parent 4cd361b commit 3feb791
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"dependencies": {
"@googlemaps/js-api-loader": "^1.12.11",
"@googlemaps/markerclusterer": "^2.0.6",
"@googlemaps/markerclusterer": "^2.4.0",
"fast-deep-equal": "^3.1.3",
"vite-plugin-css-injected-by-js": "^3.2.1"
},
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions src/components/MarkerCluster.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { defineComponent, PropType, ref, provide, inject, watch, markRaw, onBeforeUnmount } from "vue";
import { MarkerClusterer, MarkerClustererOptions, MarkerClustererEvents } from "@googlemaps/markerclusterer";
import {
MarkerClusterer,
MarkerClustererOptions,
MarkerClustererEvents,
SuperClusterViewportAlgorithm,
} from "@googlemaps/markerclusterer";
import { mapSymbol, apiSymbol, markerClusterSymbol } from "../shared/index";

const markerClusterEvents = Object.values(MarkerClustererEvents);
Expand All @@ -24,7 +29,15 @@ export default defineComponent({
map,
() => {
if (map.value) {
markerCluster.value = markRaw(new MarkerClusterer({ map: map.value, ...props.options }));
markerCluster.value = markRaw(
new MarkerClusterer({
map: map.value,
// Better perf than the default `SuperClusterAlgorithm`. See:
// https://github.com/googlemaps/js-markerclusterer/pull/640
algorithm: new SuperClusterViewportAlgorithm(props.options.algorithmOptions ?? {}),
...props.options,
})
);

markerClusterEvents.forEach((event) => {
markerCluster.value?.addListener(event, (e: unknown) => emit(event, e));
Expand Down

0 comments on commit 3feb791

Please sign in to comment.