Advanced map markers with Extensions for Leaflet Map

In the previous post we saw how to customize markers with Leaflet Map: custom icons, tooltips, HTML popups and Font Awesome markers using [leaflet-extramarker]. In this post we’ll go a step further with the Extensions for Leaflet Map plugin: clustering for maps with lots of points, navigable marker lists and markers from GeoJSON files. If…

destacada marcadores avanzados leaflet map

In the previous post we saw how to customize markers with Leaflet Map: custom icons, tooltips, HTML popups and Font Awesome markers using [leaflet-extramarker].

In this post we’ll go a step further with the Extensions for Leaflet Map plugin: clustering for maps with lots of points, navigable marker lists and markers from GeoJSON files.

If you don’t have the plugin installed yet, go to Plugins > Add New, search for Extensions for Leaflet Map and install it. You need to have Leaflet Map installed and active first.

Clustering with [cluster]

When you have lots of markers on the map, clustering is a technique that groups nearby points into a single element showing how many markers it contains. As you zoom in, the clusters split apart until the individual markers are shown.

01 grouped clusters
Grouped marker clusters

Imagine you need to show eight monuments in Granada on your map. What happens when the user zooms out so far that they only see a single point? Especially if we have another group of monuments in another city, we won’t know how many points of interest there are in each city, let alone tell them apart. This technique is used to make that information easier to read. Let’s look at this example:

[leaflet-map zoom=14 lat=37.18 lng=-3.59]

[leaflet-marker lat=37.1760 lng=-3.5880 title="Alhambra"]Alhambra[/leaflet-marker]
[leaflet-marker lat=37.1767 lng=-3.5994 title="Catedral de Granada"]Catedral de Granada[/leaflet-marker]
[leaflet-marker lat=37.1771 lng=-3.5902 title="Museo de la Alhambra"]Museo de la Alhambra[/leaflet-marker]
[leaflet-marker lat=37.1804 lng=-3.5862 title="Jardines del Generalife"]Jardines del Generalife[/leaflet-marker]
[leaflet-marker lat=37.1805 lng=-3.5918 title="Palacio de Carlos V"]Palacio de Carlos V[/leaflet-marker]
[leaflet-marker lat=37.1811 lng=-3.5975 title="Monasterio de San Jerónimo"]Monasterio de San Jerónimo[/leaflet-marker]
[leaflet-marker lat=37.1823 lng=-3.5889 title="Museo Arqueológico"]Museo Arqueológico de Granada[/leaflet-marker]
[leaflet-marker lat=37.1779 lng=-3.5943 title="Capilla Real"]Capilla Real[/leaflet-marker]

[cluster]
02 clustering zoom
How marker clusters behave when zooming

The [cluster] shortcode always goes at the end, after all the markers. It’s what tells the map to group them as soon as showing them all at once stops being practical.

Controlling the cluster radius

This shortcode ([cluster]) has a parameter (maxClusterRadius) that lets you control the cluster radius:

[cluster maxClusterRadius=40]

With maxClusterRadius=40 the clusters are smaller and split apart sooner as you zoom in. The default value is 80.

03 clustering changing the cluster radius
Here we can see the markers split apart sooner when the cluster radius is reduced.

Disabling clustering from a given zoom level

We could also disable clustering from a certain zoom level onwards:

[cluster disableClusteringAtZoom=15]

In this case, from zoom level 15 onwards the markers are shown individually even if they’re close together.

cluster disable clustering at zoom
By adding disableClusteringAtZoom with a value of 15, marker grouping stops working once that zoom level is reached.

Other parameters

Other parameters we could use to improve our clusters are the following:

  • showCoverageOnHover: shows the area covered by the cluster on mouse hover (1/0, default 1). It can be useful, although it can also be a bit confusing because it looks like a kind of polygon representing the bounds that enclose the markers.
  • zoomToBoundsOnClick: zooms to the cluster’s area when clicked (1/0, default 1).
  • spiderfyOnMaxZoom: at maximum zoom, spreads the markers out in a spiral so you can see them all (1/0, default 1)

💡 [cluster] also works with [leaflet-gpx], [leaflet-kml] and [leaflet-geojson], not just with [leaflet-marker].

Spread strategies with [placementstrategies]

