Tataaicoltd commited on
Commit
72ceae0
Β·
verified Β·
1 Parent(s): 3904399

Upload admin/gmaps.html with huggingface_hub

Browse files
Files changed (1) hide show
  1. admin/gmaps.html +3 -117
admin/gmaps.html CHANGED
@@ -7,8 +7,6 @@
7
 
8
  <!-- Leaflet CSS -->
9
  <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
10
- <link rel="shortcut icon" href="css/favicon.ico" type="image/x-icon">
11
- <link rel="icon" href="css/favicon.ico" type="image/x-icon">
12
 
13
  <style>
14
  * { box-sizing: border-box; margin: 0; padding: 0; }
@@ -116,28 +114,6 @@
116
  font-size: 16px; color: #555;
117
  }
118
  #loading.hidden { display: none; }
119
-
120
- /* ── Toast notification ── */
121
- #toast {
122
- position: fixed;
123
- bottom: 60px; left: 50%;
124
- transform: translateX(-50%);
125
- background: rgba(0,0,0,.75);
126
- color: #fff;
127
- border-radius: 20px;
128
- padding: 6px 20px;
129
- font-size: 13px;
130
- z-index: 30;
131
- pointer-events: none;
132
- opacity: 0;
133
- transition: opacity .25s;
134
- white-space: nowrap;
135
- }
136
- #toast.show { opacity: 1; }
137
-
138
- /* Dragging cursor on markers */
139
- .leaflet-marker-draggable { cursor: grab !important; }
140
- .leaflet-dragging .leaflet-marker-draggable { cursor: grabbing !important; }
141
  </style>
142
  </head>
143
  <body>
@@ -162,9 +138,6 @@
162
  <!-- Marker count -->
163
  <div id="counter" style="display:none"></div>
164
 
165
- <!-- Toast -->
166
- <div id="toast"></div>
167
-
168
  <!-- Info panel -->
169
  <div id="infoPanel">
170
  <button class="close-btn" id="closeInfo">&times;</button>
@@ -179,7 +152,7 @@
179
  // ══════════════════════════════════════════════════
180
  // CONFIG
181
  // ══════════════════════════════════════════════════
182
- const API = '/api';
183
  const DEFAULT_LAT = 10.8231;
184
  const DEFAULT_LNG = 106.6297;
185
  const DEFAULT_ZOOM = 12;
@@ -191,7 +164,6 @@ let map;
191
  let layerGroup = null; // L.LayerGroup chα»©a toΓ n bα»™ marker
192
  let streetMap = {}; // id β†’ street object
193
  let allStreets = [];
194
- // pos lΖ°u trα»±c tiαΊΏp trΓͺn marker object (marker._pos) trΓ‘nh lα»—i _leaflet_id lazy-assign
195
 
196
  // ══════════════════════════════════════════════════
197
  // HELPERS
@@ -213,16 +185,6 @@ function setCounter(n) {
213
  el.textContent = `${n} Δ‘iểm`;
214
  }
215
 
216
- let _toastTimer = null;
217
- function showToast(msg, duration) {
218
- duration = duration || 2500;
219
- const el = document.getElementById('toast');
220
- el.textContent = msg;
221
- el.classList.add('show');
222
- clearTimeout(_toastTimer);
223
- _toastTimer = setTimeout(() => el.classList.remove('show'), duration);
224
- }
225
-
226
  function hideInfo() {
227
  document.getElementById('infoPanel').style.display = 'none';
228
  }
@@ -276,87 +238,11 @@ function createMarker(pos) {
276
  .filter(Boolean)
277
  .join(', ') || 'β€”';
278
 
279
- const m = L.marker([lat, lng], {
280
- icon: circleIcon('#4285f4'),
281
- title: streetNames,
282
- draggable: true,
283
- });
284
-
285
- // LΖ°u pos trα»±c tiαΊΏp trΓͺn marker β€” trΓ‘nh lα»—i _leaflet_id chΖ°a được assign
286
- m._pos = pos;
287
-
288
- // Tooltip tọa Δ‘α»™ live khi drag
289
- const livePopup = L.popup({ closeButton: false, offset: [0, -10], className: 'coord-popup' });
290
-
291
- m.on('click', () => showInfo(m._pos, streetNames, m));
292
- m.on('dragstart', () => {
293
- m.setIcon(circleIcon('#f4a142'));
294
- hideInfo();
295
- livePopup.setLatLng(m.getLatLng())
296
- .setContent(fmtLatLng(m.getLatLng()))
297
- .openOn(map);
298
- });
299
- m.on('drag', () => {
300
- livePopup.setLatLng(m.getLatLng())
301
- .setContent(fmtLatLng(m.getLatLng()));
302
- });
303
- m.on('dragend', () => {
304
- map.closePopup(livePopup);
305
- onMarkerDragEnd(m);
306
- });
307
-
308
  return m;
309
  }
