Skip to content

Click on a cluster to zoom in upon it? #6

Closed

Description

@itamair

Hi Vladimir ...
tnx so much for you great js mapping libraries, I am a so great fun (and user) of ...
I have read your Mapbox post on this Supercluster library, (really super ...) and cloned it for testing purposes.
I would like to test it in a project of mine, in place of the markercluster library, as I have got more than 20.000 pois to render and manage quickly.
I noticed that there is not "zoom on click" event on the (super)cluster, isn't it?
Is there any set up to activate it, or this is (simply) not yet implemented? (Any plan on this? ... on this latter case.)

Italo

Activity

  1. hyperknot commented on Apr 23, 2016

    @hyperknot

    @itamair you can do something like this (for a fixed +1 zoom):

    var clusterData = index.getClusters(bbox, zoom);
    myFeatureGroup.clearLayers();
    myFeatureGroup.addData(clusterData);
    
    myFeatureGroup.eachLayer(function (layer) {
          if (layer.feature.properties.cluster) {
                layer.on('click', function() {
                    map.setView(layer.getLatLng(), map.getZoom() + 1);
                });
          }
    });
    
  2. seleckis commented on Feb 28, 2017

    @seleckis

    I have the same task, but I need to zoom maximally to the points grouped in very close location. If it will zoom on click just by one level, that would be less convenient as user have to click multiple times to see separate markers.

  3. mourner commented on Feb 28, 2017

    @mourner
    Member

    @seleckis it will zoom to a level on which the cluster expands. So if the points in a cluster are in a very close location, it will zoom in considerably.

  4. seleckis commented on Mar 1, 2017

    @seleckis

    Oh, sorry, not noticed getClusterExpansionZoom method. Thank you!

  5. headwinds commented on Sep 13, 2017

    @headwinds

    this thread helped me create another approach which I'll share... I used flyTo to zoom into the cluster revealing all the icons.

    map.on('click', 'clusters', function (e) {
      const cluster = map.queryRenderedFeatures(e.point, { layers: ["clusters"] });
      const coordinates = cluster[0].geometry.coordinates;
      const currentZoom = map.getZoom();
      
      flyIntoCluster(map, coordinates, currentZoom);
    })
    
    
    
    flyIntoCluster(map, coordinates, currentZoom){
    
    /*
    in my case, I don't care about currentZoom instead I just hardcode max zoom which I know will reveal all the icons since the user can only zoom in this close but you may want to use currentZoom
    */
       const maxZoom = 16; 
    
      map.flyTo({
        // These options control the ending camera position: centered at
        // the target, at zoom level 16, and north up.
        center: coordinates,
        zoom: maxZoom,
        bearing: 0,
    
        // These options control the flight curve, making it move
        // slowly and zoom out almost completely before starting
        // to pan.
        speed: 1, // make the flying slow
        curve: 1, // change the speed at which it zooms out
    
        // This can be any easing function: it takes a number between
        // 0 and 1 and returns another number between 0 and 1.
        easing: function (t) {
          return t;
        }
      });
    
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions