Refactor Leaflet.MarkerCluster initialization to factory-based injection (backwards compatible with global scope init) #1120
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request refactors the MarkerCluster plugin to use explicit factory and extension functions for Leaflet integration, modernizing the codebase and improving modularity and compatibility. The main entry point is now
addMarkerClusterToLeaflet, which takes a Leaflet instance and extends it with clustering, spiderfier, convex hull, refresh, and opacity features. This approach allows better support for ES module usage and tree-shaking, while maintaining backward compatibility for global usage.Core refactor: modularization and explicit Leaflet extension
addMarkerClusterToLeafletinsrc/index.jsas the main entry point, which takes a Leaflet instance and adds all MarkerCluster functionality, replacing previous implicit global patching.MarkerClusterGroup,MarkerCluster,DistanceGrid,QuickHull,Spiderfier,Refresh, andMarkerOpacity) to export factory or extension functions instead of directly patching the globalLobject. [1] [2] [3] [4] [5] [6] [7]Backward compatibility and ES module support
src/index.jsand each module to automatically patch the globalLobject if present, ensuring backward compatibility for users loading scripts via<script>tags. [1] [2] [3]"module"and"exports"fields topackage.jsonto support ES module imports and proper file resolution for modern bundlers.API consistency and internal usage
MarkerCluster,MarkerClusterGroup) instead of globalLproperties, ensuring correct class usage in modular contexts. [1] [2] [3] [4] [5]rollupdependency inpackage.jsonto a compatible semver range for easier upgrades.