Feature question: Configurable marker clustering radius for mashups

Home › Forums › MapPress Support › Feature question: Configurable marker clustering radius for mashups

Tagged: ,

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #22309
    lukobe
    Participant

      Hello! I’m using MapPress Pro with OpenFreeMap to display a mashup of 453 locations across Seattle (and that number will increase over time).

      I’d like to reduce the marker clustering radius so that, at the same zoom level, the map displays more clusters containing fewer markers. (See screen shot at https://imgur.com/a/7B6Odje.)

      The existing clustering functionality works well, but I’d like finer geographic granularity without increasing the initial zoom level.

      Is there a shortcode attribute, PHP filter, JavaScript hook, or undocumented setting that allows this?

      Ideally, I’d like to configure this per mashup rather than globally.

      Thanks!

      #22310
      Chris
      Keymaster

        Hi,

        There’s no setting or shortcode attribute for the cluster radius yet, but it’s a good idea, so the next release, 2.98.2, will add:

        • A “cluster radius” field in the MapPress settings, under Clustering.
        • A shortcode attribute to set it for a single map or mashup, which overrides the setting:

        Until then, you can adjust cluster radius with a filter.  Add this to your theme’s functions.php or a code snippets plugin:

        add_filter('mappress_options', function($l10n) {
        $opts = (array) ($l10n['options']['clusteringOptions'] ?? array());
        $opts['radius'] = 40; // default is 80 (pixels); smaller = more, smaller clusters
        $l10n['options']['clusteringOptions'] = $opts;
        return $l10n;
        })

        This applies to all maps on the site. To limit it to one page, you can try wrapping the three middle lines in a condition such as

        if (is_page('your-page-slug'))

        That may not work if the map is displayed in an iframe.

        #22311
        lukobe
        Participant

          Thank you!

        Viewing 3 posts - 1 through 3 (of 3 total)
        • You must be logged in to reply to this topic.