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

[Feature] Add anchor to ClusterItem interface. #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.sharewire.googlemapsclustering;

import android.graphics.PointF;
import android.support.annotation.Nullable;

/**
Expand Down Expand Up @@ -37,4 +38,11 @@ public interface ClusterItem extends QuadTreePoint {
*/
@Nullable
String getSnippet();

/**
* The anchor of the item.
*
* @return the anchor of the item
*/
PointF getAnchor();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.content.Context;
import android.graphics.PointF;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
Expand Down Expand Up @@ -114,6 +115,7 @@ void render(@NonNull List<Cluster<T>> clusters) {
Marker markerToAdd;

BitmapDescriptor markerIcon = getMarkerIcon(clusterToAdd);
PointF markerAnchor = getMarkerAnchor(clusterToAdd);
String markerTitle = getMarkerTitle(clusterToAdd);
String markerSnippet = getMarkerSnippet(clusterToAdd);

Expand All @@ -123,6 +125,7 @@ void render(@NonNull List<Cluster<T>> clusters) {
markerToAdd = mGoogleMap.addMarker(new MarkerOptions()
.position(new LatLng(parentCluster.getLatitude(), parentCluster.getLongitude()))
.icon(markerIcon)
.anchor(markerAnchor.x, markerAnchor.y)
.title(markerTitle)
.snippet(markerSnippet)
.zIndex(FOREGROUND_MARKER_Z_INDEX));
Expand All @@ -132,6 +135,7 @@ void render(@NonNull List<Cluster<T>> clusters) {
markerToAdd = mGoogleMap.addMarker(new MarkerOptions()
.position(new LatLng(clusterToAdd.getLatitude(), clusterToAdd.getLongitude()))
.icon(markerIcon)
.anchor(markerAnchor.x, markerAnchor.y)
.title(markerTitle)
.snippet(markerSnippet)
.alpha(0.0F)
Expand All @@ -158,6 +162,16 @@ private BitmapDescriptor getMarkerIcon(@NonNull Cluster<T> cluster) {
return checkNotNull(clusterIcon);
}

@NonNull
private PointF getMarkerAnchor(@NonNull Cluster<T> cluster) {
List<T> clusterItems = cluster.getItems();
if (clusterItems.size() > 1) {
return new PointF(0.5f, 0.5f);
} else {
return clusterItems.get(0).getAnchor();
}
}

@Nullable
private String getMarkerTitle(@NonNull Cluster<T> cluster) {
List<T> clusterItems = cluster.getItems();
Expand Down