💄 Increase default zoom & prepare click tooltip
This commit is contained in:
+30
-2
@@ -1,7 +1,10 @@
|
|||||||
import { FormEvent } from 'react';
|
import { PickingInfo } from 'deck.gl';
|
||||||
|
import { FormEvent, useCallback } from 'react';
|
||||||
|
|
||||||
export const useActions = ({
|
export const useActions = ({
|
||||||
|
deckRef,
|
||||||
viewState,
|
viewState,
|
||||||
|
setClickedItem,
|
||||||
setIsAddLoveOpened,
|
setIsAddLoveOpened,
|
||||||
setIsLoading,
|
setIsLoading,
|
||||||
setAddLoveMessage,
|
setAddLoveMessage,
|
||||||
@@ -72,5 +75,30 @@ export const useActions = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return { toggleLoveMenu, addPoint };
|
const onMapClick = useCallback(
|
||||||
|
(ev: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
|
||||||
|
if (!deckRef.current) return;
|
||||||
|
|
||||||
|
const containerRect = ev.currentTarget.getBoundingClientRect();
|
||||||
|
const x = ev.clientX - containerRect.left;
|
||||||
|
const y = ev.clientY - containerRect.top;
|
||||||
|
|
||||||
|
const pickInfos: PickingInfo | null = deckRef.current.pickObject({
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
radius: 1,
|
||||||
|
depth: 5,
|
||||||
|
});
|
||||||
|
console.log('pickInfos: ', pickInfos);
|
||||||
|
if (!pickInfos) {
|
||||||
|
setClickedItem(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setClickedItem(pickInfos);
|
||||||
|
},
|
||||||
|
[deckRef, setClickedItem]
|
||||||
|
);
|
||||||
|
|
||||||
|
return { toggleLoveMenu, addPoint, onMapClick };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ export const useData = () => {
|
|||||||
zoom: 5,
|
zoom: 5,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [clickedItem, setClickedItem] = useState(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if ('geolocation' in navigator == false) {
|
if ('geolocation' in navigator == false) {
|
||||||
setCanUseGeolocation(false);
|
setCanUseGeolocation(false);
|
||||||
@@ -38,7 +40,7 @@ export const useData = () => {
|
|||||||
...prev,
|
...prev,
|
||||||
latitude: position.coords.latitude,
|
latitude: position.coords.latitude,
|
||||||
longitude: position.coords.longitude,
|
longitude: position.coords.longitude,
|
||||||
zoom: 13,
|
zoom: 17,
|
||||||
}));
|
}));
|
||||||
setUserLocation({
|
setUserLocation({
|
||||||
latitude: position.coords.latitude,
|
latitude: position.coords.latitude,
|
||||||
@@ -46,9 +48,9 @@ export const useData = () => {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
|
console.warn(error.message);
|
||||||
if (error.PERMISSION_DENIED) {
|
if (error.PERMISSION_DENIED) {
|
||||||
setGeoError('permission_denied');
|
setGeoError('permission_denied');
|
||||||
console.warn(error.message);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -119,6 +121,8 @@ export const useData = () => {
|
|||||||
geoError,
|
geoError,
|
||||||
layers,
|
layers,
|
||||||
canUseGeolocation,
|
canUseGeolocation,
|
||||||
|
clickedItem,
|
||||||
|
setClickedItem,
|
||||||
isAddLoveOpened,
|
isAddLoveOpened,
|
||||||
setIsAddLoveOpened,
|
setIsAddLoveOpened,
|
||||||
isLoading,
|
isLoading,
|
||||||
|
|||||||
+26
-2
@@ -33,6 +33,8 @@ const Home = () => {
|
|||||||
geoError,
|
geoError,
|
||||||
canUseGeolocation,
|
canUseGeolocation,
|
||||||
layers,
|
layers,
|
||||||
|
clickedItem,
|
||||||
|
setClickedItem,
|
||||||
isAddLoveOpened,
|
isAddLoveOpened,
|
||||||
setIsAddLoveOpened,
|
setIsAddLoveOpened,
|
||||||
isLoading,
|
isLoading,
|
||||||
@@ -41,8 +43,10 @@ const Home = () => {
|
|||||||
setAddLoveMessage,
|
setAddLoveMessage,
|
||||||
} = useData();
|
} = useData();
|
||||||
|
|
||||||
const { toggleLoveMenu, addPoint } = useActions({
|
const { toggleLoveMenu, addPoint, onMapClick } = useActions({
|
||||||
|
deckRef,
|
||||||
viewState,
|
viewState,
|
||||||
|
setClickedItem,
|
||||||
setIsAddLoveOpened,
|
setIsAddLoveOpened,
|
||||||
setIsLoading,
|
setIsLoading,
|
||||||
setAddLoveMessage,
|
setAddLoveMessage,
|
||||||
@@ -63,7 +67,10 @@ const Home = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='page'>
|
<div className='page'>
|
||||||
<div className='mapContainer'>
|
<div
|
||||||
|
className='mapContainer'
|
||||||
|
onClick={onMapClick}
|
||||||
|
>
|
||||||
<DeckGL
|
<DeckGL
|
||||||
ref={deckRef}
|
ref={deckRef}
|
||||||
initialViewState={viewState}
|
initialViewState={viewState}
|
||||||
@@ -87,6 +94,23 @@ const Home = () => {
|
|||||||
}
|
}
|
||||||
preserveDrawingBuffer
|
preserveDrawingBuffer
|
||||||
></Map>
|
></Map>
|
||||||
|
{clickedItem && clickedItem.object ? (
|
||||||
|
<div
|
||||||
|
className='mapTooltip'
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
zIndex: 1,
|
||||||
|
pointerEvents: 'none',
|
||||||
|
left: clickedItem.x,
|
||||||
|
top: clickedItem.y,
|
||||||
|
backgroundColor: '#ffffff',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{clickedItem.object.properties.location}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
</DeckGL>
|
</DeckGL>
|
||||||
{isAddLoveOpened && (
|
{isAddLoveOpened && (
|
||||||
// <Image
|
// <Image
|
||||||
|
|||||||
Reference in New Issue
Block a user