diff --git a/map4.js b/map4.js index 89f0b89..d89b0f3 100644 --- a/map4.js +++ b/map4.js @@ -36,14 +36,18 @@ } // =================================== -// ピンデザインを統一(かわいい青ピン) +// 小型ピンを統一して使う +// 自分 → 緑 +// 他人 → 黄色 // =================================== function createLabeledMarker(lat, lng, name, isSelf) { - const pinColor = isSelf ? "#4ba3ff" : "#58c16b"; + const pinUrl = isSelf + ? "https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-green.png" + : "https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-gold.png"; const iconHtml = `
-
+
${name}
`; @@ -52,8 +56,8 @@ icon: L.divIcon({ className: "custom-pin", html: iconHtml, - iconSize: [1, 1], - iconAnchor: [0, 0] + iconSize: [32, 32], + iconAnchor: [16, 32], }) }); } @@ -77,10 +81,10 @@ maxZoom: 19, }).addTo(map); - // ズームごとにピン縮小(自然な大きさ) + // ズームに応じてピン縮小(自然に) map.on("zoom", () => { const zoom = map.getZoom(); - const scale = zoom / 16; // 基準は16 + const scale = zoom / 16; document.documentElement.style.setProperty("--pin-scale", scale); }); } @@ -104,6 +108,7 @@ // =================================== function renderSelfMarker() { if (selfMarker) map.removeLayer(selfMarker); + selfMarker = createLabeledMarker(lastLat, lastLng, currentUser, true); selfMarker.addTo(map); @@ -125,8 +130,12 @@ li.classList.add(isOnline ? "online" : "offline"); + // ピンの色と合わせる(自分=緑/他人=黄) + const circleColor = (row.device_id === deviceId) ? "#4ba3ff" : "#FFD700"; + const icon = document.createElement("div"); icon.className = "member-icon"; + icon.style.background = circleColor; const name = document.createElement("span"); name.textContent = row.user_name; @@ -222,7 +231,7 @@ document.getElementById("exitBtn").onclick = () => (location.href = "index.html"); - setTimeout(() => map.invalidateSize(), 300); + setTimeout(() => map.invalidateSize(), 400); } window.addEventListener("DOMContentLoaded", main);