2025-12-06 14:54:49 -05:00
|
|
|
/**
|
|
|
|
|
* Transform points array to GeoJSON FeatureCollection
|
|
|
|
|
* @param {Array} points - Array of point objects from API
|
|
|
|
|
* @returns {Object} GeoJSON FeatureCollection
|
|
|
|
|
*/
|
|
|
|
|
export function pointsToGeoJSON(points) {
|
|
|
|
|
return {
|
|
|
|
|
type: 'FeatureCollection',
|
|
|
|
|
features: points.map(point => ({
|
|
|
|
|
type: 'Feature',
|
|
|
|
|
geometry: {
|
|
|
|
|
type: 'Point',
|
|
|
|
|
coordinates: [point.longitude, point.latitude]
|
|
|
|
|
},
|
|
|
|
|
properties: {
|
|
|
|
|
id: point.id,
|
|
|
|
|
timestamp: point.timestamp,
|
|
|
|
|
altitude: point.altitude,
|
|
|
|
|
battery: point.battery,
|
|
|
|
|
accuracy: point.accuracy,
|
|
|
|
|
velocity: point.velocity,
|
|
|
|
|
country_name: point.country_name
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Format timestamp for display
|
|
|
|
|
* @param {number|string} timestamp - Unix timestamp (seconds) or ISO 8601 string
|
2025-12-14 06:05:59 -05:00
|
|
|
* @param {string} timezone - IANA timezone string (e.g., 'Europe/Berlin')
|
2025-12-06 14:54:49 -05:00
|
|
|
* @returns {string} Formatted date/time
|
|
|
|
|
*/
|
2025-12-14 06:05:59 -05:00
|
|
|
export function formatTimestamp(timestamp, timezone = 'UTC') {
|
2025-12-06 14:54:49 -05:00
|
|
|
// Handle different timestamp formats
|
|
|
|
|
let date
|
|
|
|
|
if (typeof timestamp === 'string') {
|
|
|
|
|
// ISO 8601 string
|
|
|
|
|
date = new Date(timestamp)
|
|
|
|
|
} else if (timestamp < 10000000000) {
|
|
|
|
|
// Unix timestamp in seconds
|
|
|
|
|
date = new Date(timestamp * 1000)
|
|
|
|
|
} else {
|
|
|
|
|
// Unix timestamp in milliseconds
|
|
|
|
|
date = new Date(timestamp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return date.toLocaleString('en-US', {
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
month: 'short',
|
|
|
|
|
day: 'numeric',
|
|
|
|
|
hour: '2-digit',
|
2025-12-14 06:05:59 -05:00
|
|
|
minute: '2-digit',
|
|
|
|
|
timeZone: timezone
|
2025-12-06 14:54:49 -05:00
|
|
|
})
|
|
|
|
|
}
|