Skip to content

Commit

Permalink
Update item on lat or lng change
Browse files Browse the repository at this point in the history
  • Loading branch information
r00tat committed Nov 26, 2022
1 parent fdcb704 commit b0400aa
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/components/Map/markers/FirecallItemMarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import EditIcon from '@mui/icons-material/Edit';
import { IconButton } from '@mui/material';
import { doc, setDoc } from 'firebase/firestore';
import L, { IconOptions } from 'leaflet';
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { Marker, Popup } from 'react-leaflet';
import { defaultPosition } from '../../../hooks/constants';
import { useFirecallId } from '../../../hooks/useFirecall';
Expand All @@ -22,7 +22,7 @@ async function updateFircallItemPos(
fcItem: FirecallItem
) {
const newPos = (event.target as L.Marker)?.getLatLng();
// console.info(`drag end on ${JSON.stringify(gisObject)}: ${newPos}`);
// console.info(`drag end on ${JSON.stringify(fcItem)}: ${newPos}`);
if (fcItem.id && newPos) {
const updatePos = {
lat: newPos.lat,
Expand All @@ -46,10 +46,7 @@ export default function FirecallItemMarker({
return record.type === 'connection' ? (
<ConnectionMarker record={record as Connection} selectItem={selectItem} />
) : (
<FirecallItemMarkerDefault
record={record as Connection}
selectItem={selectItem}
/>
<FirecallItemMarkerDefault record={record} selectItem={selectItem} />
);
}

Expand All @@ -71,6 +68,12 @@ export function FirecallItemMarkerDefault({
)
);

useEffect(() => {
if (record.lat && record.lng) {
setStartPos(L.latLng(record.lat, record.lng));
}
}, [record.lat, record.lng]);

return (
<>
<Marker
Expand Down

0 comments on commit b0400aa

Please sign in to comment.