Atlaslog
Atlaslog / Field Notes / Performance
Field note · Performance

Map lags once markers multiply

Quick answer

300 markers stay smooth, 800 start dropping frames and 2000 drag like a slideshow. Each default Leaflet marker is a real DOM node, so every pan recalculates and restyles thousands of elements.

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: Leaflet · OpenLayers · deck.gl
Symptom
Checklist
  1. Count the actual number of points instead of estimating it.
  2. Below 300, stop optimising the layer, since the cost is somewhere else.
  3. Above 300, switch rendering to canvas first, using preferCanvas in Leaflet.
  4. If it still lags, cull to the current viewport on moveend or add clustering.
  5. Above 20000, move the data layer to a WebGL engine such as deck.gl.
Fix

Set preferCanvas: true on the Leaflet map, or in OpenLayers share one style object and keep updateWhileInteracting false; for dense data add ol.source.Cluster with distance 40 or use the markercluster plugin. Beyond 20000 points render the data layer with deck.gl while the basemap stays raster.

Code
var map = L.map('map', {
  center: [39.9, 116.4],
  zoom: 11,
  preferCanvas: true
});
var layer = new ol.layer.Vector({
  source: source,
  style: sharedStyleObject,   // 共用一个样式,不要每条要素 new 一个
  updateWhileAnimating: false,
  updateWhileInteracting: false
});
Watch out
All 120 field notesChinese originalRunnable examples
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Cite this page

Atlaslog (2026). Map lags once markers multiply. https://www.jingweizhi.com/en/cookbook/marker-performance.html (accessed 2026-11-03).