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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="zh-CN">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
| 6 |
+
<title>地图打卡系统</title>
|
| 7 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.css" />
|
| 8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/leaflet.js"></script>
|
| 9 |
+
<style>
|
| 10 |
+
* {
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
box-sizing: border-box;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
body {
|
| 17 |
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
#map {
|
| 21 |
+
width: 100%;
|
| 22 |
+
height: 100vh;
|
| 23 |
+
position: relative;
|
| 24 |
+
z-index: 1;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
.toolbar {
|
| 28 |
+
position: fixed;
|
| 29 |
+
bottom: 20px;
|
| 30 |
+
left: 50%;
|
| 31 |
+
transform: translateX(-50%);
|
| 32 |
+
background: white;
|
| 33 |
+
padding: 10px 20px;
|
| 34 |
+
border-radius: 20px;
|
| 35 |
+
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
| 36 |
+
display: flex;
|
| 37 |
+
gap: 10px;
|
| 38 |
+
z-index: 1000;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.button {
|
| 42 |
+
padding: 8px 16px;
|
| 43 |
+
border: none;
|
| 44 |
+
border-radius: 15px;
|
| 45 |
+
background: #4CAF50;
|
| 46 |
+
color: white;
|
| 47 |
+
font-size: 14px;
|
| 48 |
+
cursor: pointer;
|
| 49 |
+
transition: background-color 0.3s;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
.button:hover {
|
| 53 |
+
background: #45a049;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
.checkin-list {
|
| 57 |
+
position: fixed;
|
| 58 |
+
top: 10px;
|
| 59 |
+
right: 10px;
|
| 60 |
+
background: white;
|
| 61 |
+
padding: 10px;
|
| 62 |
+
border-radius: 10px;
|
| 63 |
+
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
| 64 |
+
max-height: 50vh;
|
| 65 |
+
overflow-y: auto;
|
| 66 |
+
z-index: 1000;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
.checkin-item {
|
| 70 |
+
margin-bottom: 8px;
|
| 71 |
+
padding: 8px;
|
| 72 |
+
background: #f5f5f5;
|
| 73 |
+
border-radius: 5px;
|
| 74 |
+
font-size: 12px;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
.dialog {
|
| 78 |
+
display: none;
|
| 79 |
+
position: fixed;
|
| 80 |
+
top: 50%;
|
| 81 |
+
left: 50%;
|
| 82 |
+
transform: translate(-50%, -50%);
|
| 83 |
+
background: white;
|
| 84 |
+
padding: 20px;
|
| 85 |
+
border-radius: 10px;
|
| 86 |
+
box-shadow: 0 2px 20px rgba(0,0,0,0.2);
|
| 87 |
+
z-index: 1000;
|
| 88 |
+
width: 80%;
|
| 89 |
+
max-width: 300px;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
.dialog input {
|
| 93 |
+
width: 100%;
|
| 94 |
+
padding: 8px;
|
| 95 |
+
margin: 10px 0;
|
| 96 |
+
border: 1px solid #ddd;
|
| 97 |
+
border-radius: 5px;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
.dialog-buttons {
|
| 101 |
+
display: flex;
|
| 102 |
+
justify-content: flex-end;
|
| 103 |
+
gap: 10px;
|
| 104 |
+
margin-top: 15px;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
.overlay {
|
| 108 |
+
display: none;
|
| 109 |
+
position: fixed;
|
| 110 |
+
top: 0;
|
| 111 |
+
left: 0;
|
| 112 |
+
right: 0;
|
| 113 |
+
bottom: 0;
|
| 114 |
+
background: rgba(0,0,0,0.5);
|
| 115 |
+
z-index: 999;
|
| 116 |
+
}
|
| 117 |
+
</style>
|
| 118 |
+
</head>
|
| 119 |
+
<body>
|
| 120 |
+
<div id="map"></div>
|
| 121 |
+
|
| 122 |
+
<div class="toolbar">
|
| 123 |
+
<button class="button" onclick="getCurrentLocation()">定位</button>
|
| 124 |
+
<button class="button" onclick="startCheckin()">打卡</button>
|
| 125 |
+
<button class="button" onclick="toggleCheckinList()">记录</button>
|
| 126 |
+
</div>
|
| 127 |
+
|
| 128 |
+
<div class="checkin-list" id="checkinList" style="display: none;">
|
| 129 |
+
<h3>打卡记录</h3>
|
| 130 |
+
<div id="checkinRecords"></div>
|
| 131 |
+
</div>
|
| 132 |
+
|
| 133 |
+
<div class="overlay" id="overlay"></div>
|
| 134 |
+
<div class="dialog" id="checkinDialog">
|
| 135 |
+
<h3>添加打卡记录</h3>
|
| 136 |
+
<input type="text" id="checkinNote" placeholder="添加备注...">
|
| 137 |
+
<div class="dialog-buttons">
|
| 138 |
+
<button class="button" onclick="cancelCheckin()">取消</button>
|
| 139 |
+
<button class="button" onclick="saveCheckin()">保存</button>
|
| 140 |
+
</div>
|
| 141 |
+
</div>
|
| 142 |
+
|
| 143 |
+
<script>
|
| 144 |
+
let map;
|
| 145 |
+
let marker;
|
| 146 |
+
let checkinLocation;
|
| 147 |
+
const STORAGE_KEY = 'mapCheckins';
|
| 148 |
+
|
| 149 |
+
// 初始化地图
|
| 150 |
+
function initMap() {
|
| 151 |
+
map = L.map('map').setView([39.9042, 116.4074], 11);
|
| 152 |
+
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
| 153 |
+
attribution: '© OpenStreetMap contributors'
|
| 154 |
+
}).addTo(map);
|
| 155 |
+
|
| 156 |
+
// 从本地存储加载打卡记录并显示标记
|
| 157 |
+
loadCheckins();
|
| 158 |
+
|
| 159 |
+
// 添加点击事件监听
|
| 160 |
+
map.on('click', function(e) {
|
| 161 |
+
checkinLocation = e.latlng;
|
| 162 |
+
if (marker) {
|
| 163 |
+
marker.setLatLng(checkinLocation);
|
| 164 |
+
} else {
|
| 165 |
+
marker = L.marker(checkinLocation).addTo(map);
|
| 166 |
+
}
|
| 167 |
+
});
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
// 获取当前位置
|
| 171 |
+
function getCurrentLocation() {
|
| 172 |
+
if (navigator.geolocation) {
|
| 173 |
+
navigator.geolocation.getCurrentPosition(
|
| 174 |
+
function(position) {
|
| 175 |
+
const lat = position.coords.latitude;
|
| 176 |
+
const lng = position.coords.longitude;
|
| 177 |
+
checkinLocation = L.latLng(lat, lng);
|
| 178 |
+
|
| 179 |
+
map.setView(checkinLocation, 15);
|
| 180 |
+
|
| 181 |
+
if (marker) {
|
| 182 |
+
marker.setLatLng(checkinLocation);
|
| 183 |
+
} else {
|
| 184 |
+
marker = L.marker(checkinLocation).addTo(map);
|
| 185 |
+
}
|
| 186 |
+
},
|
| 187 |
+
function(error) {
|
| 188 |
+
alert('无法获取位置:' + error.message);
|
| 189 |
+
},
|
| 190 |
+
{
|
| 191 |
+
enableHighAccuracy: true,
|
| 192 |
+
timeout: 5000,
|
| 193 |
+
maximumAge: 0
|
| 194 |
+
}
|
| 195 |
+
);
|
| 196 |
+
} else {
|
| 197 |
+
alert('您的浏览器不支持地理定位');
|
| 198 |
+
}
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
// 开始打卡
|
| 202 |
+
function startCheckin() {
|
| 203 |
+
if (!checkinLocation) {
|
| 204 |
+
alert('请先在地图上选择位置或使用定位!');
|
| 205 |
+
return;
|
| 206 |
+
}
|
| 207 |
+
document.getElementById('overlay').style.display = 'block';
|
| 208 |
+
document.getElementById('checkinDialog').style.display = 'block';
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
// 取消打卡
|
| 212 |
+
function cancelCheckin() {
|
| 213 |
+
document.getElementById('overlay').style.display = 'none';
|
| 214 |
+
document.getElementById('checkinDialog').style.display = 'none';
|
| 215 |
+
document.getElementById('checkinNote').value = '';
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
// 保存打卡记录
|
| 219 |
+
function saveCheckin() {
|
| 220 |
+
const note = document.getElementById('checkinNote').value;
|
| 221 |
+
const checkin = {
|
| 222 |
+
location: {
|
| 223 |
+
lat: checkinLocation.lat,
|
| 224 |
+
lng: checkinLocation.lng
|
| 225 |
+
},
|
| 226 |
+
note: note,
|
| 227 |
+
timestamp: new Date().toLocaleString()
|
| 228 |
+
};
|
| 229 |
+
|
| 230 |
+
let checkins = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
|
| 231 |
+
checkins.push(checkin);
|
| 232 |
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(checkins));
|
| 233 |
+
|
| 234 |
+
// 添加新标记
|
| 235 |
+
L.marker([checkin.location.lat, checkin.location.lng])
|
| 236 |
+
.bindPopup(note)
|
| 237 |
+
.addTo(map);
|
| 238 |
+
|
| 239 |
+
cancelCheckin();
|
| 240 |
+
updateCheckinList();
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
// 加载已有的打卡记录
|
| 244 |
+
function loadCheckins() {
|
| 245 |
+
const checkins = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
|
| 246 |
+
checkins.forEach(checkin => {
|
| 247 |
+
L.marker([checkin.location.lat, checkin.location.lng])
|
| 248 |
+
.bindPopup(checkin.note)
|
| 249 |
+
.addTo(map);
|
| 250 |
+
});
|
| 251 |
+
updateCheckinList();
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
// 更新打卡记录列表
|
| 255 |
+
function updateCheckinList() {
|
| 256 |
+
const checkins = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
|
| 257 |
+
const recordsContainer = document.getElementById('checkinRecords');
|
| 258 |
+
recordsContainer.innerHTML = '';
|
| 259 |
+
|
| 260 |
+
checkins.reverse().forEach(checkin => {
|
| 261 |
+
const item = document.createElement('div');
|
| 262 |
+
item.className = 'checkin-item';
|
| 263 |
+
item.innerHTML = `
|
| 264 |
+
<div>${checkin.note}</div>
|
| 265 |
+
<div style="color: #666; font-size: 11px;">${checkin.timestamp}</div>
|
| 266 |
+
`;
|
| 267 |
+
recordsContainer.appendChild(item);
|
| 268 |
+
});
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
// 切换打卡记录列表显示状态
|
| 272 |
+
function toggleCheckinList() {
|
| 273 |
+
const list = document.getElementById('checkinList');
|
| 274 |
+
list.style.display = list.style.display === 'none' ? 'block' : 'none';
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
// 初始化地图
|
| 278 |
+
initMap();
|
| 279 |
+
</script>
|
| 280 |
+
</body>
|
| 281 |
+
</html>
|