mistpe commited on
Commit
dbc5392
·
verified ·
1 Parent(s): b448df7

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +30 -29
index.html CHANGED
@@ -34,7 +34,7 @@
34
  }
35
 
36
  .leaflet-tile-container img {
37
- opacity: 0.6 !important;
38
  filter: grayscale(100%) brightness(0) invert(1) !important;
39
  }
40
 
@@ -251,6 +251,7 @@
251
  let lastPosition = null;
252
  let lastUpdateTime = 0;
253
  const updateInterval = 1000;
 
254
 
255
  function initSocket() {
256
  socket = io();
@@ -336,24 +337,18 @@
336
  icon: createUserIcon(username)
337
  }).addTo(map);
338
  map.setView([latitude, longitude], 16);
339
- lastPosition = newPosition;
340
  } else {
341
- if (lastPosition) {
342
- const distance = map.distance(
343
- [lastPosition.lat, lastPosition.lng],
344
- [latitude, longitude]
345
- );
346
-
347
- // Only create footprints if moved more than 2 meters
348
- if (distance > 2) {
349
- const angle = getAngle(lastPosition, newPosition);
350
- placeFootprint(newPosition, angle);
351
- lastPosition = newPosition;
352
- }
353
- }
354
  userMarker.setLatLng([latitude, longitude]);
 
 
 
 
 
355
  }
356
 
 
 
 
357
  socket.emit('update_location', {
358
  username: username,
359
  location: newPosition
@@ -364,26 +359,32 @@
364
  for (const [name, data] of Object.entries(users)) {
365
  if (name === username) continue;
366
 
 
 
367
  if (!otherUsers[name]) {
368
- otherUsers[name] = L.marker([data.location.lat, data.location.lng], {
369
- icon: createUserIcon(name)
370
- }).addTo(map);
 
 
 
371
  } else {
372
- const oldPos = otherUsers[name].getLatLng();
373
- const newPos = L.latLng(data.location.lat, data.location.lng);
374
- otherUsers[name].setLatLng(newPos);
375
-
376
- const angle = getAngle(
377
- { lat: oldPos.lat, lng: oldPos.lng },
378
- { lat: newPos.lat, lng: newPos.lng }
379
- );
380
- placeFootprint(data.location, angle);
381
  }
 
 
382
  }
383
 
 
384
  for (const name of Object.keys(otherUsers)) {
385
  if (!users[name]) {
386
- map.removeLayer(otherUsers[name]);
387
  delete otherUsers[name];
388
  }
389
  }
@@ -391,7 +392,7 @@
391
 
392
  function removeUser(username) {
393
  if (otherUsers[username]) {
394
- map.removeLayer(otherUsers[username]);
395
  delete otherUsers[username];
396
  }
397
  }
 
34
  }
35
 
36
  .leaflet-tile-container img {
37
+ opacity: 0.4 !important;
38
  filter: grayscale(100%) brightness(0) invert(1) !important;
39
  }
40
 
 
251
  let lastPosition = null;
252
  let lastUpdateTime = 0;
253
  const updateInterval = 1000;
254
+ let isInitialLoad = true;
255
 
256
  function initSocket() {
257
  socket = io();
 
337
  icon: createUserIcon(username)
338
  }).addTo(map);
339
  map.setView([latitude, longitude], 16);
 
340
  } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
341
  userMarker.setLatLng([latitude, longitude]);
342
+ // 只在非初次加载且有上一个位置时创建脚印
343
+ if (!isInitialLoad && lastPosition) {
344
+ const angle = getAngle(lastPosition, newPosition);
345
+ placeFootprint(newPosition, angle);
346
+ }
347
  }
348
 
349
+ isInitialLoad = false;
350
+ lastPosition = newPosition;
351
+
352
  socket.emit('update_location', {
353
  username: username,
354
  location: newPosition
 
359
  for (const [name, data] of Object.entries(users)) {
360
  if (name === username) continue;
361
 
362
+ const newPos = { lat: data.location.lat, lng: data.location.lng };
363
+
364
  if (!otherUsers[name]) {
365
+ otherUsers[name] = {
366
+ marker: L.marker([newPos.lat, newPos.lng], {
367
+ icon: createUserIcon(name)
368
+ }).addTo(map),
369
+ lastPosition: null
370
+ };
371
  } else {
372
+ const oldPos = otherUsers[name].lastPosition;
373
+ otherUsers[name].marker.setLatLng([newPos.lat, newPos.lng]);
374
+
375
+ if (oldPos) {
376
+ const angle = getAngle(oldPos, newPos);
377
+ placeFootprint(newPos, angle);
378
+ }
 
 
379
  }
380
+
381
+ otherUsers[name].lastPosition = newPos;
382
  }
383
 
384
+ // 清理断开连接的用户
385
  for (const name of Object.keys(otherUsers)) {
386
  if (!users[name]) {
387
+ map.removeLayer(otherUsers[name].marker);
388
  delete otherUsers[name];
389
  }
390
  }
 
392
 
393
  function removeUser(username) {
394
  if (otherUsers[username]) {
395
+ map.removeLayer(otherUsers[name].marker);
396
  delete otherUsers[username];
397
  }
398
  }