I have a webapp that displays many markers on a map that are loaded dynamically when the user moves the map around. I call an API with the bounds and get back a list of markers.
The current solution
<l-map v-if="showMap" :zoom="zoom" :center="center" @update:bounds="boundsUpdated" style="height: 100%">
<l-tile-layer :url="url" :attribution="attribution"/>
<l-marker v-for="marker in markers" :key="marker.id" :lat-lng="marker.coordinates" >
<l-icon
icon-url="https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-green.png">
</l-icon>
</l-marker>
</l-map>
...
mounted() {
let thisClass = this;
EventBus.$on('new_markers', function (payLoad) {
for (const marker of payLoad) {
thisClass.markerMap[marker.id] = marker;
}
thisClass.markers = Object.values(thisClass.markerMap)
});
},
Based on how slow it is to render the markers and how hot my laptop gets, I assume it is rendering all the markers every time.
My question
How to load with leaflet only the markers that are new in the list of markers and not the entire list every time?