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

Marker Cluster Plugin #49

Merged
merged 1 commit into from
Oct 21, 2017
Merged

Marker Cluster Plugin #49

merged 1 commit into from
Oct 21, 2017

Conversation

tobrun
Copy link
Member

@tobrun tobrun commented Jun 21, 2017

This PR ports 2 open-source clustering algorithms from googlemaps/android-maps-utils.

  • Non-hierarchical distance based algorithm
  • Grid based algorithm

ezgif com-video-to-gif 52

cc @mapbox/android

Copy link
Member

@zugaldia zugaldia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just small notes. I realize there're a bunch of TODO and UNSUPPORTED that probably come from the original library. I'd check which ones are worth ticketing. Otherwise, let's at least add a note saying something like "This TODO item was part of the original library (http://...), we welcome contributions if you want to work on it. See https://github.com/mapbox/mapbox-plugins-android#contributing for details."

compile('com.mapbox.mapboxsdk:mapbox-android-sdk:5.1.0-beta.3@aar') {
transitive = true
}
// javadocDeps 'com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.2'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this left commented on purpose? Should we remove it instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This setup was copied from the traffic plugin and will be required for release. Since there is a need for a final 5.1.0 of the map SDK (dependency on new OnCameraIdle API). I would leave this untouched until the release of this plugin.

package="com.mapbox.mapboxsdk.plugins.cluster"
>

<application android:allowBackup="true"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can remove the application tag from here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes 👍

import java.util.Map;
import java.util.Set;

// TODO: add OnMarkerDragListener
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ticket?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

private Bounds createBoundsFromSpan(Point p, double span) {
// TODO: Use a span that takes into account the visual size of the marker, not just its
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ticket?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a todo from the original implementation


private final Algorithm<T> algorithm;

// TODO: evaluate maxSize parameter for LruCache.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ticket?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a todo from the original implementation

*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can remove this file.


final Set<MarkerWithPosition> markersToRemove = markers;
final LatLngBounds visibleBounds = mProjection.getVisibleRegion().latLngBounds;
// TODO: Add some padding, so that markers can animate in from off-screen.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ticket?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a todo from the original implementation

for (final MarkerWithPosition marker : markersToRemove) {
boolean onScreen = visibleBounds.contains(marker.position);
// Don't animate when zooming out more than 3 zoom levels.
// TODO: drop animation based on speed of device & number of markers to animate.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ticket?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a todo from the original implementation

return null;
}

// TODO: make this configurable.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ticket?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a todo from the original implementation

private static final TimeInterpolator ANIMATION_INTERP = new DecelerateInterpolator();

/**
* Animates a markerWithPosition from one position to another. TODO: improve performance for
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ticket?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a todo from the original implementation

@tobrun
Copy link
Member Author

tobrun commented Aug 1, 2017

@zugaldia I was able to make the code work with a configurable flag for MarkerView though the performance wasn't great. I'm thinking on punting on Markers as we aim to deprecate MarkerView in upcoming releases in mapbox/mapbox-gl-native#9365.

@mdakram
Copy link
Contributor

mdakram commented Aug 1, 2017

Small issue with this plugin is there is no option to disable clustering at certain zoom level, say we need to plot 5 markers in 5 mtrs radius even at last zoom level we are not able to see all markers.

Is there any workaround for this?

@zugaldia
Copy link
Member

I'm thinking on punting on Markers as we aim to deprecate MarkerView in upcoming releases in mapbox/mapbox-gl-native#9365.

👍 on reducing the scope to markers for now.

@tobrun tobrun force-pushed the tvn-clustering branch 7 times, most recently from a06a718 to 6bcfc42 Compare August 23, 2017 14:33
@simon1867
Copy link

Is there a timeframe on getting this PR merged? I'm currently in the process of migrating from Google Maps and this is one of the main features missing on MapBox for my usage.

@tobrun
Copy link
Member Author

tobrun commented Oct 20, 2017

@simon-the-canadian I'm working on rebasing this PR on latest changes of master.
Will merge once CI has approved.

cc @lilykaiser

@tobrun tobrun merged commit f0d6e4a into master Oct 21, 2017
@tobrun tobrun deleted the tvn-clustering branch October 21, 2017 08:52
@simon1867
Copy link

@tobrun Are you guys planning on releasing an artifact to maven soonish?

@maheshchakkarwar1
Copy link

When I run this code. Not working for me.
org.maplibre.android.exceptions.CalledFromWorkerThreadException: Map interactions should happen on the UI thread. Method invoked from wrong thread is latLngForPixel. at org.maplibre.android.maps.NativeMapView.checkState(NativeMapView.java:119) at org.maplibre.android.maps.NativeMapView.latLngForPixel(NativeMapView.java:713) at org.maplibre.android.maps.Projection.fromScreenLocation(Projection.java:96) at org.maplibre.android.maps.Projection.getVisibleRegion(Projection.java:153) at org.maplibre.android.maps.Projection.getVisibleRegion(Projection.java:122) at commichelin.clustering.view.DefaultClusterRenderer$RenderTask.run(DefaultCl

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

Successfully merging this pull request may close these issues.

5 participants