question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add markercluster Identification Property

See original GitHub issue
  • I’m reporting a bug, not asking for help
  • I’m sure this is a Leaflet.MarkerCluster code issue, not an issue with my own code nor with the framework I’m using (Cordova, Ionic, Angular, React…)
  • I’ve searched through the issues to make sure it’s not yet reported

Hi all! I’m the author of leaflet drawing plugin leaflet.pm and I’m currently trying to make our two plugins work together (https://github.com/codeofsumit/leaflet.pm/issues/316).

If developers are using both our plugins, spiderlegs are editable and drag & edit features affect the whole marker group instead of single markers. Also the cluster-marker becomes editable. image

As far as I see it, leaflet.pm should basically only consider “core” layers/markers and ignore helper markers of any plugins. I consider the cluster-marker and the spiderlegs to be helpers of the markercluster plugin.

My issue currently is to identify layers from markercluster. I’m checking against the _group and _markerCluster property. I could not find any way to identify a Spiderleg layer, so I additionally check markers for _spiderLegs and remove leaflet.pm classes after their initialization. This is far from ideal and sprinkles markercluster specific if-else statements across the library code.

Suggestion: In leaflet.PM I’ve added pmTempLayer: true to any helper-layer that is created by the library for others to identify and ignore, if necessary. Would it make sense to introduce a similar property like markerclusterHelper: true to the cluster-marker and spiderlegs to easily identify them? With that, I could check for that property and ignore these layers.

Alternative If you would like to add leaflet.PM compatibility to markercluster from your side, you could also add the option pmIgnore: true to all cluster-marker and the spiderlegs and they’re ignored automatically by leaflet.pm. I’d be happy to create a PR for this if this is an option for you.

What do you think?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:5
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
codeofsumitcommented, Jul 20, 2018

@danzel I was able to make editing of my plugin work together with markercluster: markercluster

(spiderlegs are getting ignored and clustermarker updates correctly 👍 )

But I still have some problems with the removal of markers. When I fan out a cluster and delete a marker from the cluster it seems as if markercluster events are getting lost. The icon is not updated, I can’t collapse the cluster again, mouse events do not work anymore. No error is thrown though. Any idea what could cause this?

Here are the sub-plugin changes I have so far:

L.MarkerClusterGroup.include({
    originalInit: L.MarkerClusterGroup.prototype.initialize,
    initialize(options) {
        // ignore spiderlegs
        this.options.spiderLegPolylineOptions.pmIgnore = true;

        // ignore this, not sure what it is though 🤔
        this.options.polygonOptions.pmIgnore = true;

        this.originalInit(options);
    },

    // Fire regular layeradd event when adding a layer via markercluster
    _originalAddLayer: L.MarkerClusterGroup.prototype.addLayer,
    addLayer(layer) {
        this._originalAddLayer(layer);

        return this.fire('layeradd', { layer });
    },
});

// add pmIgnore to the cluster marker
L.MarkerCluster.include({
    originalInit: L.MarkerCluster.prototype.initialize,
    initialize(...args) {
        this.options.pmIgnore = true;

        this.originalInit(...args);
    },
});

Any hints are appreciated 👍

0reactions
ghybscommented, Jul 23, 2018

Hi @codeofsumit,

Indeed, you should remove the Marker from the MCG instead of from the map directly.

Or use Leaflet.FeatureGroup.SubGroup or Leaflet.MarkerCluster.LayerSupport.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Leaflet markercluster: How can I create a ... - Stack Overflow
Is there some better way to create markers that have an ID that I can refer to later? There are ways that work...
Read more >
Marker Clustering | Maps JavaScript API - Google Developers
Overview. This tutorial shows you how to use marker clusters to display a large number of markers on a map. You can use...
Read more >
How to Create Marker and Marker Cluster with Leaflet Map
L.map() we define one id in it. This id will be the id that we add to our HTML page. You can still...
Read more >
How to add Marker Cluster on Google Map - YouTube
For more video please like ,share and subscribe to my channel. facebook ...
Read more >
leaflet - How do I Cluster by an Attrbute? - GIS Stack Exchange
Simply create one Marker Cluster Group per State. Loop through your markers, and depending on their State attribute, add them to the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found