dawarich/app/javascript/maps_v2/utils/geojson_transformers.js
Eugene Burmakin f49b6d4434 Phase 7
2025-11-21 19:46:51 +01:00

42 lines
1 KiB
JavaScript

/**
* 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} timestamp - Unix timestamp
* @returns {string} Formatted date/time
*/
export function formatTimestamp(timestamp) {
const date = new Date(timestamp * 1000)
return date.toLocaleString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
})
}