[FAQ] 지도/로컬 API 문의 전 꼭 읽어 주세요.
function updateMarkers() {
const bounds = new kakao.maps.LatLngBounds();
dataRows.forEach((row, index) => {
const latitude = parseFloat(row[4]);
const longitude = parseFloat(row[5]);
if (isNaN(latitude) || isNaN(longitude)) {
console.warn(`Invalid coordinates for row ${index}: [${latitude}, ${longitude}]`);
return;
}
const label = `${row[0]} - ${row[1]}`;
const markerPosition = new kakao.maps.LatLng(latitude, longitude);
const key = `${latitude},${longitude}`;
const isCompleted = row.includes("완료");
if (markerDataMap[key]) {
// Handle duplicate marker
markerDataMap[key].rows.push({ index, row, completed: isCompleted });
const duplicateCount = markerDataMap[key].rows.length;
const markerImageSrc = "https://gobiztrip.synology.me/myproject/images/R_100.png";
markerDataMap[key].marker.setImage(new kakao.maps.MarkerImage(markerImageSrc, getMarkerSize()));
const duplicateLabel = `<div class="label" onclick="handleMarkerClick('${key}')">${label} 외 ${duplicateCount - 1}개</div>`;
markerDataMap[key].overlay.setContent(duplicateLabel);
markerDataMap[key].isDuplicate = true;
if (markerDataMap[key].rows.every(item => item.completed)) {
const completedMarkerImageSrc = "https://gobiztrip.synology.me/myproject/images/Gr_100.png";
markerDataMap[key].marker.setImage(new kakao.maps.MarkerImage(completedMarkerImageSrc, getMarkerSize()));
markerDataMap[key].overlay.setContent(`<div class="label completed">${label} 외 ${duplicateCount - 1}개 (완료)</div>`);
}
} else {
const markerImageSrc = isCompleted
? "https://gobiztrip.synology.me/myproject/images/Gr_100.png"
: "https://gobiztrip.synology.me/myproject/images/G100.png";
const marker = new kakao.maps.Marker({
position: markerPosition,
image: new kakao.maps.MarkerImage(markerImageSrc, getMarkerSize())
});
marker.setMap(map);
markers.push(marker);
// Create label
const labelContent = isCompleted
? `<div class="label completed"><s>${label}</s></div>`
: `<div class="label">${label}</div>`;
const customOverlay = new kakao.maps.CustomOverlay({
content: labelContent,
position: markerPosition,
yAnchor: 2.1,
zIndex: 3,
clickable: true
});
customOverlay.setMap(map);
markerDataMap[key] = { marker, overlay: customOverlay, rows: [{ index, row, completed: isCompleted }] };
// Add click events to marker and overlay
kakao.maps.event.addListener(marker, "click", () => handleMarkerClick(key));
kakao.maps.event.addListener(customOverlay, "click", () => handleMarkerClick(key));
// Zoom-level based visibility
kakao.maps.event.addListener(map, 'zoom_changed', function() {
var level = map.getLevel();
if (level <= 10) {
customOverlay.setMap(map);
} else {
customOverlay.setMap(null);
}
});
}
bounds.extend(markerPosition);
});
if (dataRows.length > 0) {
map.setBounds(bounds);
}
}
마커는 되는데 라벨을 못불러오는것은 왜그런가여 ?