Spaces:
Running
Running
Update index.html
Browse files- index.html +54 -52
index.html
CHANGED
|
@@ -58,11 +58,6 @@ body::-webkit-scrollbar-thumb {
|
|
| 58 |
<body>
|
| 59 |
<div id="loading">Loading...</div>
|
| 60 |
<img src="https://lh3.googleusercontent.com/d/1Wo9oLj4D6JEsT_MWUZ4VyaIy10uLN3q0" />
|
| 61 |
-
<div id="map-controls" style="position: absolute; top: 10px; left: 10px; z-index: 1000;">
|
| 62 |
-
<button id="add-marker-btn" style="margin-bottom: 5px; padding: 10px; border: none; background-color: #007bff; color: #fff; font-size: 14px; border-radius: 4px; cursor: pointer;">新しくマーカーを追加</button>
|
| 63 |
-
<button id="edit-marker-btn" style="padding: 10px; border: none; background-color: #007bff; color: #fff; font-size: 14px; border-radius: 4px; cursor: pointer;">マーカーを編集</button>
|
| 64 |
-
</div>
|
| 65 |
-
|
| 66 |
<div id="map" style="width:90%; margin:5%;"></div>
|
| 67 |
<div id="marker-editor">
|
| 68 |
<h3>マーカーを編集</h3>
|
|
@@ -125,53 +120,6 @@ body::-webkit-scrollbar-thumb {
|
|
| 125 |
|
| 126 |
|
| 127 |
<script>
|
| 128 |
-
// 「新しくマーカーを追加」ボタンの動作
|
| 129 |
-
document.getElementById("add-marker-btn").addEventListener("click", function () {
|
| 130 |
-
map.on("click", function addMarkerHandler(e) {
|
| 131 |
-
const latlng = e.latlng;
|
| 132 |
-
const newMarker = L.marker(latlng).addTo(map);
|
| 133 |
-
newMarker.bindPopup("新しいマーカー");
|
| 134 |
-
newMarker.bindTooltip("新しいマーカーのツールチップ");
|
| 135 |
-
|
| 136 |
-
// マーカー編集可能にする
|
| 137 |
-
newMarker.on("mouseover", function () {
|
| 138 |
-
hoveredMarker = newMarker;
|
| 139 |
-
});
|
| 140 |
-
newMarker.on("mouseout", function () {
|
| 141 |
-
if (hoveredMarker === newMarker) hoveredMarker = null;
|
| 142 |
-
});
|
| 143 |
-
|
| 144 |
-
// 編集パネルを開く
|
| 145 |
-
openEditor(newMarker);
|
| 146 |
-
|
| 147 |
-
// 一度クリックでイベント解除
|
| 148 |
-
map.off("click", addMarkerHandler);
|
| 149 |
-
|
| 150 |
-
// マーカー保存
|
| 151 |
-
saveMapToStorage();
|
| 152 |
-
});
|
| 153 |
-
});
|
| 154 |
-
|
| 155 |
-
// 「マーカーを編集」ボタンの動作
|
| 156 |
-
document.getElementById("edit-marker-btn").addEventListener("click", function () {
|
| 157 |
-
map.on("click", function editMarkerHandler(e) {
|
| 158 |
-
const nearbyMarkers = [];
|
| 159 |
-
map.eachLayer(function (layer) {
|
| 160 |
-
if (layer instanceof L.Marker) {
|
| 161 |
-
if (map.distance(e.latlng, layer.getLatLng()) < 20) {
|
| 162 |
-
nearbyMarkers.push(layer);
|
| 163 |
-
}
|
| 164 |
-
}
|
| 165 |
-
});
|
| 166 |
-
|
| 167 |
-
if (nearbyMarkers.length > 0) {
|
| 168 |
-
const markerToEdit = nearbyMarkers[0];
|
| 169 |
-
openEditor(markerToEdit);
|
| 170 |
-
map.off("click", editMarkerHandler); // 一度クリックでイベント解除
|
| 171 |
-
}
|
| 172 |
-
});
|
| 173 |
-
});
|
| 174 |
-
|
| 175 |
|
| 176 |
function saveMapToStorage() {
|
| 177 |
const markers = [];
|
|
@@ -558,6 +506,60 @@ map.on("contextmenu", function (e) {
|
|
| 558 |
openEditor(clickedMarkers[0]);
|
| 559 |
}
|
| 560 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
|
| 562 |
// マップが動いたときに保存
|
| 563 |
</script>
|
|
|
|
| 58 |
<body>
|
| 59 |
<div id="loading">Loading...</div>
|
| 60 |
<img src="https://lh3.googleusercontent.com/d/1Wo9oLj4D6JEsT_MWUZ4VyaIy10uLN3q0" />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
<div id="map" style="width:90%; margin:5%;"></div>
|
| 62 |
<div id="marker-editor">
|
| 63 |
<h3>マーカーを編集</h3>
|
|
|
|
| 120 |
|
| 121 |
|
| 122 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
function saveMapToStorage() {
|
| 125 |
const markers = [];
|
|
|
|
| 506 |
openEditor(clickedMarkers[0]);
|
| 507 |
}
|
| 508 |
});
|
| 509 |
+
// ボタンを配置するコンテナを作成
|
| 510 |
+
const buttonContainer = document.createElement("div");
|
| 511 |
+
buttonContainer.style.position = "absolute";
|
| 512 |
+
buttonContainer.style.top = "10px";
|
| 513 |
+
buttonContainer.style.left = "10px";
|
| 514 |
+
buttonContainer.style.zIndex = "1000";
|
| 515 |
+
buttonContainer.style.display = "flex";
|
| 516 |
+
buttonContainer.style.gap = "10px";
|
| 517 |
+
document.body.appendChild(buttonContainer);
|
| 518 |
+
|
| 519 |
+
// 「新しくマーカーを追加」ボタンを作成
|
| 520 |
+
const addMarkerButton = document.createElement("button");
|
| 521 |
+
addMarkerButton.textContent = "新しくマーカーを追加";
|
| 522 |
+
addMarkerButton.style.padding = "10px";
|
| 523 |
+
addMarkerButton.style.border = "none";
|
| 524 |
+
addMarkerButton.style.borderRadius = "5px";
|
| 525 |
+
addMarkerButton.style.background = "#007BFF";
|
| 526 |
+
addMarkerButton.style.color = "white";
|
| 527 |
+
addMarkerButton.style.cursor = "pointer";
|
| 528 |
+
addMarkerButton.addEventListener("click", () => {
|
| 529 |
+
const center = map.getCenter();
|
| 530 |
+
const newMarker = L.marker(center).addTo(map);
|
| 531 |
+
newMarker.bindPopup("新しいマーカー").openPopup();
|
| 532 |
+
newMarker.bindTooltip("新しいマーカーのツールチップ");
|
| 533 |
+
newMarker.on("mouseover", function () {
|
| 534 |
+
hoveredMarker = newMarker;
|
| 535 |
+
});
|
| 536 |
+
newMarker.on("mouseout", function () {
|
| 537 |
+
if (hoveredMarker === newMarker) {
|
| 538 |
+
hoveredMarker = null;
|
| 539 |
+
}
|
| 540 |
+
});
|
| 541 |
+
saveMapToStorage();
|
| 542 |
+
});
|
| 543 |
+
buttonContainer.appendChild(addMarkerButton);
|
| 544 |
+
|
| 545 |
+
// 「マーカーを編集」ボタンを作成
|
| 546 |
+
const editMarkerButton = document.createElement("button");
|
| 547 |
+
editMarkerButton.textContent = "マーカーを編集";
|
| 548 |
+
editMarkerButton.style.padding = "10px";
|
| 549 |
+
editMarkerButton.style.border = "none";
|
| 550 |
+
editMarkerButton.style.borderRadius = "5px";
|
| 551 |
+
editMarkerButton.style.background = "#28A745";
|
| 552 |
+
editMarkerButton.style.color = "white";
|
| 553 |
+
editMarkerButton.style.cursor = "pointer";
|
| 554 |
+
editMarkerButton.addEventListener("click", () => {
|
| 555 |
+
if (hoveredMarker) {
|
| 556 |
+
openEditor(hoveredMarker);
|
| 557 |
+
} else {
|
| 558 |
+
alert("編集するマーカーを選択してください。");
|
| 559 |
+
}
|
| 560 |
+
});
|
| 561 |
+
buttonContainer.appendChild(editMarkerButton);
|
| 562 |
+
|
| 563 |
|
| 564 |
// マップが動いたときに保存
|
| 565 |
</script>
|