Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
Festivelo_frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Festivelo
Festivelo_frontend
Compare revisions
55e48d5799abfce08397b9a8cd5a681809593f27 to 4ea9143952f32a42e065aef839f61ca0cb299434
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
festivelo/festivelo_frontend
Select target project
No results found
4ea9143952f32a42e065aef839f61ca0cb299434
Select Git revision
Swap
Target
festivelo/festivelo_frontend
Select target project
festivelo/festivelo_frontend
1 result
55e48d5799abfce08397b9a8cd5a681809593f27
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
refactor: enhance map marker handling and clearMap
· ca2ea13b
pjookim
authored
5 months ago
ca2ea13b
Merge remote-tracking branch 'refs/remotes/origin/main'
· 4ea91439
pjookim
authored
5 months ago
4ea91439
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/hooks/useKakaoMap.js
+11
-4
11 additions, 4 deletions
src/hooks/useKakaoMap.js
src/pages/Home.js
+32
-22
32 additions, 22 deletions
src/pages/Home.js
with
43 additions
and
26 deletions
src/hooks/useKakaoMap.js
View file @
4ea91439
...
...
@@ -24,7 +24,10 @@ const UseKakaoMap = (initialLocation) => {
},
[
initialLocation
,
map
]);
const
clearMap
=
useCallback
(()
=>
{
console
.
log
(
'
clearMap1
'
);
if
(
!
map
)
return
;
console
.
log
(
'
clearMap2
'
);
console
.
log
(
markers
);
markers
.
forEach
(
marker
=>
{
if
(
marker
.
marker
)
marker
.
marker
.
setMap
(
null
);
...
...
@@ -42,10 +45,14 @@ const UseKakaoMap = (initialLocation) => {
map
.
infowindow
=
null
;
}
if
(
map
.
clusterer
)
{
map
.
clusterer
.
clear
();
map
.
clusterer
=
null
;
}
const
clusterers
=
map
.
markerClusterers
||
[];
clusterers
.
forEach
(
clusterer
=>
{
if
(
clusterer
)
{
clusterer
.
clear
();
clusterer
.
setMap
(
null
);
}
});
map
.
markerClusterers
=
[];
},
[
map
,
markers
]);
const
loadKakaoMapScript
=
useCallback
(()
=>
{
...
...
This diff is collapsed.
Click to expand it.
src/pages/Home.js
View file @
4ea91439
...
...
@@ -187,15 +187,19 @@ const Home = () => {
setselectedTrip
(
trip
);
clearMap
();
const
newMarkers
=
[];
const
bounds
=
new
window
.
kakao
.
maps
.
LatLngBounds
();
const
linePath
=
[];
const
allPlaces
=
Object
.
values
(
trip
.
plans
)
.
flatMap
(
day
=>
day
.
places
);
const
allPlaces
=
Object
.
values
(
trip
.
plans
).
flatMap
(
day
=>
{
return
day
.
route
.
map
(
routeId
=>
day
.
places
.
find
(
place
=>
place
.
id
===
routeId
)
);
});
if
(
allPlaces
.
length
===
0
)
{
const
geocoder
=
new
window
.
kakao
.
maps
.
services
.
Geocoder
();
geocoder
.
addressSearch
(
trip
.
location
,
(
result
,
status
)
=>
{
if
(
status
===
window
.
kakao
.
maps
.
services
.
Status
.
OK
)
{
const
position
=
new
window
.
kakao
.
maps
.
LatLng
(
...
...
@@ -205,8 +209,6 @@ const Home = () => {
map
.
setCenter
(
position
);
map
.
setLevel
(
8
);
map
.
relayout
();
}
else
{
console
.
error
(
'
주소를 좌표로 변환하는데 실패했습니다.
'
);
}
});
return
;
...
...
@@ -248,14 +250,16 @@ const Home = () => {
}]
});
const
markers
=
allPlaces
.
map
((
place
,
index
)
=>
{
const
markers
=
[];
const
overlayMarkers
=
[];
allPlaces
.
forEach
((
place
,
index
)
=>
{
const
position
=
new
window
.
kakao
.
maps
.
LatLng
(
place
.
coordinates
.
lat
,
place
.
coordinates
.
lng
);
const
marker
=
new
window
.
kakao
.
maps
.
Marker
({
position
});
const
overlayMarker
=
new
window
.
kakao
.
maps
.
Marker
({
position
,
opacity
:
0
...
...
@@ -269,16 +273,18 @@ const Home = () => {
bounds
.
extend
(
position
);
linePath
.
push
(
position
);
markers
.
push
(
marker
);
overlayMarkers
.
push
(
overlayMarker
);
newMarkers
.
push
({
marker
,
overlay
});
return
{
marker
,
overlayMarker
};
});
markerClusterer
.
addMarkers
(
markers
.
map
(
m
=>
m
.
marker
));
overlayClusterer
.
addMarkers
(
markers
.
map
(
m
=>
m
.
overlayMarker
));
markerClusterer
.
addMarkers
(
markers
);
overlayClusterer
.
addMarkers
(
overlayMarkers
);
window
.
kakao
.
maps
.
event
.
addListener
(
markerClusterer
,
'
clusterclick
'
,
(
cluster
)
=>
{
const
level
=
map
.
getLevel
()
-
1
;
map
.
setLevel
(
level
,
{
anchor
:
cluster
.
getCenter
()
});
});
const
polyline
=
new
window
.
kakao
.
maps
.
Polyline
({
path
:
linePath
,
...
...
@@ -290,21 +296,18 @@ const Home = () => {
polyline
.
setMap
(
map
);
map
.
polyline
=
polyline
;
map
.
relayout
();
setMarkers
(
newMarkers
);
map
.
setBounds
(
bounds
);
map
.
relayout
();
window
.
kakao
.
maps
.
event
.
addListener
(
markerClusterer
,
'
clusterclick
'
,
(
cluster
)
=>
{
const
level
=
map
.
getLevel
()
-
1
;
map
.
setLevel
(
level
,
{
anchor
:
cluster
.
getCenter
()
});
});
map
.
markerClusterers
=
[
markerClusterer
,
overlayClusterer
];
setMarkers
(
newMarkers
);
},
[
map
,
clearMap
,
handlePlaceSelect
,
createCustomOverlay
]);
const
handleRouteChange
=
async
(
tripId
,
day
,
newRoute
,
places
,
newName
)
=>
{
try
{
if
(
newName
)
{
// 여행 이름 수정
const
response
=
await
axios
.
put
(
`
${
API_URL
}
/api/trips/trips/
${
tripId
}
`
,
{
name
:
newName
}
...
...
@@ -313,7 +316,6 @@ const Home = () => {
refreshTrips
();
}
}
else
if
(
day
&&
newRoute
)
{
// 기존 경로 수정 로직
const
requestData
=
{
dayKey
:
day
,
places
:
places
,
...
...
@@ -420,6 +422,7 @@ const Home = () => {
const
refreshTrips
=
async
()
=>
{
try
{
clearMap
();
const
token
=
localStorage
.
getItem
(
'
token
'
);
const
response
=
await
axios
.
get
(
`
${
API_URL
}
/api/trips/trips`
,
...
...
@@ -430,6 +433,13 @@ const Home = () => {
}
);
setTrips
(
response
.
data
);
if
(
selectedTrip
)
{
const
updatedTrip
=
response
.
data
.
find
(
trip
=>
trip
.
_id
===
selectedTrip
.
_id
);
if
(
updatedTrip
)
{
handleTripSelect
(
updatedTrip
);
}
}
}
catch
(
error
)
{
if
(
error
.
response
?.
status
===
401
)
{
toast
.
error
(
'
로그인이 필요합니다
'
);
...
...
This diff is collapsed.
Click to expand it.