Sometimes several markers are at exactly the same geographic point. In that case, standard clustering would overlap them even at maximum zoom. To solve this, [placementstrategies] controls how those markers are visually spread out when the cluster expands.

Let’s look at an example that may make it a bit clearer:

[leaflet-map zoom=14 lat=37.18 lng=-3.59]

[leaflet-marker lat=37.1760 lng=-3.5880 title="Marcador 1"]Marcador 1[/leaflet-marker]
[leaflet-marker lat=37.1760 lng=-3.5880 title="Marcador 2"]Marcador 2[/leaflet-marker]
[leaflet-marker lat=37.1760 lng=-3.5880 title="Marcador 3"]Marcador 3[/leaflet-marker]
[leaflet-marker lat=37.1760 lng=-3.5880 title="Marcador 4"]Marcador 4[/leaflet-marker]
[leaflet-marker lat=37.1760 lng=-3.5880 title="Marcador 5"]Marcador 5[/leaflet-marker]
[leaflet-marker lat=37.1760 lng=-3.5880 title="Marcador 6"]Marcador 6[/leaflet-marker]
[leaflet-marker lat=37.1760 lng=-3.5880 title="Marcador 7"]Marcador 7[/leaflet-marker]
[leaflet-marker lat=37.1760 lng=-3.5880 title="Marcador 8"]Marcador 8[/leaflet-marker]
[leaflet-marker lat=37.1760 lng=-3.5880 title="Marcador 9"]Marcador 9[/leaflet-marker]

[placementstrategies elementsPlacementStrategy="default" maxClusterRadius=40]

As we can see, all the markers are located at exactly the same point, so only one of them is visible. When we set the placement strategy with placementstrategies, a cluster appears with all the markers grouped together.

placementstrategies grouped
Grouped marker cluster.

But when you click on it, the markers spread out using the strategy we chose. In this example we chose the default strategy, which is a kind of spiral. This doesn’t mean the markers are actually located in a spiral; it’s just a “friendlier” way to see them.

placementstrategies spread out
Marker cluster spread out in a spiral.

You can also use this command with [leaflet-extramarker].

As always, you can set the default values for each parameter under Settings > Leaflet Map > Extensions for Leaflet Map and override them in each map’s shortcode.

Markers from GeoJSON with [geojsonmarker]

Adding markers with [leaflet-marker] or [leaflet-extramarker] is fine for four or five markers, ten if you’re patient. But if you’ve ever worked with a GIS, you’ll know how convenient it is to generate data in that kind of software, manage it and then export it to compatible formats such as GeoJSON.

But don’t worry: if you’ve never used a GIS, or don’t even know what I’m talking about, there are very convenient alternatives. First of all, I suggest you read this post to learn what a GIS is. And if you don’t need such an advanced tool, geojson.io may be enough: an online tool that lets you draw points, polygons and so on, attach data to each of them just as you would in a GIS, and generate a GeoJSON file you can import into WordPress to show more complex data.

So, as we were saying, if you have data in GeoJSON format, [geojsonmarker] lets you style markers differently according to each feature’s properties, without defining every point with its own shortcode. That saves us a lot of headaches.

To follow this example, upload the monumentos-granada.geojson file to your WordPress site (under Media > Add New) and copy the URL it’s given.

⚠️ You’ll probably need a plugin such as WP Add Mime Types to allow uploading new file types.

The file contains eight monuments with a Tipo (type) property that takes the values monumento, iglesia, museo and jardin (monument, church, museum and garden). This lets us style the markers by type, as follows:

[leaflet-map fitbounds]

[leaflet-geojson src="https://tudominio.com/wp-content/uploads/monumentos-granada.geojson"]{name}[/leaflet-geojson]

[geojsonmarker property=Tipo auto]
geojson markers 1
Grouped markers with the category filter enabled.

With auto, the plugin assigns a different color to each value of the Tipo property without you having to define them. It works for up to 16 different values with standard markers and 14 with ExtraMarkers.

Now let’s look at an example with manually defined colors:

[leaflet-map fitbounds]

[leaflet-geojson src="https://guorpre.com/wp-content/uploads/2026/04/monumentos-granada.geojson"]{Texto}[/leaflet-geojson]

