I am using Leaflet and Angular (with @asymmetrik/ngx-leaflet ^14.0.1 and leaflet ^1.9.2) and I have an issue with custom marker icons.
On the map, I have approximately 200-400 markers, which are "dynamic" and update each 15 s. (representing vehicles on the map). When the user clicks on the marker, a new icon is set to let the user know, what vehicle is selected. There are only 3 types of selected icon/marker.
When users click on the marker, I see it in Google Chrome Dev. Tools network tab that this image (icon) is loaded, which is fine then I click again, and nothing is shown in the network tab, because the image was cached, which is also fine. But when I click again on the same marker (same icon, therefore same image) after like 10 s., which was already cached, I see that it's loaded again in the network tab. And this is causing problems because there is always a small lag when loading images from the network (and also on slower devices/slower internet speed this will produce blank spots for a while).
I tried to do something like "asset warmup" where I preloaded these three images right after the map is ready, but the loading of the images/icons is still there after approx. 10 s. after warmup. Here is the asset warmup code
private warmMarkerAssets(): void {
const selectedMarkerIcons = ["bus/selected_bus.png", "train/selected_train.png", "trolleybus/selected_trolleybus.png"]
selectedMarkerIcons.forEach((iconPath) => {
const tempMarker = marker(
latLng(0, 0),
{ icon: icon({
iconUrl: this.assetMarkerPath + iconPath,
iconSize: [40, 40],
iconAnchor: [20, 20],
})}
)
this.map.addLayer(tempMarker)
this.map.removeLayer(tempMarker)
})
}
Do you have any advice on how to solve this or maybe you already encountered this issue before?
Thanks a lot