Skip to content

Conversation

@sebastianthulin
Copy link

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

  • Introduced addMarkerClusterToLeaflet in src/index.js as the main entry point, which takes a Leaflet instance and adds all MarkerCluster functionality, replacing previous implicit global patching.
  • Refactored all major classes (MarkerClusterGroup, MarkerCluster, DistanceGrid, QuickHull, Spiderfier, Refresh, and MarkerOpacity) to export factory or extension functions instead of directly patching the global L object. [1] [2] [3] [4] [5] [6] [7]

Backward compatibility and ES module support

  • Updated src/index.js and each module to automatically patch the global L object if present, ensuring backward compatibility for users loading scripts via <script> tags. [1] [2] [3]
  • Added the "module" and "exports" fields to package.json to support ES module imports and proper file resolution for modern bundlers.

API consistency and internal usage

  • Updated all internal references to use locally created classes (e.g., MarkerCluster, MarkerClusterGroup) instead of global L properties, ensuring correct class usage in modular contexts. [1] [2] [3] [4] [5]
  • Changed the rollup dependency in package.json to a compatible semver range for easier upgrades.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant