Atlaslog
Atlaslog / Leaflet / Tutorial / Plugin ecosystem and selection
Leaflet · Tutorial

Plugin ecosystem and selection

Quick answer

This tutorial treats plugins as the source of most Leaflet capabilities and gives four criteria for judging them: recent commits, declared compatibility with 1.9, bundled CSS and global namespace changes. It walks through a complete Leaflet.markercluster integration with maxClusterRadius and spiderfyOnMaxZoom, and a hasPlugin feature check that degrades to a plain layer group. Readers can choose and load plugins without silent failures.

Last verified 2026-11-03 · Leaflet 1.9.4 · Cite this page
Key points
Example
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet.markercluster@1.5.3/dist/MarkerCluster.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet.markercluster@1.5.3/dist/MarkerCluster.Default.css">

<script src="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.js"></script>
<script src="https://cdn.jsdelivr.net/npm/leaflet.markercluster@1.5.3/dist/leaflet.markercluster.js"></script>

<script>
  var map = L.map('map').setView([39.907359, 116.391263], 10);

  var clusters = L.markerClusterGroup({
    maxClusterRadius: 60,
    spiderfyOnMaxZoom: true,
    showCoverageOnHover: false
  });

  points.forEach(function (p) {
    clusters.addLayer(L.marker([p.lat, p.lng]));
  });

  map.addLayer(clusters);   // 一次性加入,别逐个 addTo(map)
</script>
function hasPlugin(name) {
  return typeof L !== 'undefined' && typeof L[name] === 'function';
}

if (hasPlugin('markerClusterGroup')) {
  map.addLayer(buildClusters(points));
} else {
  map.addLayer(L.layerGroup(points.map(function (p) {
    return L.circleMarker([p.lat, p.lng], { radius: 4 });
  })));
}
Notes
Runnable examplesChinese originalAll Tutorials
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). Plugin ecosystem and selection. https://www.jingweizhi.com/en/leaflet/tutorials/plugins.html (accessed 2026-11-03).