Implement true OSRM Match API
This commit is contained in:
@@ -188,6 +188,40 @@
|
||||
if (greenPts.length > 0) {
|
||||
var polyGreen = L.polyline(greenPts, { color: '#10b981', weight: 8, opacity: 0.95, lineCap: 'round', lineJoin: 'round', smoothFactor: 2.0 }).addTo(map);
|
||||
activePolylines.push(polyGreen);
|
||||
|
||||
// OSRM Map Matching (Pürüzsüz Rota Çizimi)
|
||||
if (greenPts.length >= 2) {
|
||||
// Sadece son 80 noktayı al ki OSRM URL limiti aşılmasın
|
||||
var validPts = greenPts.length > 80 ? greenPts.slice(-80) : greenPts;
|
||||
var coords = validPts.map(function(p) { return p[1] + ',' + p[0]; });
|
||||
var osrmUrl = 'https://router.project-osrm.org/match/v1/driving/' + coords.join(';') + '?overview=full&geometries=geojson';
|
||||
|
||||
fetch(osrmUrl)
|
||||
.then(function(res) { return res.json(); })
|
||||
.then(function(data) {
|
||||
if (data && data.matchings && data.matchings.length > 0) {
|
||||
// Ham (kırık) çizgiyi haritadan ve diziden kaldır
|
||||
map.removeLayer(polyGreen);
|
||||
var index = activePolylines.indexOf(polyGreen);
|
||||
if (index > -1) activePolylines.splice(index, 1);
|
||||
|
||||
// OSRM'den gelen pürüzsüz rotayı GeoJSON olarak çiz
|
||||
data.matchings.forEach(function(match) {
|
||||
var snappedPoly = L.geoJSON(match.geometry, {
|
||||
style: { color: '#10b981', weight: 8, opacity: 0.95, lineCap: 'round', lineJoin: 'round' }
|
||||
}).addTo(map);
|
||||
activePolylines.push(snappedPoly);
|
||||
});
|
||||
|
||||
// Yeni çizilen pürüzsüz rotaya göre kamerayı odakla
|
||||
var group = new L.featureGroup(activePolylines);
|
||||
map.fitBounds(group.getBounds(), { padding: [50, 50] });
|
||||
}
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.log('OSRM Map Matching Hatası, ham çizgi bırakıldı:', err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Kırmızı 1 km+ Sapma Çizgisi
|
||||
|
||||
@@ -270,7 +270,7 @@
|
||||
style="display: none;"/>
|
||||
|
||||
<!-- Harita ve Tablo İşleme Kodları (Statik Dosyadan Yüklenir - QWeb Çakışmalarını Önler) -->
|
||||
<script type="text/javascript" src="/mymach_fleet_intelligence/static/src/js/dashboard.js?v=8"></script>
|
||||
<script type="text/javascript" src="/mymach_fleet_intelligence/static/src/js/dashboard.js?v=9"></script>
|
||||
</body>
|
||||
</html>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user