本文整理汇总了Java中com.google.maps.android.clustering.Cluster类的典型用法代码示例。如果您正苦于以下问题:Java Cluster类的具体用法?Java Cluster怎么用?Java Cluster使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Cluster类属于com.google.maps.android.clustering包,在下文中一共展示了Cluster类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBeforeClusterRendered
import com.google.maps.android.clustering.Cluster; //导入依赖的package包/类
@Override
protected void onBeforeClusterRendered(Cluster<IssueMarker> cluster, MarkerOptions options) {
super.onBeforeClusterRendered(cluster, options);
// Cluster customization
Context context = mMap.getContext();
int clusterSize = cluster.getSize();
String clusterIconRes = "cluster1";
for (int i = 0; i < CLUSTER_THRESHOLDS.length; i++) {
int threshold = CLUSTER_THRESHOLDS[i];
if (clusterSize >= threshold) clusterIconRes = "cluster" + (i + 2);
}
mClusterIconGenerator.setBackground(getClusterIcon(context, clusterIconRes));
mClusterIconGenerator.setTextAppearance(R.style.ClusterIconText);
Bitmap sizeIcon = mClusterIconGenerator.makeIcon(String.valueOf(clusterSize));
options.icon(BitmapDescriptorFactory.fromBitmap(sizeIcon));
}
示例2: onClusterClick
import com.google.maps.android.clustering.Cluster; //导入依赖的package包/类
@Override
public boolean onClusterClick(Cluster<CustomMarker> cluster) {
// Zoom in the cluster. Need to create LatLngBounds and including all the cluster items
// inside of bounds, then animate to center of the bounds.
// Create the builder to collect all essential cluster items for the bounds.
LatLngBounds.Builder builder = LatLngBounds.builder();
for (CustomMarker item : cluster.getItems()) {
builder.include(item.getPosition());
}
// Get the LatLngBounds
final LatLngBounds bounds = builder.build();
// Animate camera to the bounds
try {
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 150));
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
示例3: setUpCluster
import com.google.maps.android.clustering.Cluster; //导入依赖的package包/类
private void setUpCluster(){
mClusterManager = new ClusterManager<MyItem>(this, mMap);
mClusterManager.setOnClusterClickListener(new ClusterManager.OnClusterClickListener<MyItem>() {
@Override
public boolean onClusterClick(Cluster<MyItem> cluster) {
return false;
}
});
mClusterManager.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<MyItem>() {
@Override
public boolean onClusterItemClick(MyItem myItem) {
// Toast.makeText(MainActivity.this, myItem.getPosition().toString(), Toast.LENGTH_SHORT).show();
itemSelected = myItem;
return false;
}
});
//mMap.setOnCameraIdleListener(mClusterManager);
}
示例4: onClusterClick
import com.google.maps.android.clustering.Cluster; //导入依赖的package包/类
@Override
public boolean onClusterClick(Cluster<Asset> cluster) {
// Show a toast with some info when the cluster is clicked.
String firstName = cluster.getItems().iterator().next().name;
Toast.makeText(this, cluster.getSize() + " (including " + firstName + ")", Toast.LENGTH_SHORT).show();
// Zoom in the cluster. Need to create LatLngBounds and including all the cluster items
// inside of bounds, then animate to center of the bounds.
// Create the builder to collect all essential cluster items for the bounds.
LatLngBounds.Builder builder = LatLngBounds.builder();
for (ClusterItem item : cluster.getItems()) {
builder.include(item.getPosition());
}
// Get the LatLngBounds
final LatLngBounds bounds = builder.build();
// Animate camera to the bounds
try {
getMap().animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
开发者ID:aminyazdanpanah,项目名称:google-maps-3D-pie-chart-marker-clustering-java,代码行数:27,代码来源:DemoActivity.java
示例5: onBeforeClusterRendered
import com.google.maps.android.clustering.Cluster; //导入依赖的package包/类
@Override
protected void onBeforeClusterRendered(Cluster<ScoutingGroepInfo> cluster, MarkerOptions markerOptions) {
Deelgebied deelgebied = Deelgebied.resolveOnLocation(cluster.getPosition());
if(deelgebied != null) {
Set<String> enabled = JappPreferences.getAreasEnabled();
if(!enabled.contains(deelgebied.getName())) {
markerOptions.visible(false);
}
}
MarkerIdentifier identifier = new MarkerIdentifier.Builder()
.setType(MarkerIdentifier.TYPE_SC_CLUSTER)
.add("size", String.valueOf(cluster.getSize()))
.create();
markerOptions.title(new Gson().toJson(identifier));
super.onBeforeClusterRendered(cluster, markerOptions);
}
示例6: getClusters
import com.google.maps.android.clustering.Cluster; //导入依赖的package包/类
@Override
public Set<? extends Cluster<T>> getClusters(double zoom) {
long numCells = (long) Math.ceil(256 * Math.pow(2, zoom) / GRID_SIZE);
SphericalMercatorProjection proj = new SphericalMercatorProjection(numCells);
HashSet<Cluster<T>> clusters = new HashSet<Cluster<T>>();
LongSparseArray<StaticCluster<T>> sparseArray = new LongSparseArray<StaticCluster<T>>();
synchronized (mItems) {
for (T item : mItems) {
Point p = proj.toPoint(item.getPosition());
long coord = getCoord(numCells, p.x, p.y);
StaticCluster<T> cluster = sparseArray.get(coord);
if (cluster == null) {
cluster = new StaticCluster<T>(proj.toLatLng(new Point(Math.floor(p.x) + .5, Math.floor(p.y) + .5)));
sparseArray.put(coord, cluster);
clusters.add(cluster);
}
cluster.add(item);
}
}
return clusters;
}
示例7: getClustersInternal
import com.google.maps.android.clustering.Cluster; //导入依赖的package包/类
private Set<? extends Cluster<T>> getClustersInternal(int discreteZoom) {
Set<? extends Cluster<T>> results;
mCacheLock.readLock().lock();
results = mCache.get(discreteZoom);
mCacheLock.readLock().unlock();
if (results == null) {
mCacheLock.writeLock().lock();
results = mCache.get(discreteZoom);
if (results == null) {
results = mAlgorithm.getClusters(discreteZoom);
mCache.put(discreteZoom, results);
}
mCacheLock.writeLock().unlock();
}
return results;
}
示例8: onClusterClick
import com.google.maps.android.clustering.Cluster; //导入依赖的package包/类
/**
*
*/
@Override
public boolean onClusterClick(Cluster<MyItem> cluster) {
/*
* Calculate geographic area of cluster.
*/
LatLngBounds.Builder builder = LatLngBounds.builder();
Collection<MyItem> ci = cluster.getItems();
for(MyItem item : ci) {
builder.include(item.getPosition());
}
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(builder.build(), 0);
map.moveCamera(cameraUpdate);
return false;
}
示例9: shouldRenderAsCluster
import com.google.maps.android.clustering.Cluster; //导入依赖的package包/类
@UiThreadTest
@Test
public void shouldRenderAsCluster() {
Cluster<TruckCluster> cluster = mock(Cluster.class);
when(cluster.getSize())
.thenReturn(1)
.thenReturn(2);
// Should not render as cluster with only 1 item
assertThat(clusterRenderer.shouldRenderAsCluster(cluster)).isEqualTo(false);
// Should render as cluster with 2 or more items
assertThat(clusterRenderer.shouldRenderAsCluster(cluster)).isEqualTo(true);
}
示例10: onBeforeClusterRendered
import com.google.maps.android.clustering.Cluster; //导入依赖的package包/类
@Override
protected void onBeforeClusterRendered(Cluster<Person> cluster, MarkerOptions markerOptions) {
// Draw multiple people.
// Note: this method runs on the UI thread. Don't spend too much time in here (like in this example).
List<Drawable> profilePhotos = new ArrayList<Drawable>(Math.min(4, cluster.getSize()));
int width = mDimension;
int height = mDimension;
for (Person p : cluster.getItems()) {
// Draw 4 at most.
if (profilePhotos.size() == 4) break;
Drawable drawable = getResources().getDrawable(p.profilePhoto);
drawable.setBounds(0, 0, width, height);
profilePhotos.add(drawable);
}
MultiDrawable multiDrawable = new MultiDrawable(profilePhotos);
multiDrawable.setBounds(0, 0, width, height);
mClusterImageView.setImageDrawable(multiDrawable);
Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
}
示例11: onClusterClick
import com.google.maps.android.clustering.Cluster; //导入依赖的package包/类
@Override
public boolean onClusterClick(Cluster<Person> cluster) {
// Show a toast with some info when the cluster is clicked.
String firstName = cluster.getItems().iterator().next().name;
Toast.makeText(this, cluster.getSize() + " (including " + firstName + ")", Toast.LENGTH_SHORT).show();
// Zoom in the cluster. Need to create LatLngBounds and including all the cluster items
// inside of bounds, then animate to center of the bounds.
// Create the builder to collect all essential cluster items for the bounds.
LatLngBounds.Builder builder = LatLngBounds.builder();
for (ClusterItem item : cluster.getItems()) {
builder.include(item.getPosition());
}
// Get the LatLngBounds
final LatLngBounds bounds = builder.build();
// Animate camera to the bounds
try {
getMap().animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
示例12: onClusterClick
import com.google.maps.android.clustering.Cluster; //导入依赖的package包/类
@Override
public boolean onClusterClick(Cluster<EntryMarker> entryMarkerCluster) {
Log.d("", "onClusterClick()");
ArrayList<Entry> entries = new ArrayList<>();
for ( EntryMarker marker : entryMarkerCluster.getItems())
entries.add(marker.entry);
mListDialog.setData(entries);
mListDialog.show(getFragmentManager(), "EntryListDialogFragment");
return true;
}
示例13: getBucket
import com.google.maps.android.clustering.Cluster; //导入依赖的package包/类
/**
* Gets the "bucket" for a particular cluster. By default, uses the number of points within the
* cluster, bucketed to some set points.
*/
protected int getBucket(Cluster<T> cluster) {
int size = cluster.getSize();
if (size <= BUCKETS[0]) {
return size;
}
for (int i = 0; i < BUCKETS.length - 1; i++) {
if (size < BUCKETS[i + 1]) {
return BUCKETS[i];
}
}
return BUCKETS[BUCKETS.length - 1];
}
示例14: queue
import com.google.maps.android.clustering.Cluster; //导入依赖的package包/类
public void queue(Set<? extends Cluster<T>> clusters) {
synchronized (this) {
// Overwrite any pending cluster tasks - we don't care about intermediate states.
mNextClusters = new RenderTask(clusters);
}
sendEmptyMessage(RUN_TASK);
}
示例15: removeMarker
import com.google.maps.android.clustering.Cluster; //导入依赖的package包/类
private void removeMarker(Marker m) {
Cluster<T> cluster = mMarkerToCluster.get(m);
mClusterToMarker.remove(cluster);
mMarkerCache.remove(m);
mMarkerToCluster.remove(m);
mClusterManager.getMarkerManager().remove(m);
}