[geojsonmarker property=Tipo values="Monumento,Iglesia,Museo,Jardín" iconprops="red,blue,green,orange" groups="Monumento,Iglesia, Museo,Jardín" icondefault=blue]
geojson markers 2
Map with the category filter enabled.

If we want to control the groups and show or hide categories, we’ll do the following:

[leaflet-map fitbounds]

[leaflet-geojson src="https://tudominio.com/wp-content/uploads/monumentos-granada.geojson"]{name}[/leaflet-geojson]

[geojsonmarker property=tipo values="monumento,iglesia,museo,jardin" iconprops="red,blue,green,orange" icondefault=blue groups="Monumentos,Iglesias,Museos,Jardines" visible=1,1,1,1 position=topright]

With groups, a control appears on the map that lets the user show or hide each category. visible defines which ones are visible on load (1 visible, 0 hidden).

geojson markers 3
In this case some categories have been selected and the rest are grouped as “others”.

You have lots of points in your GeoJSON and want to add clustering? It’s as easy as following the steps we already saw for regular markers.

[leaflet-map fitbounds]

[leaflet-geojson src="https://tudominio.com/wp-content/uploads/monumentos-granada.geojson"]{name}[/leaflet-geojson]

[geojsonmarker property=tipo auto maxClusterRadius=60]
geojson markers 4
Here only the group showing the rest of the categories together remains.

You can add the [cluster] parameters directly to the [geojsonmarker] shortcode.

Marker list with [listmarker]

The [listmarker] command generates a panel next to the map with the marker titles. Clicking an item in the list centers the map on that marker and opens its popup, which can help users find their way around the map. It’s best not to use it if the list is extremely long, though.

⚠️ The title parameter is required in [leaflet-marker] and [leaflet-extramarker] for the marker to appear in the list. Without title, the marker isn’t included.

Let’s see an example of how [listmarker] works:

[leaflet-map zoom=14 lat=37.18 lng=-3.59]

[leaflet-marker lat=37.1760 lng=-3.5880 title="Alhambra"]Alhambra[/leaflet-marker]
[leaflet-marker lat=37.1767 lng=-3.5994 title="Catedral de Granada"]Catedral de Granada[/leaflet-marker]
[leaflet-marker lat=37.1771 lng=-3.5902 title="Museo de la Alhambra"]Museo de la Alhambra[/leaflet-marker]
[leaflet-marker lat=37.1804 lng=-3.5862 title="Jardines del Generalife"]Jardines del Generalife[/leaflet-marker]

[listmarker]
listmarker 01
Marker list enabled

Now imagine we want the list collapsed by default and hover enabled. You just need to add these two attributes to [listmarker]:

[listmarker collapse=true hover=true]

With hover=true, hovering over an item in the list highlights that marker on the map without needing to click.

listmarker 02
Collapsed marker list.

If you use [cluster], keep in mind that the shortcode must go after [listmarker]:

[leaflet-map zoom=14 lat=37.18 lng=-3.59]

[leaflet-marker lat=37.1760 lng=-3.5880 title="Alhambra"]Alhambra[/leaflet-marker]
[leaflet-marker lat=37.1767 lng=-3.5994 title="Catedral de Granada"]Catedral de Granada[/leaflet-marker]
[leaflet-marker lat=37.1771 lng=-3.5902 title="Museo de la Alhambra"]Museo de la Alhambra[/leaflet-marker]
[leaflet-marker lat=37.1804 lng=-3.5862 title="Jardines del Generalife"]Jardines del Generalife[/leaflet-marker]

[listmarker update=true]
[cluster]
listmarker 03
Marker list with the markers clustered.

With update=true (the default), the list only shows the markers visible in the current viewport. When you zoom or pan the map, the list updates.

If you’re using GeoJSON, you’ll need to specify which property in the file is used as the name in the list:

[leaflet-map fitbounds]

[leaflet-geojson src="https://tudominio.com/wp-content/uploads/monumentos-granada.geojson"]{name}[/leaflet-geojson]

[listmarker propertyname=name]

Conclusion

As you’ve seen in both the previous post and this one, with Leaflet Map and Extensions for Leaflet Map you have practically every common marker scenario in WordPress covered.

Now you can fill your maps with markers like a pro. Go wild…

Jesús Yesares-García Avatar

Leave a Reply

Your email address will not be published. Required fields are marked *