Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/api/pin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type MapPinPreviewResponse = {
albumImageUrl: string | null;
youtubeVideoId: string;
clipStartMs: number;
hasBookmarkedPlace?: boolean;
};

const toMapPin = (pin: MapPinPreviewResponse): MapPin => ({
Expand All @@ -80,6 +81,7 @@ const toMapPin = (pin: MapPinPreviewResponse): MapPin => ({
introduction: pin.introduction,
youtubeVideoId: pin.youtubeVideoId,
clipStartMs: pin.clipStartMs,
hasBookmarkedPlace: pin.hasBookmarkedPlace ?? false,
});

export type MapPinsResponse = {
Expand Down
3 changes: 3 additions & 0 deletions src/assets/icons/pin-cover-empty.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/assets/icons/pin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 10 additions & 3 deletions src/features/map/components/ClusterMarker.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
const CLUSTER_COUNT_DISPLAY_MAX = 99;
const CLUSTER_BOOKMARKED_COLOR = '#F7FE90';

export type ClusterMarkerProps = {
placeCount: number;
/** 북마크 강조 모드가 켜져 있고 이 클러스터에 북마크된 장소가 포함되어 있을 때 색을 바꾼다. */
isBookmarked?: boolean;
};

export function ClusterMarker({ placeCount }: ClusterMarkerProps) {
export function ClusterMarker({ placeCount, isBookmarked = false }: ClusterMarkerProps) {
const isOverflow = placeCount > CLUSTER_COUNT_DISPLAY_MAX;

return (
<div
className="flex items-center justify-center rounded-full bg-white shadow-[0_4px_4px_rgba(0,0,0,0.25)]"
style={{ width: isOverflow ? 66 : 38, height: isOverflow ? 66 : 38 }}
className="flex items-center justify-center rounded-full shadow-[0_4px_4px_rgba(0,0,0,0.25)]"
style={{
width: isOverflow ? 66 : 38,
height: isOverflow ? 66 : 38,
backgroundColor: isBookmarked ? CLUSTER_BOOKMARKED_COLOR : '#FFFFFF',
}}
>
<span className="head-24-sb text-black">
{isOverflow ? `${CLUSTER_COUNT_DISPLAY_MAX}+` : placeCount}
Expand Down
25 changes: 18 additions & 7 deletions src/features/map/components/MapPinMarker.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import PinIcon from '@/assets/icons/pin.svg?react';
import PinCoverEmptyIcon from '@/assets/icons/pin-cover-empty.svg?react';
import { MapPinMessageBox } from '@/features/map/components/MapPinMessageBox';

const PIN_DEFAULT_COLOR = '#F6F6F6';
const PIN_BOOKMARKED_COLOR = '#F7FE90';
const PIN_COVER_EMPTY_BG = '#888888';

export type MapPinMarkerProps = {
coverUrl?: string;
isSelected?: boolean;
Expand All @@ -11,6 +16,8 @@ export type MapPinMarkerProps = {
onPlay?: () => void;
/** 말풍선(MapPinMessageBox) 노출 여부. isSelected와 별개로, 줌 21 범위에서만 켠다. */
showMessageBubble?: boolean;
/** 북마크 강조 모드가 켜져 있고 이 핀이 북마크된 장소일 때 핀 색을 바꾼다. */
isBookmarked?: boolean;
};

export function MapPinMarker({
Expand All @@ -22,6 +29,7 @@ export function MapPinMarker({
introduction,
onPlay,
showMessageBubble = false,
isBookmarked = false,
}: MapPinMarkerProps) {
return (
<div className="relative cursor-pointer select-none" style={{ width: 63, height: 70 }}>
Expand All @@ -45,30 +53,33 @@ export function MapPinMarker({
role="img"
aria-label="핀 아이콘"
className="pointer-events-none block size-full overflow-visible"
style={
isSelected
style={{
color: isBookmarked ? PIN_BOOKMARKED_COLOR : PIN_DEFAULT_COLOR,
...(isSelected
? {
filter:
'drop-shadow(0px 24px 9.85px rgba(0, 0, 0, 0.5)) drop-shadow(0px 4px 2px rgba(0, 0, 0, 0.25))',
}
: undefined
}
: undefined),
}}
/>

<div
className="pointer-events-none absolute overflow-hidden rounded-full"
className="pointer-events-none absolute flex items-center justify-center overflow-hidden rounded-full"
style={{
left: '49.7%',
top: '36%',
width: 28,
height: 28,
transform: 'translate(-50%, -50%)',
background: coverUrl,
backgroundColor: coverUrl ? undefined : PIN_COVER_EMPTY_BG,
}}
>
{coverUrl ? (
<img src={coverUrl} alt="" draggable={false} className="size-full object-cover" />
) : null}
) : (
<PinCoverEmptyIcon aria-hidden className="h-[13px] w-[8.4px]" />
)}
</div>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions src/features/map/components/MapViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type MapViewerProps = {
onMapDragStart?: () => void;
/** 장소가 1개뿐인 클러스터를 눌러 줌 21로 이동을 마쳤을 때 호출된다. */
onSingleClusterArrive?: (position: MapCoordinate) => void;
/** 북마크 강조 모드 on/off. 켜져 있으면 hasBookmarkedPlace인 핀/클러스터 색이 바뀐다. */
isBookmarkHighlightOn?: boolean;
};

export type MapViewerHandle = {
Expand Down Expand Up @@ -77,6 +79,7 @@ export const MapViewer = forwardRef<MapViewerHandle, MapViewerProps>(function Ma
onMapClick,
onMapDragStart,
onSingleClusterArrive,
isBookmarkHighlightOn = false,
},
ref,
) {
Expand Down Expand Up @@ -126,6 +129,7 @@ export const MapViewer = forwardRef<MapViewerHandle, MapViewerProps>(function Ma
flyTo,
onSelectMapPin,
onPlayPin,
isBookmarkHighlightOn,
});
useClusterOverlays({
mapInstanceRef,
Expand All @@ -135,6 +139,7 @@ export const MapViewer = forwardRef<MapViewerHandle, MapViewerProps>(function Ma
flyTo,
fitToBounds,
onSingleClusterArrive,
isBookmarkHighlightOn,
});
useCoordinateProjection({
mapInstanceRef,
Expand Down
4 changes: 4 additions & 0 deletions src/features/map/constants/devMockMapPins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const DEV_MOCK_MAP_PINS: MapPin[] = [
coverUrl: undefined,
nickname: '냥코',
introduction: '도가니 살리기 위잉잉잉~',
hasBookmarkedPlace: true,
},
{
id: 'dev-mock:2',
Expand All @@ -23,6 +24,7 @@ export const DEV_MOCK_MAP_PINS: MapPin[] = [
coverUrl: undefined,
nickname: '한강러버',
introduction: '야경 보면서 듣기 딱 좋아요',
hasBookmarkedPlace: false,
},
{
id: 'dev-mock:3',
Expand All @@ -31,6 +33,7 @@ export const DEV_MOCK_MAP_PINS: MapPin[] = [
coverUrl: undefined,
nickname: '산책러',
introduction: '퇴근길 산책 플레이리스트',
hasBookmarkedPlace: false,
},
{
id: 'dev-mock:4',
Expand All @@ -39,5 +42,6 @@ export const DEV_MOCK_MAP_PINS: MapPin[] = [
coverUrl: undefined,
nickname: '댄스머신',
introduction: '기분 좋아지는 노래 추천',
hasBookmarkedPlace: true,
},
];
47 changes: 44 additions & 3 deletions src/features/map/hooks/useClusterOverlays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ import type { MapCoordinate, PinCluster, PinClusterLevel } from '../types';
import {
createClusterOverlay,
disposeClusterOverlay,
updateClusterMarker,
type ClusterOverlayEntry,
} from '../utils/mapClusterMarker';
import {
createMapPinOverlay,
disposeMapPinOverlay,
updateMapPinMarker,
type MapPinOverlayEntry,
} from '../utils/mapPinMarker';

// 클러스터 클릭 시, bounds가 한 점으로 퇴화됐는데 장소가 2개 이상인 경우(같은 좌표에
// 여러 장소가 겹친 경우) fitBounds 대신 이동할 다음 단계의 줌 레벨. 각 클러스터
// 레벨이 다음에 어떤 줌 구간으로 이어지는지는 확정된 줌 구간 표를 따른다.
const NEXT_TIER_ZOOM: Record<PinClusterLevel, number> = {
REGION1: 8,
REGION1: 9,
REGION2: 11,
REGION3: 14,
GEOHASH: 20,
Expand Down Expand Up @@ -63,6 +65,8 @@ type UseClusterOverlaysParams = {
fitToBounds: (bounds: google.maps.LatLngBoundsLiteral) => void;
/** 장소 1개짜리 클러스터를 눌러 줌 21 이동을 마쳤을 때 호출된다(그 좌표를 넘겨줌). */
onSingleClusterArrive?: (position: MapCoordinate) => void;
/** 북마크 강조 모드 on/off. 켜져 있으면 hasBookmarkedPlace인 클러스터 색이 바뀐다. */
isBookmarkHighlightOn?: boolean;
};

/**
Expand All @@ -78,12 +82,14 @@ export function useClusterOverlays({
flyTo,
fitToBounds,
onSingleClusterArrive,
isBookmarkHighlightOn = false,
}: UseClusterOverlaysParams) {
const clusterOverlaysRef = useRef<{ key: string; entry: ClusterOverlayEntry }[]>([]);
const singlePlacePinOverlaysRef = useRef<{ key: string; entry: MapPinOverlayEntry }[]>([]);
const flyToRef = useRef(flyTo);
const fitToBoundsRef = useRef(fitToBounds);
const onSingleClusterArriveRef = useRef(onSingleClusterArrive);
const isBookmarkHighlightOnRef = useRef(isBookmarkHighlightOn);
// 소수점 zoom을 그대로 의존성에 넣으면 줌 애니메이션 프레임마다 다시 그려 깜빡이므로,
// 14 문턱을 넘었는지 여부(불리언)만 의존성으로 쓴다.
const showSinglePlaceAsPin = zoom >= SINGLE_PLACE_PIN_MIN_ZOOM;
Expand All @@ -100,6 +106,10 @@ export function useClusterOverlays({
fitToBoundsRef.current = fitToBounds;
}, [fitToBounds]);

useEffect(() => {
isBookmarkHighlightOnRef.current = isBookmarkHighlightOn;
}, [isBookmarkHighlightOn]);

useEffect(() => {
const map = mapInstanceRef.current;
if (!isLoaded || !map) return;
Expand Down Expand Up @@ -157,14 +167,21 @@ export function useClusterOverlays({
});
};

const isBookmarked = isBookmarkHighlightOnRef.current && cluster.hasBookmarkedPlace;

if (isPinMode) {
const entry = createMapPinOverlay({ position, onClick });
const entry = createMapPinOverlay({ position, onClick, isBookmarked });
entry.overlay.setMap(map);
nextPinEntries.push({ key, entry });
return;
}

const entry = createClusterOverlay({ position, placeCount: cluster.placeCount, onClick });
const entry = createClusterOverlay({
position,
placeCount: cluster.placeCount,
onClick,
isBookmarked,
});
entry.overlay.setMap(map);
nextClusterEntries.push({ key, entry });
});
Expand All @@ -177,6 +194,30 @@ export function useClusterOverlays({
singlePlacePinOverlaysRef.current = nextPinEntries;
}, [isLoaded, clusters, showSinglePlaceAsPin, mapInstanceRef]);

// --- 북마크 강조 색상 갱신 ---
// 위 이펙트는 키가 같으면 기존 오버레이를 재사용해 색을 다시 계산하지 않으므로,
// 강조 모드를 켜고 끌 때는 이미 떠 있는 오버레이들의 색만 별도로 갱신한다.
useEffect(() => {
const clusterByKey = new Map(clusters.map((cluster) => [clusterKey(cluster), cluster]));

clusterOverlaysRef.current.forEach(({ key, entry }) => {
const cluster = clusterByKey.get(key);
if (!cluster) return;
updateClusterMarker(entry.mount, {
placeCount: cluster.placeCount,
isBookmarked: isBookmarkHighlightOn && cluster.hasBookmarkedPlace,
});
});

singlePlacePinOverlaysRef.current.forEach(({ key, entry }) => {
const cluster = clusterByKey.get(key);
if (!cluster) return;
updateMapPinMarker(entry.mount, {
isBookmarked: isBookmarkHighlightOn && cluster.hasBookmarkedPlace,
});
});
}, [clusters, isBookmarkHighlightOn]);

// 언마운트될 때만 정리한다 - 위 이펙트는 재실행마다 자체적으로 diff해서 정리한다.
useEffect(() => {
return () => {
Expand Down
12 changes: 11 additions & 1 deletion src/features/map/hooks/useMapPinOverlays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type UseMapPinOverlaysParams = {
flyTo: (position: MapCoordinate, targetZoom: number, onArrive?: () => void) => void;
onSelectMapPin?: (pinId: string) => void;
onPlayPin?: (pinId: string) => void;
/** 북마크 강조 모드 on/off. 켜져 있으면 hasBookmarkedPlace인 핀 색이 바뀐다. */
isBookmarkHighlightOn?: boolean;
};

/** 지도 위 핀(OverlayView)을 렌더링하고, 선택 상태에 따라 강조한다. */
Expand All @@ -36,13 +38,15 @@ export function useMapPinOverlays({
flyTo,
onSelectMapPin,
onPlayPin,
isBookmarkHighlightOn = false,
}: UseMapPinOverlaysParams) {
const mapPinOverlaysRef = useRef<{ id: string; entry: MapPinOverlayEntry }[]>([]);
const onSelectMapPinRef = useRef(onSelectMapPin);
const onPlayPinRef = useRef(onPlayPin);
const selectedMapPinIdRef = useRef(selectedMapPinId);
const playingMapPinIdRef = useRef(playingMapPinId);
const flyToRef = useRef(flyTo);
const isBookmarkHighlightOnRef = useRef(isBookmarkHighlightOn);
// 마커 재생성 이펙트가 zoom에 매 프레임 반응하면 깜빡이므로 최신 값은 ref로 읽는다.
const isAtPinFocusZoomRef = useRef(Math.abs(zoom - PIN_FOCUS_ZOOM) <= ZOOM_EQUALITY_EPSILON);
// 선택 상태 갱신 이펙트는 줌 21 문턱을 넘었는지(불리언)만 의존성으로 쓴다.
Expand All @@ -68,6 +72,10 @@ export function useMapPinOverlays({
flyToRef.current = flyTo;
}, [flyTo]);

useEffect(() => {
isBookmarkHighlightOnRef.current = isBookmarkHighlightOn;
}, [isBookmarkHighlightOn]);

useEffect(() => {
isAtPinFocusZoomRef.current = isAtPinFocusZoom;
}, [isAtPinFocusZoom]);
Expand Down Expand Up @@ -113,6 +121,7 @@ export function useMapPinOverlays({
() => onPlayPinRef.current?.(pin.id),
pin.id === playingId,
pin.id === selectedId && isAtPinFocusZoomRef.current,
isBookmarkHighlightOnRef.current && pin.hasBookmarkedPlace,
),
});
entry.overlay.setMap(map);
Expand Down Expand Up @@ -146,9 +155,10 @@ export function useMapPinOverlays({
() => onPlayPinRef.current?.(pin.id),
id === playingMapPinId,
isSelected && isAtPinFocusZoom,
isBookmarkHighlightOn && pin.hasBookmarkedPlace,
),
);
entry.overlay.setZIndex(isSelected ? 200 : 100);
});
}, [selectedMapPinId, playingMapPinId, mapPins, isAtPinFocusZoom]);
}, [selectedMapPinId, playingMapPinId, mapPins, isAtPinFocusZoom, isBookmarkHighlightOn]);
}
2 changes: 2 additions & 0 deletions src/features/map/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type MapPin = {
introduction: string;
youtubeVideoId?: string;
clipStartMs?: number;
hasBookmarkedPlace: boolean;
};

// 행정구역(REGION1~3) 또는 geohash(GEOHASH) 기준 핀 클러스터
Expand All @@ -58,6 +59,7 @@ export type PinCluster = {
longitude: number;
placeCount: number;
bounds: PinClusterBounds;
hasBookmarkedPlace: boolean;
};

// 현재 위치 마커 기본 색상
Expand Down
4 changes: 4 additions & 0 deletions src/features/map/utils/mapClusterMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const unmountClusterMarker = (mount: HTMLElement) => {
markerRoots.delete(mount);
};

export const updateClusterMarker = (mount: HTMLElement, props: ClusterMarkerProps) => {
renderClusterMarker(mount, props);
};

type ClusterOverlayOptions = {
position: google.maps.LatLngLiteral;
onClick?: () => void;
Expand Down
2 changes: 2 additions & 0 deletions src/features/map/utils/mapPinMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const toMapPinMarkerProps = (
onPlay?: () => void,
isPlaying = false,
showMessageBubble = false,
isBookmarked = false,
): MapPinMarkerProps => ({
coverUrl: pin.coverUrl,
isSelected,
Expand All @@ -25,6 +26,7 @@ export const toMapPinMarkerProps = (
introduction: pin.introduction,
onPlay,
showMessageBubble,
isBookmarked,
});

export const renderMapPinMarker = (mount: HTMLElement, props: MapPinMarkerProps) => {
Expand Down
Loading
Loading