Auto refresh and static history json
This commit is contained in:
@@ -6,6 +6,21 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
var logsData = JSON.parse(telemetryEl.getAttribute('data-logs') || '[]');
|
var logsData = JSON.parse(telemetryEl.getAttribute('data-logs') || '[]');
|
||||||
var googleMapsApiKey = telemetryEl.getAttribute('data-gmaps-key') || '';
|
var googleMapsApiKey = telemetryEl.getAttribute('data-gmaps-key') || '';
|
||||||
|
|
||||||
|
// Arka planda sunucudan JSON rotasını çek
|
||||||
|
fetch('/mymach_fleet_intelligence/static/src/data/history.json?t=' + new Date().getTime())
|
||||||
|
.then(function(res) {
|
||||||
|
if (!res.ok) throw new Error('History not found');
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.then(function(historyData) {
|
||||||
|
initDashboard(historyData);
|
||||||
|
})
|
||||||
|
.catch(function(e) {
|
||||||
|
// Dosya yoksa veya hata varsa boş rotayla başlat
|
||||||
|
initDashboard([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
function initDashboard(serverHistory) {
|
||||||
var map;
|
var map;
|
||||||
var activePolylines = [];
|
var activePolylines = [];
|
||||||
var activeMarkers = [];
|
var activeMarkers = [];
|
||||||
@@ -43,32 +58,6 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mavi Başlangıç İğnesi (Google Maps Stilinde)
|
|
||||||
function createBlueStartIcon() {
|
|
||||||
return L.divIcon({
|
|
||||||
className: 'custom-blue-start-marker',
|
|
||||||
html: '<div style="position: relative;">' +
|
|
||||||
'<div style="background: #2563eb; border: 2px solid white; width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); box-shadow: 0 4px 14px rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center;">' +
|
|
||||||
'<div style="background: white; width: 9px; height: 9px; border-radius: 50%; transform: rotate(45deg);"></div>' +
|
|
||||||
'</div></div>',
|
|
||||||
iconSize: [26, 26],
|
|
||||||
iconAnchor: [13, 26]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kırmızı Bitiş Hedef İğnesi (Google Maps Stilinde)
|
|
||||||
function createRedEndIcon() {
|
|
||||||
return L.divIcon({
|
|
||||||
className: 'custom-red-end-marker',
|
|
||||||
html: '<div style="position: relative;">' +
|
|
||||||
'<div style="background: #ef4444; border: 2px solid white; width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); box-shadow: 0 4px 14px rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center;">' +
|
|
||||||
'<div style="background: white; width: 9px; height: 9px; border-radius: 50%; transform: rotate(45deg);"></div>' +
|
|
||||||
'</div></div>',
|
|
||||||
iconSize: [26, 26],
|
|
||||||
iconAnchor: [13, 26]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Yol Üzeri Türkçe Çağrı Kutucuğu (Callout Badge)
|
// Yol Üzeri Türkçe Çağrı Kutucuğu (Callout Badge)
|
||||||
function createCalloutIcon(text, bgHex) {
|
function createCalloutIcon(text, bgHex) {
|
||||||
var bg = bgHex || '#2563eb';
|
var bg = bgHex || '#2563eb';
|
||||||
@@ -181,9 +170,6 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
if (allPts.length > 0) {
|
if (allPts.length > 0) {
|
||||||
var startPt = greenPts[0] || allPts[0];
|
var startPt = greenPts[0] || allPts[0];
|
||||||
var endPt = redPts.length > 0 ? redPts[redPts.length - 1] : (greenPts[greenPts.length - 1] || allPts[allPts.length - 1]);
|
var endPt = redPts.length > 0 ? redPts[redPts.length - 1] : (greenPts[greenPts.length - 1] || allPts[allPts.length - 1]);
|
||||||
var mStart = new google.maps.Marker({ position: {lat: startPt[0], lng: startPt[1]}, map: map, title: "Başlangıç Noktası" });
|
|
||||||
var mEnd = new google.maps.Marker({ position: {lat: endPt[0], lng: endPt[1]}, map: map, title: vehicle.destination });
|
|
||||||
activeMarkers.push(mStart, mEnd);
|
|
||||||
|
|
||||||
var bounds = new google.maps.LatLngBounds();
|
var bounds = new google.maps.LatLngBounds();
|
||||||
allPts.forEach(function(p) { bounds.extend({lat: p[0], lng: p[1]}); });
|
allPts.forEach(function(p) { bounds.extend({lat: p[0], lng: p[1]}); });
|
||||||
@@ -211,6 +197,10 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var allPts = greenPts.concat(redPts);
|
var allPts = greenPts.concat(redPts);
|
||||||
|
if (allPts.length > 0) {
|
||||||
|
var startPt = greenPts[0] || allPts[0];
|
||||||
|
var endPt = redPts.length > 0 ? redPts[redPts.length - 1] : (greenPts[greenPts.length - 1] || allPts[allPts.length - 1]);
|
||||||
|
|
||||||
// Başlangıç ve Bitiş İğnelerini (Mavi/Kırmızı) Canlı Radarda Gizliyoruz (Sadece araba ve çizgi görünecek)
|
// Başlangıç ve Bitiş İğnelerini (Mavi/Kırmızı) Canlı Radarda Gizliyoruz (Sadece araba ve çizgi görünecek)
|
||||||
// Kırmızı Yol Üzerindeki "1.5 km Sapma" Çağrı Kutucuğu
|
// Kırmızı Yol Üzerindeki "1.5 km Sapma" Çağrı Kutucuğu
|
||||||
if (redPts.length > 0) {
|
if (redPts.length > 0) {
|
||||||
@@ -288,31 +278,9 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
var offlineCount = 0;
|
var offlineCount = 0;
|
||||||
|
|
||||||
vehiclesData.forEach(function(v, idx) {
|
vehiclesData.forEach(function(v, idx) {
|
||||||
// === Tarayıcı Tabanlı Rota Çizgisi Geçmişi (Frontend History) ===
|
// Sunucudan (Odoo JSON dosyası) gelen rotayı ezici olarak kullan
|
||||||
var historyKey = 'mymach_route_' + v.id;
|
if (serverHistory && serverHistory.length > 0) {
|
||||||
var history = [];
|
v.green_route = serverHistory;
|
||||||
try {
|
|
||||||
history = JSON.parse(localStorage.getItem(historyKey) || '[]');
|
|
||||||
} catch(e) {}
|
|
||||||
|
|
||||||
if (v.green_route && v.green_route.length > 0) {
|
|
||||||
var currentLat = v.green_route[0][0];
|
|
||||||
var currentLon = v.green_route[0][1];
|
|
||||||
|
|
||||||
var addPoint = true;
|
|
||||||
if (history.length > 0) {
|
|
||||||
var lastPt = history[history.length - 1];
|
|
||||||
// Sadece BİREBİR aynı koordinatsa ekleme. (Hafif bir GPS oynamasını bile kaydetmek için)
|
|
||||||
if (lastPt[0] === currentLat && lastPt[1] === currentLon) {
|
|
||||||
addPoint = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (addPoint) {
|
|
||||||
history.push([currentLat, currentLon]);
|
|
||||||
if (history.length > 300) history = history.slice(-300); // 300 noktayı hafızada tut
|
|
||||||
localStorage.setItem(historyKey, JSON.stringify(history));
|
|
||||||
}
|
|
||||||
v.green_route = history;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Basit bir kural: Hızı 0'dan büyük olanlar HAREKETLİ, 0 olanlar PARK, veri olmayanlar ÇEVRİMDIŞI.
|
// Basit bir kural: Hızı 0'dan büyük olanlar HAREKETLİ, 0 olanlar PARK, veri olmayanlar ÇEVRİMDIŞI.
|
||||||
@@ -415,4 +383,10 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- 10 Saniyede Bir Sayfayı Tam Ekran Yenileyerek Görüntüyü Güncelleyen Kod ---
|
||||||
|
setInterval(function() {
|
||||||
|
window.location.reload();
|
||||||
|
}, 15000);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user