Created
June 16, 2025 05:42
-
-
Save youssef22222/d326a257f1b70c179e315699816c10ce to your computer and use it in GitHub Desktop.
Speed Violation Map - S16AG-588 - 1750052568
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Speed Violation Path - S16AG-588</title> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" /> | |
<style> | |
html, body { height: 100%; margin: 0; padding: 0; } | |
#map { height: 100%; } | |
.number-icon { | |
background-color: #4285F4; | |
border: 2px solid white; | |
border-radius: 50%; | |
color: white; | |
font-weight: bold; | |
text-align: center; | |
font-size: 12px; | |
line-height: 20px; | |
width: 24px; | |
height: 24px; | |
margin-left: -12px; | |
margin-top: -12px; | |
box-shadow: 0 2px 5px rgba(0,0,0,0.3); | |
} | |
.start-icon { | |
background-color: #00C853; | |
} | |
.end-icon { | |
background-color: #FF6F00; /* Orange for violation/end point */ | |
width: 30px; | |
height: 30px; | |
line-height: 26px; | |
font-size: 14px; | |
} | |
.popup-content { | |
min-width: 250px; | |
} | |
.popup-content table { | |
width: 100%; | |
border-collapse: collapse; | |
} | |
.popup-content td { | |
padding: 2px 5px; | |
border-bottom: 1px solid #eee; | |
} | |
.popup-content td:first-child { | |
font-weight: bold; | |
width: 40%; | |
} | |
.speed-ok { color: green; } | |
.speed-violation { color: red; font-weight: bold; } | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script> | |
<script src="https://unpkg.com/leaflet-polylinedecorator@1.6.0/dist/leaflet.polylineDecorator.js"></script> | |
<script> | |
// Initialize the map | |
var map = L.map('map').setView([26.21840662210829, 50.19496841956609], 14); | |
// Add OpenStreetMap tile layer | |
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { | |
maxZoom: 19, | |
attribution: '© OpenStreetMap contributors' | |
}).addTo(map); | |
// Define the coordinates and the detailed path data | |
var latlngs = [ | |
[26.217995244216585, 50.19655983913218], | |
[26.218818, 50.193377] | |
]; | |
var pathData = [{"latitude": 26.217995244216585, "longitude": 50.19655983913218, "time": "06/16/25,08:42:43", "speed": 150, "speed_limit": 110, "street_name": "King Khaled Road", "street_name_ar": "\u0637\u0631\u064a\u0642 \u0627\u0644\u0645\u0644\u0643 \u062e\u0627\u0644\u062f", "distance_to_segment": 2.35, "vehicle_direction": 349, "segment_bearing": 354.3, "nearest_segment": [[26.217554, 50.1965849], [26.2182769, 50.196505]], "closest_point": [26.21799265540602, 50.1965364167147]}, {"latitude": 26.218818, "longitude": 50.193377, "time": "06/16/25,08:42:43", "speed": 150, "speed_limit": 60, "street_name": null, "street_name_ar": "\u0637\u0631\u064a\u0642 \u0627\u0644\u0645\u0644\u0643 \u062e\u0627\u0644\u062f \u0627\u0644\u0641\u0631\u0639\u064a", "distance_to_segment": 5.2, "vehicle_direction": 349, "segment_bearing": 228.0, "nearest_segment": [[26.2190167, 50.1935457], [26.2186429, 50.1930824]], "closest_point": [26.218855910898217, 50.19334641270504]}]; | |
// Draw the polyline (straight lines between points) | |
var polyline = L.polyline(latlngs, { | |
color: 'blue', | |
weight: 4, | |
opacity: 0.6, | |
dashArray: '10, 5' | |
}).addTo(map); | |
// Add directional arrows | |
var decorator = L.polylineDecorator(polyline, { | |
patterns: [ | |
{ | |
offset: 25, | |
repeat: 50, | |
symbol: L.Symbol.arrowHead({ | |
pixelSize: 12, | |
polygon: false, | |
pathOptions: { | |
stroke: true, | |
color: 'blue', | |
weight: 2, | |
opacity: 0.8 | |
} | |
}) | |
} | |
] | |
}).addTo(map); | |
// Function to create numbered div icons | |
function createNumberedIcon(number, extraClass = '') { | |
return L.divIcon({ | |
className: 'number-icon ' + extraClass, | |
html: number.toString(), | |
iconSize: [24, 24] | |
}); | |
} | |
// Function to create popup content | |
function createPopupContent(pointNum, data) { | |
var lat = data.latitude; | |
var lon = data.longitude; | |
var isViolation = data.speed && data.speed_limit && (data.speed > data.speed_limit); | |
var speedClass = isViolation ? 'speed-violation' : 'speed-ok'; | |
var html = '<div class="popup-content">'; | |
html += '<h4 style="margin: 0 0 5px 0;">Point ' + pointNum + '</h4>'; | |
html += '<table>'; | |
html += '<tr><td>Latitude:</td><td>' + lat.toFixed(6) + '</td></tr>'; | |
html += '<tr><td>Longitude:</td><td>' + lon.toFixed(6) + '</td></tr>'; | |
if (data.time) { | |
html += '<tr><td>Time:</td><td>' + data.time + '</td></tr>'; | |
} | |
if (data.device_name) { | |
html += '<tr><td>Vehicle:</td><td>' + data.device_name + '</td></tr>'; | |
} | |
if (data.street_name_ar) { | |
html += '<tr><td>Street (AR):</td><td style="direction: rtl;">' + data.street_name_ar + '</td></tr>'; | |
} | |
if (data.street_name) { // This is street_name_en | |
html += '<tr><td>Street (EN):</td><td>' + data.street_name + '</td></tr>'; | |
} | |
if (data.distance_to_segment !== undefined) { | |
html += '<tr><td>Dist to street:</td><td>' + data.distance_to_segment.toFixed(2) + ' m</td></tr>'; | |
} | |
if (data.vehicle_direction !== undefined) { | |
html += '<tr><td>Vehicle Dir:</td><td>' + data.vehicle_direction.toFixed(1) + '°</td></tr>'; | |
} | |
if (data.segment_bearing !== undefined) { | |
html += '<tr><td>Street Bearing:</td><td>' + data.segment_bearing.toFixed(1) + '°</td></tr>'; | |
} | |
if (data.speed_limit) { | |
html += '<tr><td>Speed Limit:</td><td>' + data.speed_limit + ' km/h</td></tr>'; | |
} | |
if (data.speed) { | |
html += '<tr><td>Vehicle Speed:</td><td class="' + speedClass + '">' + data.speed + ' km/h</td></tr>'; | |
} | |
if (isViolation) { | |
var overSpeed = data.speed - data.speed_limit; | |
html += '<tr><td>Over Speed:</td><td class="speed-violation">+' + overSpeed + ' km/h</td></tr>'; | |
} | |
html += '</table>'; | |
html += '</div>'; | |
return html; | |
} | |
// Add markers for all points | |
for (var i = 0; i < pathData.length; i++) { | |
var iconClass = ''; | |
var icon; | |
var data = pathData[i]; | |
data.device_name = "S16AG-588"; // Add device name to each point's data | |
if (i === 0) { | |
iconClass = 'start-icon'; | |
icon = createNumberedIcon('S', iconClass); | |
} else if (i === latlngs.length - 1) { | |
iconClass = 'end-icon'; // End point is the violation point | |
icon = createNumberedIcon('V', iconClass); | |
} else { | |
icon = createNumberedIcon(i + 1); | |
} | |
var popupContent = createPopupContent(i + 1, data); | |
var vehicleMarker = L.marker([data.latitude, data.longitude], {icon: icon}) | |
.addTo(map) | |
.bindPopup(popupContent); | |
// Draw the nearest street segment for each point if available | |
if (data.nearest_segment && data.nearest_segment.length === 2) { | |
L.polyline(data.nearest_segment, { | |
color: 'red', // CHANGED to red | |
weight: 6, | |
opacity: 0.8 | |
}).addTo(map).bindPopup('Nearest Street Segment for Point ' + (i + 1)); | |
// Add start and end circles for the segment | |
L.circleMarker(data.nearest_segment[0], { radius: 4, color: 'black', fillColor: 'red', fillOpacity: 1 }).addTo(map); | |
L.circleMarker(data.nearest_segment[1], { radius: 4, color: 'black', fillColor: 'red', fillOpacity: 1 }).addTo(map); | |
} | |
// Draw the closest point on the segment and a line to it | |
if (data.closest_point && data.closest_point.length === 2) { | |
// Draw a small black circle at the closest point on the segment | |
L.circleMarker(data.closest_point, { radius: 4, color: 'black', fillColor: 'black', fillOpacity: 1 }).addTo(map); | |
// Draw a dashed line from the vehicle to the closest point | |
var line_to_closest = [ | |
[data.latitude, data.longitude], | |
data.closest_point | |
]; | |
L.polyline(line_to_closest, { | |
color: 'grey', | |
weight: 2, | |
opacity: 0.8, | |
dashArray: '5, 5' | |
}).addTo(map); | |
} | |
} | |
// Fit the map to show all points | |
map.fitBounds(polyline.getBounds().pad(0.1)); | |
// Add a legend | |
var legend = L.control({position: 'bottomright'}); | |
legend.onAdd = function (map) { | |
var div = L.DomUtil.create('div', 'legend'); | |
div.style.background = 'white'; | |
div.style.padding = '10px'; | |
div.style.border = '2px solid #ccc'; | |
div.style.borderRadius = '5px'; | |
div.style.fontSize = '12px'; | |
div.innerHTML = '<h4 style="margin: 0 0 5px 0;">Legend</h4>' + | |
'<p style="margin: 2px 0;"><span style="color: #00C853; font-weight: bold;">S</span> Start Point</p>' + | |
'<p style="margin: 2px 0;"><span style="color: #4285F4; font-weight: bold;">1-9</span> Path Points</p>' + | |
'<p style="margin: 2px 0;"><span style="color: #FF6F00; font-weight: bold;">V</span> Violation Location</p>' + | |
'<p style="margin: 2px 0;"><span style="background-color: red; display: inline-block; width: 20px; height: 3px; margin-right: 5px;"></span> Nearest Street Segment</p>' + | |
'<p style="margin: 2px 0;"><span style="color: blue;">- - →</span> Vehicle Path</p>' + | |
'<hr style="margin: 5px 0;">' + | |
'<p style="margin: 2px 0; font-style: italic; font-size: 11px;">Note: Lines show direct paths<br>between GPS points, not<br>actual street routes.</p>'; | |
return div; | |
}; | |
legend.addTo(map); | |
// Add info control | |
var info = L.control({position: 'topleft'}); | |
info.onAdd = function (map) { | |
var div = L.DomUtil.create('div', 'info'); | |
div.style.background = 'rgba(255,255,255,0.9)'; | |
div.style.padding = '8px'; | |
div.style.border = '2px solid #ccc'; | |
div.style.borderRadius = '5px'; | |
div.style.fontSize = '14px'; | |
var violationCount = 0; | |
for (var i = 0; i < pathData.length; i++) { | |
var d = pathData[i]; | |
if (d.speed && d.speed_limit && d.speed > d.speed_limit) { | |
violationCount++; | |
} | |
} | |
div.innerHTML = '<b>Vehicle:</b> S16AG-588<br>' + | |
'<b>Total Points:</b> ' + latlngs.length + '<br>' + | |
'<b>Violations on Path:</b> ' + violationCount; | |
return div; | |
}; | |
info.addTo(map); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment