diff options
author | Anton Tananaev <anton@traccar.org> | 2022-05-02 19:18:21 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-05-02 19:18:21 -0700 |
commit | 76e3a4189f282afc391a948a9a818157df99de97 (patch) | |
tree | e39bec1e4d86a0a979cd4d7c24530c319b5305af /modern/src/components | |
parent | 69251d6252aaee71acf54f5e403551a807afb2fa (diff) | |
download | trackermap-web-76e3a4189f282afc391a948a9a818157df99de97.tar.gz trackermap-web-76e3a4189f282afc391a948a9a818157df99de97.tar.bz2 trackermap-web-76e3a4189f282afc391a948a9a818157df99de97.zip |
Implement show address
Diffstat (limited to 'modern/src/components')
-rw-r--r-- | modern/src/components/PositionValue.js | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/modern/src/components/PositionValue.js b/modern/src/components/PositionValue.js index 442ac859..9127ecf4 100644 --- a/modern/src/components/PositionValue.js +++ b/modern/src/components/PositionValue.js @@ -1,4 +1,5 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; +import { Link } from '@material-ui/core'; import { formatAlarm, formatBoolean, formatCoordinate, formatCourse, formatDistance, formatNumber, formatPercentage, formatSpeed, formatTime, } from '../common/formatter'; @@ -15,6 +16,23 @@ const PositionValue = ({ position, property, attribute }) => { const speedUnit = useAttributePreference('speedUnit'); const coordinateFormat = usePreference('coordinateFormat'); + const [address, setAddress] = useState(); + + useEffect(() => { + setAddress(position.address); + }, [position]); + + const showAddress = async () => { + const query = new URLSearchParams({ + latitude: position.latitude, + longitude: position.longitude, + }); + const response = await fetch(`/api/server/geocode?${query.toString()}`); + if (response.ok) { + setAddress(await response.text()); + } + }; + const formatValue = () => { switch (key) { case 'fixTime': @@ -47,7 +65,15 @@ const PositionValue = ({ position, property, attribute }) => { } }; - return (<>{formatValue(value)}</>); + if (property === 'address') { + if (address) { + return (<>{address}</>); + } else { + return (<Link onClick={showAddress}>{t('sharedShowAddress')}</Link>) + } + } else { + return (<>{formatValue(value)}</>); + } }; export default PositionValue; |