import React, { useState, useEffect } from "react" import { Map, Marker, GeoJson, ZoomControl } from "pigeon-maps" import useLocalState from "@phntms/use-local-state"; import moment from "moment"; import 'moment/min/locales'; export default () => { moment.locale('ru'); const [point, setPoint] = useState({ "id": "", "user_id": "", "lat": 0, "lon": 0, "time": "2024-08-15T09:54:00.666Z", "speed": 0, "direction": 0, "accuracy": 0, }); const [selected, setSelected] = useState(null) const [points, setPoints] = useState([]) const [loaded, setLoaded] = useState(false); const [zoom, setZoom] = useLocalState("zoom", 5); const [center, setCenter] = useState([]) const [page, setPage] = useState(0) const updatePosition = () => { fetch("/api/points/last").then(x => x.json()).then((p) => { setPoint(p); setCenter([point.lat, point.lon]) setLoaded(true); }) fetch("/api/points").then(x => x.json()).then(p => { setPoints(p.reverse()) }) } useEffect(updatePosition, []) if (!loaded) { return

Загрузка карты

} const path = { type: "FeatureCollection", features: [ { type: "Feature", geometry: { type: "LineString", coordinates: points.map((pp) => [pp.lon, pp.lat]), }, properties: { prop0: "value0" }, }, ], }; return (
{setZoom(zoom); setCenter(center)}}> { return { strokeWidth: "2", stroke: "red" }; }} /> {selected ? ():null}
Дата последней точки: {moment(point.time).format("LTS L")}
Точность: {point.accuracy.toFixed(2)}м
История перемещения:
) }