web / lib/utils/coordinates
lib/utils/coordinates
Coordinate formatting utilities for cartographic display.
Provides functions to format geographic coordinates in various styles appropriate for map interfaces and navigation displays.
Interfaces
MapBounds
Map bounds interface matching the Zustand store structure.
Properties
north
north:
number
south
south:
number
east
east:
number
west
west:
number
Functions
getCenterFromBounds()
getCenterFromBounds(
bounds):object
Calculate the center point of a bounding box.
Parameters
bounds
The map bounds
Returns
object
Object with lat and lon of center point
lat
lat:
number
lon
lon:
number
Example
const center = getCenterFromBounds({
north: 41.0,
south: 40.0,
east: -73.0,
west: -74.0
});
// { lat: 40.5, lon: -73.5 }formatCoordinate()
formatCoordinate(
value,isLatitude,precision):string
Format a coordinate value with hemisphere indicator.
Converts decimal degrees to a formatted string with degree symbol and hemisphere (N/S for latitude, E/W for longitude).
Parameters
value
number
The coordinate value in decimal degrees
isLatitude
boolean
True for latitude (N/S), false for longitude (E/W)
precision
number = 2
Number of decimal places (default: 2)
Returns
string
Formatted coordinate string
Example
formatCoordinate(40.7128, true); // "40.71°N"
formatCoordinate(-74.0060, false); // "74.01°W"
formatCoordinate(51.5074, true, 4); // "51.5074°N"formatCenterCoordinates()
formatCenterCoordinates(
bounds,precision):string
Format center coordinates from map bounds.
Creates a compact, cartographic-style coordinate display showing the center point of the current map view.
Parameters
bounds
The map bounds
precision
number = 2
Number of decimal places (default: 2)
Returns
string
Formatted coordinate pair string
Example
const bounds = {
north: 41.0,
south: 40.0,
east: -73.0,
west: -74.0
};
formatCenterCoordinates(bounds);
// "40.50°N 73.50°W"formatEventCount()
formatEventCount(
visible,total):null|string
Format event count statistics.
Creates a compact display of visible events vs total events.
Parameters
visible
Number of visible events
undefined | number
total
Total number of events
undefined | number
Returns
null | string
Formatted count string or null if data is invalid
Example
formatEventCount(327, 1240);
// "327 / 1,240"
formatEventCount(5, 5);
// "5 / 5"
formatEventCount(undefined, undefined);
// null