Marker clusters group nearby locations into one marker that shows how many locations it contains. To turn them on, go to Store Locator > Settings > Markers and enable Enable marker clusters?
Since version 3.0 the clusters are drawn as SVG shapes instead of image files, so the clusterImagePath code from earlier versions currently has no effect.
Google Maps
After you’ve enabled the marker clusters on the Store Locator > Settings > Markers page, the options below it let you change how the clusters look:
- Default style / Interpolation style. The default style switches between the low and high density color. Interpolation blends between the two based on how many locations a cluster holds.
- Low density color, High density color and Label color.
- Cluster marker shape. Choose circles, square, hexagon, diamond, donut or pulse.
Add your own shape
If none of the shapes fit your site, you can add your own. Place the code below in the functions.php inside your active theme folder.
| add_filter( 'wpsl_cluster_marker_shapes', 'my_cluster_marker_shapes' ); | |
| function my_cluster_marker_shapes( $shapes ) { | |
| $shapes['outlined'] = [ | |
| 'label' => 'Outlined circle', | |
| 'svg' => '<svg fill="${color}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240"><circle cx="120" cy="120" r="100" stroke="#ffffff" stroke-width="16" opacity=".9" /><text x="50%" y="50%" style="fill:${labelColor}" text-anchor="middle" font-size="${labelSize}" dominant-baseline="middle" font-family="roboto,arial,sans-serif">${count}</text></svg>', | |
| 'size' => 55, | |
| ]; | |
| return $shapes; | |
| } |
Your shape now appears in the Cluster marker shape dropdown. The SVG supports these placeholders:
${color}is the cluster color.${labelColor}and${labelSize}style the number.${count}is the number of locations.
Draw the shape on a 240×240 viewBox. size is the width and height in pixels on the map. If the SVG isn’t valid, the default circles are used instead.
Use your own image
The cluster is drawn as an SVG image, and browsers don’t load external files inside one. So you have to embed the image in the SVG, not link to it. Place a cluster.png in a wpsl-markers folder inside your active theme folder, then add the code below to the functions.php in your active theme folder.
| add_filter( 'wpsl_cluster_marker_shapes', 'my_cluster_image_shape' ); | |
| function my_cluster_image_shape( $shapes ) { | |
| $file = get_stylesheet_directory() . '/wpsl-markers/cluster.png'; | |
| if ( ! file_exists( $file ) ) { | |
| return $shapes; | |
| } | |
| $image = 'data:image/png;base64,' . base64_encode( file_get_contents( $file ) ); | |
| $shapes['my-image'] = [ | |
| 'label' => 'Custom image', | |
| 'svg' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240"><image href="' . $image . '" width="240" height="240" /><text x="50%" y="50%" style="fill:${labelColor}" text-anchor="middle" font-size="${labelSize}" dominant-baseline="middle" font-family="roboto,arial,sans-serif">${count}</text></svg>', | |
| 'size' => 50, | |
| ]; | |
| return $shapes; | |
| } |
Then select Custom image as the cluster marker shape. Keep the image small, a few KB at most, because it’s embedded in every store locator page.
Mapbox
Mapbox uses three circle sizes: under 100 locations, 100–750, and more than 750. There are no cluster style settings for Mapbox, so to change the colors, add the code below to the functions.php inside your active theme folder.
| add_filter( 'wpsl_cluster_marker_props', 'my_mapbox_cluster_colors' ); | |
| function my_mapbox_cluster_colors( $props ) { | |
| if ( isset( $props['circle'] ) ) { | |
| // Color below 100, threshold, colour 100 - 750, threshold, colour above 750. | |
| $props['circle']['color'] = [ '#2b83ba', 100, '#fdae61', 750, '#d7191c' ]; | |
| } | |
| return $props; | |
| } |
$props['circle']['radius'] uses the same format, for example [ 20, 100, 30, 750, 40 ].
OpenStreetMap and Stadia Maps
These services use the standard Leaflet cluster styles. Small is under 10 locations, medium is under 100, and large is 100 or more.
To change them, go to Appearance > Customize > Additional CSS, paste the code below, and click Publish. If your theme doesn’t have a Customize menu (block themes such as Twenty Twenty-Five), go to Appearance > Editor > Styles, click the ⋮ icon at the top of the Styles panel, and choose Additional CSS.
| .wpsl-canvas-osm .marker-cluster-small, | |
| .wpsl-canvas-stadia .marker-cluster-small { background-color: rgba(43, 131, 186, .4); } | |
| .wpsl-canvas-osm .marker-cluster-small div, | |
| .wpsl-canvas-stadia .marker-cluster-small div { background-color: rgba(43, 131, 186, .8); } | |
| .wpsl-canvas-osm .marker-cluster-medium, | |
| .wpsl-canvas-stadia .marker-cluster-medium { background-color: rgba(253, 174, 97, .4); } | |
| .wpsl-canvas-osm .marker-cluster-medium div, | |
| .wpsl-canvas-stadia .marker-cluster-medium div { background-color: rgba(253, 174, 97, .8); } | |
| .wpsl-canvas-osm .marker-cluster-large, | |
| .wpsl-canvas-stadia .marker-cluster-large { background-color: rgba(215, 25, 28, .4); } | |
| .wpsl-canvas-osm .marker-cluster-large div, | |
| .wpsl-canvas-stadia .marker-cluster-large div { background-color: rgba(215, 25, 28, .8); } |