310
 
311
- // ══════════════════════════════════════════════════
312
- // DRAG β†’ UPDATE DB (dΓΉng tọa Δ‘α»™ drag thα»±c, khΓ΄ng snap OSM)
313
- // ══════════════════════════════════════════════════
314
- function fmtLatLng(latlng) {
315
- return `${latlng.lat.toFixed(6)}, ${latlng.lng.toFixed(6)}`;
316
- }
317
-
318
- async function onMarkerDragEnd(marker) {
319
- const { lat, lng } = marker.getLatLng();
320
- const pos = marker._pos;
321
- if (!pos || !pos.id) {
322
- console.warn('[dragend] pos not found on marker', marker);
323
- marker.setIcon(circleIcon('#4285f4'));
324
- return;
325
- }
326
-
327
- showToast('Đang lΖ°u…', 30000);
328
-
329
- try {
330
- const resp = await fetch(`${API}/positions/${pos.id}`, {
331
- method: 'PUT',
332
- headers: { 'Content-Type': 'application/json' },
333
- body: JSON.stringify({ y: lat, x: lng }),
334
- });
335
- if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
336
- const updated = await resp.json();
337
-
338
- // CαΊ­p nhαΊ­t local state
339
- pos.y = updated.y ?? lat;
340
- pos.x = updated.x ?? lng;
341
- marker._pos = pos;
342
-
343
- marker.setIcon(circleIcon('#34a853'));
344
- showToast(`βœ“ ${fmtLatLng({ lat: pos.y, lng: pos.x })}`);
345
- setTimeout(() => marker.setIcon(circleIcon('#4285f4')), 2000);
346
-
347
- // Mở lαΊ‘i info panel vα»›i tọa Δ‘α»™ mα»›i
348
- const streetNames = (pos.streets || [])
349
- .map(id => streetMap[id]?.name).filter(Boolean).join(', ') || 'β€”';
350
- showInfo(pos, streetNames, marker);
351
-
352
- } catch (e) {
353
- console.error('onMarkerDragEnd', e);
354
- marker.setIcon(circleIcon('#ea4335'));
355
- showToast('Lα»—i khi lΖ°u vα»‹ trΓ­ mα»›i');
356
- setTimeout(() => marker.setIcon(circleIcon('#4285f4')), 2000);
357
- }
358
- }
359
-
360
  // ══════════════════════════════════════════════════
361
  // LOAD ALL POSITIONS FROM DB
362
  // ══════════════════════════════════════════════════
 
7
 
8
  <!-- Leaflet CSS -->
9
  <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
 
 
10
 
11
  <style>
12
  * { box-sizing: border-box; margin: 0; padding: 0; }
 
114
  font-size: 16px; color: #555;
115
  }
116
  #loading.hidden { display: none; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  </style>
118
  </head>
119
  <body>
 
138
  <!-- Marker count -->
139
  <div id="counter" style="display:none"></div>
140
 
 
 
 
141
  <!-- Info panel -->
142
  <div id="infoPanel">
143
  <button class="close-btn" id="closeInfo">&times;</button>
 
152
  // ══════════════════════════════════════════════════
153
  // CONFIG
154
  // ══════════════════════════════════════════════════
155
+ const API = location.hostname === 'localhost' ? 'http://localhost:4000/api' : '/api';
156
  const DEFAULT_LAT = 10.8231;
157
  const DEFAULT_LNG = 106.6297;
158
  const DEFAULT_ZOOM = 12;
 
164
  let layerGroup = null; // L.LayerGroup chα»©a toΓ n bα»™ marker
165
  let streetMap = {}; // id β†’ street object
166
  let allStreets = [];
 
167
 
168
  // ══════════════════════════════════════════════════
169
  // HELPERS
 
185
  el.textContent = `${n} Δ‘iểm`;
186
  }
187
 
 
 
 
 
 
 
 
 
 
 
188
  function hideInfo() {
189
  document.getElementById('infoPanel').style.display = 'none';
190
  }
 
238
  .filter(Boolean)
239
  .join(', ') || 'β€”';
240
 
241
+ const m = L.marker([lat, lng], { icon: circleIcon('#4285f4'), title: streetNames });
242
+ m.on('click', () => showInfo(pos, streetNames, m));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  return m;
244
  }
245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  // ══════════════════════════════════════════════════
247
  // LOAD ALL POSITIONS FROM DB
248
  // ══════════════════════════════════════════════════