yuvaraj119 / android-maps-extensions

android-maps-extensions
0 stars 0 forks source link

Ability to split clustered marker to list of regular markers. #16

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If some markers are located to close to each other, there is no way to show 
them separately (even in max zoom level).

Original issue reported on code.google.com by sergei.r...@gmail.com on 18 May 2013 at 1:09

GoogleCodeExporter commented 9 years ago

Original comment by maciek.g...@gmail.com on 18 May 2013 at 4:44

GoogleCodeExporter commented 9 years ago
Splitting is possible. Just need to disable clustering when hitting certain 
zoom level (see code below).

private boolean clusteringEnabled;

in onCameraChange:

if (cameraPosition.zoom > 20.7) {
  if (clusteringEnabled) {
    map.setClustering(new ClusteringSettings().enabled(false).addMarkersDynamically(true));
    clusteringEnabled = false;
  }
} else {
  if (!clusteringEnabled) {
    // your normal clustering settings
    clusteringEnabled = true;
  }
}

Original comment by maciek.g...@gmail.com on 18 May 2013 at 4:59

GoogleCodeExporter commented 9 years ago
It wokrs great! Thanks!

Original comment by sergei.r...@gmail.com on 20 May 2013 at 8:45

GoogleCodeExporter commented 9 years ago
Now it is also possible to achieve spliting a single cluster into markers by 
setting different cluster group on each marker (or just -1 in the next release 
after 1.5.1).

This was resolved as part of Issue 10.

Original comment by maciek.g...@gmail.com on 25 Aug 2013 at 1:43

GoogleCodeExporter commented 9 years ago
To split specific cluster use

Marker cluster = ...
for (Marker marker : cluster.getMarkers()) {
    marker.setClusterGroup(ClusterGroup.NOT_CLUSTERED);
}

Original comment by maciek.g...@gmail.com on 31 Aug 2013 at 4:06

GoogleCodeExporter commented 9 years ago
Just wanted to point that when using the proposed solution for disabling 
clustering when zooming in to a certain zoom level, you may also want to change 
this in DelegatingOnCameraChangeListener:

From:

@Override
public void onCameraChange(CameraPosition cameraPosition) {
   markerManager.onCameraChange(cameraPosition);
   if (onCameraChangeListener != null) {
      onCameraChangeListener.onCameraChange(cameraPosition);
   }
}

To:

@Override
public void onCameraChange(CameraPosition cameraPosition) {
   if (onCameraChangeListener != null) {
      onCameraChangeListener.onCameraChange(cameraPosition);
   }
   markerManager.onCameraChange(cameraPosition);
}

Otherwise, if you zoom out the map very quickly to a very little zoom level 
after being in a non-clustered zoom level, first all the markers are drawn to 
the map, becoming unresponsive for a while, and later clustering is reapplied.

Original comment by eer...@gmail.com on 29 Dec 2013 at 12:47

GoogleCodeExporter commented 9 years ago
@#6 eereza

That's a good idea for a custom modification in your code when implementing my 
suggestion from comment #2, but I can't do that in the code, because it would 
be inconsistent, e.g. when trying to use GoogleMap.getDisplayedMarkers in 
onCameraChange, you would get a list of markers before clustering is applied.

If I were to use my #2 suggestion, I would probably add 
BeforeCameraChangeListener and make the code look like:

@Override
public void onCameraChange(CameraPosition cameraPosition) {
   if (beforeCameraChangeListener != null) {
      beforeCameraChangeListener.beforeCameraChange(cameraPosition);
   }
   markerManager.onCameraChange(cameraPosition);
   if (onCameraChangeListener != null) {
      onCameraChangeListener.onCameraChange(cameraPosition);
   }
}

and put code from #2 into beforeCameraChange... or just hardcode it before 
markerManager is called.

Original comment by maciek.g...@gmail.com on 29 Dec 2013 at 10:28