Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layersupport + freezable #13

Closed
timelyportfolio opened this issue Aug 31, 2017 · 2 comments
Closed

layersupport + freezable #13

timelyportfolio opened this issue Aug 31, 2017 · 2 comments

Comments

@timelyportfolio
Copy link

Thanks so much for all your work on this. Is there any way to use layersupport and freezable together/simultaneously?

@ghybs
Copy link
Owner

ghybs commented Aug 31, 2017

Hi,

Thank you for your message.

Indeed it looks like the naming collision on _originalOnAdd prevents the simultaneous integration of both plugins.

By using a workaround to prevent this naming collision, all seems the work correctly:

// Modify _originalOnAdd before LayerSupport kicks in, in order to prevent naming collision.
L.MarkerClusterGroup.include({
  // Original onAdd is already stored in _originalOnAdd and replaced in onAdd by Freezable plugin.
  _originalOnAddFreezable: L.MarkerClusterGroup.prototype._originalOnAdd,

  onAdd: function(map) {
    var frozenZoom = this._zoom;

    // Use the new name for the original onAdd.
    this._originalOnAddFreezable(map);

    // Rest of method is unchanged compared to Freezable plugin.
    if (this._frozen) {

      // Restore the specified frozenZoom if necessary.
      if (frozenZoom >= 0 && frozenZoom !== this._zoom) {
        // Undo clusters and markers addition to this._featureGroup.
        this._featureGroup.clearLayers();

        this._zoom = frozenZoom;

        this.addLayers([]);
      }

      // Replace the callbacks on zoomend and moveend events.
      map.off('zoomend', this._zoomEnd, this);
      map.off('moveend', this._moveEnd, this);
      map.on('zoomend moveend', this._viewChangeEndNotClustering, this);
    }
  }
});

Live demo: http://playground-leaflet.rhcloud.com/rono/1/edit?html,output

Versions:

  • Leaflet 1.2.0
  • Leaflet.markercluster 1.1.0
  • Leaflet.MarkerCluster.Freezable 0.1.1
  • workaround
  • Leaflet.MarkerCluster.LayerSupport 1.0.5

@timelyportfolio
Copy link
Author

Perfect, thanks so much for the response and more importantly thanks for your efforts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants