fix: prevent drawn items from disappearing during data load
This commit is contained in:
@@ -266,39 +266,14 @@ function Map({data, loading, end, duration, slider, mapState, setMapState, setSu
|
||||
setDrawnItems(items => items.filter(item => !deletedIds.includes(item.id)));
|
||||
};
|
||||
|
||||
const showMap = Array.isArray(data);
|
||||
|
||||
return (
|
||||
<div className='container'>
|
||||
{loading ?
|
||||
<p>Loading...</p>
|
||||
:
|
||||
coords.length ?
|
||||
(
|
||||
<MapContainer center={mapState.center || [0, 0]} zoom={mapState.zoom} scrollWheelZoom={true} style={{ width: '100%', height: 'calc(100vh - 2.5rem)' }}>
|
||||
<MapViewManager coords={coords} mapState={mapState} setMapState={setMapState} loading={loading} setSubmenu={setSubmenu} />
|
||||
<TileLayer
|
||||
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
url='https://maptiles.p.rapidapi.com/en/map/v1/{z}/{x}/{y}.png?rapidapi-key=4375b0b1d8msh0c9e7fa3efb9adfp1769dfjsnd603a0387fea'
|
||||
/>
|
||||
<PolylineWithArrows coords={coords} showDirection={showDirection} />
|
||||
<FeatureGroup>
|
||||
<EditControl
|
||||
position="topright"
|
||||
onCreated={onCreated}
|
||||
onEdited={onEdited}
|
||||
onDeleted={onDeleted}
|
||||
draw={{
|
||||
rectangle: true,
|
||||
polyline: false,
|
||||
polygon: false,
|
||||
circle: false,
|
||||
marker: false,
|
||||
circlemarker: false,
|
||||
}}
|
||||
/>
|
||||
</FeatureGroup>
|
||||
</MapContainer>
|
||||
)
|
||||
:
|
||||
{!showMap ? (
|
||||
loading ? (
|
||||
<p>Loading...</p>
|
||||
) : (
|
||||
<>
|
||||
<p>No data</p>
|
||||
<form onSubmit={handleSubmit}>
|
||||
@@ -307,7 +282,40 @@ function Map({data, loading, end, duration, slider, mapState, setMapState, setSu
|
||||
</p>
|
||||
</form>
|
||||
</>
|
||||
}
|
||||
)
|
||||
) : (
|
||||
<div style={{ position: 'relative', width: '100%', height: 'calc(100vh - 2.5rem)' }}>
|
||||
{loading && (
|
||||
<div className="loading-overlay">
|
||||
<p>Loading...</p>
|
||||
</div>
|
||||
)}
|
||||
<MapContainer center={mapState.center || [0, 0]} zoom={mapState.zoom} scrollWheelZoom={true} style={{ width: '100%', height: '100%' }}>
|
||||
<MapViewManager coords={coords} mapState={mapState} setMapState={setMapState} loading={loading} setSubmenu={setSubmenu} />
|
||||
<TileLayer
|
||||
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
url='https://maptiles.p.rapidapi.com/en/map/v1/{z}/{x}/{y}.png?rapidapi-key=4375b0b1d8msh0c9e7fa3efb9adfp1769dfjsnd603a0387fea'
|
||||
/>
|
||||
<PolylineWithArrows coords={coords} showDirection={showDirection} />
|
||||
<FeatureGroup>
|
||||
<EditControl
|
||||
position="topright"
|
||||
onCreated={onCreated}
|
||||
onEdited={onEdited}
|
||||
onDeleted={onDeleted}
|
||||
draw={{
|
||||
rectangle: true,
|
||||
polyline: false,
|
||||
polygon: false,
|
||||
circle: false,
|
||||
marker: false,
|
||||
circlemarker: false,
|
||||
}}
|
||||
/>
|
||||
</FeatureGroup>
|
||||
</MapContainer>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user