Skip to content

Commit

Permalink
feat: 클러스터 알고리즘 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
1119wj committed Dec 3, 2024
1 parent e6f9f43 commit 3323a2e
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
2 changes: 1 addition & 1 deletion frontend/src/api/place/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const putPlaceToCourse = async ({
}) => {
const { data } = await axiosInstance.put<CoursePlace[]>(
END_POINTS.PUT_PLACE_TO_COURSE(id),
{ places },
{ pins: places },
);
return { ...data, id };
};
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/constants/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ export const USER_ERROR_MESSAGE = {
E303: '해당 장소가 이미 존재합니다.',
E304: '유효하지 않은 지도입니다. 다시 확인해 주세요.',
E201: '요청한 장소를 찾을 수 없습니다.',
E999: '서버에 문제가 발생했습니다. 잠시 후 다시 시도해 주세요.',
E900: '양식이 잘못 되었습니다. 다시 확인해 주세요.',
};
2 changes: 1 addition & 1 deletion frontend/src/lib/CustomMarkerClusterer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class CustomMarkerClusterer extends MarkerClusterer {
map,
mapCanvasProjection: this.getProjection(),
});
console.log(changed, 'changed');
console.log(changed, 'given changed');

Check warning on line 83 in frontend/src/lib/CustomMarkerClusterer.ts

View workflow job for this annotation

GitHub Actions / Lint, Build and Test (frontend)

Unexpected console statement
// Allow algorithms to return flag on whether the clusters/markers have changed.
if (changed || changed === undefined) {
// Accumulate the markers of the clusters composed of a single marker.
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/lib/CustomSuperCluseterAlgorithm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export class CustomSuperClusterAlgorithm extends SuperClusterViewportAlgorithm {
),
};

let changed = !equal(this.state, state);
// let changed = !equal(this.state, state);
let changed = false;
if (!equal(input.markers, this.markers)) {
// TODO use proxy to avoid copy?
this.markers = [...input.markers];
Expand All @@ -51,6 +52,7 @@ export class CustomSuperClusterAlgorithm extends SuperClusterViewportAlgorithm {
//!equal(this.clusters, newClusters)
if (this.clusters.length !== newClusters.length) {
this.clusters = newClusters;
changed = true;
} else {
changed = false;
}
Expand Down
57 changes: 57 additions & 0 deletions frontend/src/lib/SuperClusterAlgorithm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {
AlgorithmInput,
AlgorithmOutput,
getPaddedViewport,
MarkerUtils,
SuperClusterViewportAlgorithm,
SuperClusterViewportOptions,
SuperClusterViewportState,
} from '@googlemaps/markerclusterer';
import equal from 'fast-deep-equal';

export class SuperClusterAlgorithmTest extends SuperClusterViewportAlgorithm {
constructor({ ...options }: SuperClusterViewportOptions) {
super(options);
this.clusters = [];
}

public calculate(input: AlgorithmInput): AlgorithmOutput {
const state: SuperClusterViewportState = {
zoom: Math.round(input.map.getZoom()!),
view: getPaddedViewport(
input.map.getBounds()!,
input.mapCanvasProjection,
this.viewportPadding,
),
};

let changed = !equal(this.state, state);
console.log('Origin changed', changed);

Check warning on line 29 in frontend/src/lib/SuperClusterAlgorithm.ts

View workflow job for this annotation

GitHub Actions / Lint, Build and Test (frontend)

Unexpected console statement
if (!equal(input.markers, this.markers)) {
changed = true;
// TODO use proxy to avoid copy?
this.markers = [...input.markers];

const points = this.markers.map((marker) => {
const position = MarkerUtils.getPosition(marker);
const coordinates = [position.lng(), position.lat()];
return {
type: 'Feature' as const,
geometry: {
type: 'Point' as const,
coordinates,
},
properties: { marker },
};
});
this.superCluster.load(points);
}

if (changed) {
this.clusters = this.cluster(input);
this.state = state;
}

return { clusters: this.clusters, changed };
}
}
6 changes: 5 additions & 1 deletion frontend/src/store/googleMapSlice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import {
getGoogleMapClass,
loadGoogleMapsApi,
} from '@/lib/googleMapsAPI-loader';
import { MarkerClusterer } from '@googlemaps/markerclusterer';
import {
MarkerClusterer,
SuperClusterAlgorithm,

Check failure on line 10 in frontend/src/store/googleMapSlice/index.ts

View workflow job for this annotation

GitHub Actions / Lint, Build and Test (frontend)

'SuperClusterAlgorithm' is defined but never used
} from '@googlemaps/markerclusterer';
import {
clustererOptions,
CustomMarkerClusterer,
} from '@/lib/CustomMarkerClusterer';
import { CustomSuperClusterAlgorithm } from '@/lib/CustomSuperCluseterAlgorithm';
import { SuperClusterAlgorithmTest } from '@/lib/SuperClusterAlgorithm';

Check failure on line 17 in frontend/src/store/googleMapSlice/index.ts

View workflow job for this annotation

GitHub Actions / Lint, Build and Test (frontend)

'SuperClusterAlgorithmTest' is defined but never used

export type GoogleMapState = {
googleMap: google.maps.Map | null;
Expand Down

0 comments on commit 3323a2e

Please sign in to comment.