💄 Display user position
This commit is contained in:
+38
-4
@@ -1,4 +1,4 @@
|
|||||||
import { IconLayer } from 'deck.gl';
|
import { IconLayer, ScatterplotLayer } from 'deck.gl';
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { StringifiedPinIcon } from '@/assets/PinIcon';
|
import { StringifiedPinIcon } from '@/assets/PinIcon';
|
||||||
|
|
||||||
@@ -7,6 +7,9 @@ export const useData = () => {
|
|||||||
|
|
||||||
const [canUseGeolocation, setCanUseGeolocation] = useState(false);
|
const [canUseGeolocation, setCanUseGeolocation] = useState(false);
|
||||||
const [geoError, setGeoError] = useState(null);
|
const [geoError, setGeoError] = useState(null);
|
||||||
|
const [userLocation, setUserLocation] = useState<{ [key: string]: number }>(
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
const [source, setSource] = useState([]);
|
const [source, setSource] = useState([]);
|
||||||
const [layers, setLayers] = useState([]);
|
const [layers, setLayers] = useState([]);
|
||||||
@@ -35,13 +38,23 @@ export const useData = () => {
|
|||||||
...prev,
|
...prev,
|
||||||
latitude: position.coords.latitude,
|
latitude: position.coords.latitude,
|
||||||
longitude: position.coords.longitude,
|
longitude: position.coords.longitude,
|
||||||
|
zoom: 13,
|
||||||
}));
|
}));
|
||||||
|
setUserLocation({
|
||||||
|
latitude: position.coords.latitude,
|
||||||
|
longitude: position.coords.longitude,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
if (error.PERMISSION_DENIED) {
|
if (error.PERMISSION_DENIED) {
|
||||||
setGeoError('permission_denied');
|
setGeoError('permission_denied');
|
||||||
console.warn(error.message);
|
console.warn(error.message);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
maximumAge: 0,
|
||||||
|
timeout: 5000,
|
||||||
|
enableHighAccuracy: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -53,8 +66,28 @@ export const useData = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const newLayers = [];
|
||||||
|
|
||||||
|
if (userLocation) {
|
||||||
|
const userLayer = new ScatterplotLayer({
|
||||||
|
id: 'userLayer',
|
||||||
|
data: [userLocation],
|
||||||
|
stroked: true,
|
||||||
|
getPosition: (d) => [d.longitude, d.latitude],
|
||||||
|
getRadius: 10,
|
||||||
|
getFillColor: [217, 66, 83],
|
||||||
|
getLineColor: [217, 66, 83, 175],
|
||||||
|
getLineWidth: 5,
|
||||||
|
radiusUnits: 'pixels',
|
||||||
|
lineWidthUnits: 'pixels',
|
||||||
|
pickable: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
newLayers.push(userLayer);
|
||||||
|
}
|
||||||
|
|
||||||
if (isAddLoveOpened) {
|
if (isAddLoveOpened) {
|
||||||
setLayers([]);
|
setLayers(newLayers);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,8 +113,9 @@ export const useData = () => {
|
|||||||
pickable: true,
|
pickable: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
setLayers([datasetLayer]);
|
newLayers.push(datasetLayer);
|
||||||
}, [source, isAddLoveOpened]);
|
setLayers(newLayers);
|
||||||
|
}, [userLocation, source, isAddLoveOpened]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
deckRef,
|
deckRef,
|
||||||
|
|||||||
Reference in New Issue
Block a user