I'm trying to create a map with a very large amount of Circle objects. these Circles' colors will change based on a user input. A lot of colors can change at once, and I want to present the changes as fast as possible.
To save up on the time of creating the Circles each time the user changes something and the map re-renders, I thought about storing the Circle objects in an array in the state. Then when the user changes something, I would want to update the Circles' properties, but without using copy methods and the like (as it contradicts the idea of creating the Circle objects only once).
I thought about making a parallel array that stores the colors, which will be updated by the user, and to store in each Circle object's pathOptions a reference to the parallel location in this array, but am not sure how to do this.
Alternatively I would be glad to hear any other directions on how to optimize the speed.
basic version, app loads Circles from array correctly, colors are static:
import locations from "../locations.json"
function Map(props){
const [circlesArray, setCirclesArray] = useState([])
useEffect(() => { //initializes the circlesArray
let tempCirclesArray = []
locations.map(location => {
let position = [location.coordinates[1], location.coordinates[0]]
tempCirclesArray.push(
<CircleMarker center={position} radius={4}
pathOptions={
color: "red",
fillColor: "red"
} //here pathOptions is predetermined
/>
)
})
setCirclesArray(tempCirclesArray)
}, [])
return(
<div>
<div id="mapid" ref={mapRef}>
<button onClick={clickTest}>helno</button>
<MapContainer center={defaultPositon} zoom={mapZoom} scrollWheelZoom={true}>
<TileLayer
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
//map and display the Circle objects
{
circlesArray.map(circle => {
return(circle)
})
}
</MapContainer>
</div>
</div>
)