subplugin for the Leaflet.MarkerCluster that implements new possibilities how to place clustered chidren markers
include Leaflet and Leaflet.MarkerCluster libraries (cdnjs, ungkg, …) or npm install these libraries with npm install leaflet leaflet.markercluster
download and include built leaflet-markercluster.placementstrategies.js or leaflet-markercluster.placementstrategies.src.js file from dist folder or npm install npm install leaflet.markercluster.placementstrategies
create L.markerClusterGroup instance, add markers, and define placement strategy and other options. We recommend to hide spiderLegs by spiderLegPolylineOptions: {weight: 0}
var markers = L.markerClusterGroup({
spiderLegPolylineOptions: { weight: 0 },
clockHelpingCircleOptions: {
weight: 0.7,
opacity: 1,
color: "black",
fillOpacity: 0,
dashArray: "10 5",
},
elementsPlacementStrategy: "clock",
helpingCircles: true,
spiderfyDistanceSurplus: 25,
spiderfyDistanceMultiplier: 1,
elementsMultiplier: 1.4,
firstCircleElements: 8,
});
for (var i = 0; i < 10000; i++) {
var circle = L.circleMarker([Math.random() * 30, Math.random() * 30], {
fillOpacity: 0.7,
radius: 8,
fillColor: "red",
color: "black",
});
markers.addLayer(circle);
}
map.addLayer(markers);
This sub-plugin can be easily used also with react-leaflet.
npm install leaflet react-leaflet leaflet.markercluster react-leaflet-markerclusternpm install leaflet.markercluster.placementstrategiesimport L from "leaflet";
import {
Map,
Marker,
TileLayer,
LayersControl,
LayerGroup,
} from "react-leaflet";
import MarkerClusterGroup from "react-leaflet-markercluster";
import "leaflet.markercluster.placementstrategies";
import "./../node_modules/leaflet/dist/leaflet.css";
export const MapComponent: React.FC = ({ center, zoom, points }) => {
return (
<Map center={center} zoom={zoom}>
<LayersControl position="bottomright">
<LayersControl.BaseLayer name="Open Street Maps">
<TileLayer
attribution="© <a href='https://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors"
url="https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png"
/>
</LayersControl.BaseLayer>
</LayersControl>
<LayerGroup>
<MarkerClusterGroup
showCoverageOnHover={false}
spiderLegPolylineOptions=
clockHelpingCircleOptions=
elementsPlacementStrategy="clock-concentric"
helpingCircles={true}
maxClusterRadius={25}
iconCreateFunction={(cluster) => {
return divIcon({
html: `<div class="outer"><div class="inner"><span class="label">${cluster.getChildCount()}</span></div></div>`,
className: "marker-cluster",
iconSize: [20, 20],
});
}}
>
{points.map((point, ii) => {
return (
<Marker key={ii} position={point.coords}>
<Popup>
<div className="tooltip-content">{point.info}</div>
</Popup>
</Marker>
);
})}
</MarkerClusterGroup>
</LayerGroup>
</Map>
);
};
npm installnpm run buildnpm start watches changes in js files and builds
spiral - snail/spiral placement

one-circle - put all the elements into one circle

concentric - elements are placed automatically into concentric circles, there is a maximum of 4 circles

clock - fills circles around the cluster marker in the style of clocks

clock-concentric - in the case of one circle, elements are places based on the concentric style, more circles are dislocated in the clock style

original-locations - elements are placed at their original locations

*can be changed - _circleSpiralSwitchover variable in the original markerCluster code
the new type geometry called “helpingCircle” to make the cluster more visually-consistent (not supported for origin-locations strategy and spiral strategy)
animation and animateAddingMarkers variables)circleMarkers should be preferred to markersL.SVG renderer if possible (L.Canvas renderer has technical issues with some visual properties, see #6)