diff options
author | Anton Tananaev <anton@traccar.org> | 2024-05-25 19:43:59 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2024-05-25 19:43:59 -0700 |
commit | d8c1d8296b4728ebaac6a49e1da7de3e20bef19a (patch) | |
tree | 6b4ff984d6f351a691df3b7be4171a0fc9ce7cd5 /src | |
parent | afafc146475e1c9219c7c48f1cb9c7f027d90940 (diff) | |
download | trackermap-web-d8c1d8296b4728ebaac6a49e1da7de3e20bef19a.tar.gz trackermap-web-d8c1d8296b4728ebaac6a49e1da7de3e20bef19a.tar.bz2 trackermap-web-d8c1d8296b4728ebaac6a49e1da7de3e20bef19a.zip |
Send OsmAnd emulator data
Diffstat (limited to 'src')
-rw-r--r-- | src/map/MapPositions.js | 2 | ||||
-rw-r--r-- | src/other/EmulatorPage.jsx | 24 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/map/MapPositions.js b/src/map/MapPositions.js index d1b16299..45e5fc0f 100644 --- a/src/map/MapPositions.js +++ b/src/map/MapPositions.js @@ -54,7 +54,7 @@ const MapPositions = ({ positions, onClick, showStatus, selectedPosition, titleF const onMapClick = useCallback((event) => { if (!event.defaultPrevented && onClick) { - onClick(); + onClick(event.lngLat.lat, event.lngLat.lng); } }, [onClick]); diff --git a/src/other/EmulatorPage.jsx b/src/other/EmulatorPage.jsx index c4dcd843..9adc129f 100644 --- a/src/other/EmulatorPage.jsx +++ b/src/other/EmulatorPage.jsx @@ -17,6 +17,7 @@ import MapGeocoder from '../map/geocoder/MapGeocoder'; import SelectField from '../common/components/SelectField'; import { devicesActions } from '../store'; import MapPositions from '../map/MapPositions'; +import { useCatch } from '../reactHelper'; const useStyles = makeStyles((theme) => ({ root: { @@ -66,6 +67,23 @@ const EmulatorPage = () => { const deviceId = useSelector((state) => state.devices.selectedId); const positions = useSelector((state) => state.session.positions); + const handleClick = useCatch(async (latitude, longitude) => { + if (deviceId) { + const params = new URLSearchParams(); + params.append('id', devices[deviceId].uniqueId); + params.append('lat', latitude); + params.append('lon', longitude); + + const response = await fetch(`http://${window.location.hostname}:5055?${params.toString()}`, { + method: 'GET', + mode: 'no-cors', + }); + if (!response.ok) { + throw Error(await response.text()); + } + } + }); + return ( <div className={classes.root}> <div className={classes.content}> @@ -96,7 +114,11 @@ const EmulatorPage = () => { </Drawer> <div className={classes.mapContainer}> <MapView> - <MapPositions positions={Object.values(positions)} showStatus /> + <MapPositions + positions={Object.values(positions)} + onClick={handleClick} + showStatus + /> </MapView> <MapCurrentLocation /> <MapGeocoder /> |