Currently, I am in the process of developing an application using React-leaflet version 3 with TypeScript. One of the requirements for my app is to add multiple icons for one position on the map. For example, a specific [lat,long] location could be identified as a blood donation camp in the morning at 8 A.M., and then transform into an outdoor checkup center; followed by a makeshift music concert and free-food center in the afternoon at 3 P.M. This means that I need to place at least two icons for each marker at a given time. Unfortunately, the icon attribute in the marker tag only allows for a single value.
I attempted a solution using L.divIcon
, but have not had success thus far.
const mapNodeIcon = L.divIcon({
html: `<div class="multi-icon-div">
<img src="../icon/myIcons/bloodDonCamp.svg" width="30px"/>
<img src="../icon/myIcons/outdoorCheck.svg" width="30px"/>
</div>`,
iconAnchor: [10, 10],
popupAnchor: [0, -19],
iconSize: [55, 55],
});
Marker Tag
<Marker
key={myMap.id}
position={[lat, lng]}
icon={mapNodeIcon}
>
<Popup>
<h3>This is the event location</h3>
</Popup>
</Marker>
The issue I'm encountering here is that the SVG icon images are not loading within the div structure, even though the iconDiv appears as a marker on the map. How can I resolve this problem?
While it may seem like a simple question, I wonder if this method is the most efficient way to solve the issue. Since my map will display different SVG icons based on the time of day (morning and afternoon), I am concerned about the speed of rendering for a multi-node map. Any suggestions or assistance would be greatly appreciated.