This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity : AppCompatActivity, IOnMapReadyCallback, ClusterManager.IOnClusterItemInfoWindowClickListener, | |
GoogleMap.IOnCameraIdleListener, GoogleMap.IInfoWindowAdapter, GoogleMap.IOnInfoWindowClickListener | |
{ | |
private ClusterManager m_ClusterManagerFav; | |
private ClusterRenderer m_ClusterRendererFav; | |
private CustomGoogleMapInfoWindow m_InfoWindowAdapter; | |
//... | |
public void OnMapReady(GoogleMap map) | |
{ | |
//Initialize Map | |
m_map = map; | |
m_map.SetOnCameraIdleListener(this); | |
m_map.SetInfoWindowAdapter(this); | |
m_map.SetOnInfoWindowClickListener(this); | |
//Initialize info window adapter | |
m_InfoWindowAdapter = new CustomGoogleMapInfoWindow(this, m_dicAllMarkerOnMap); | |
//Initialize Cluster manager | |
ConfigCluster(); | |
//Initialize Cluster manager for favorites markers | |
ConfigClusterFav(); | |
SetupMap(); | |
} | |
private void ConfigCluster() | |
{ | |
//Initialize cluster manager. | |
m_ClusterManager = new ClusterManager(this, m_map); | |
//Initialize cluster renderer, and keep a reference that will be usefull for the InfoWindowsAdapter | |
m_ClusterRenderer = new ClusterRenderer(this, m_map, m_ClusterManager, m_dicAllMarkerOnMap); | |
m_ClusterManager.Renderer = m_ClusterRenderer; | |
//Custom info window : single markers only (a click on a cluster marker should not show info window) | |
m_ClusterManager.MarkerCollection.SetOnInfoWindowAdapter(m_InfoWindowAdapter); | |
//Handle Info Window's click event | |
m_ClusterManager.SetOnClusterItemInfoWindowClickListener(this); | |
} | |
private void ConfigClusterFav() | |
{ | |
//Initialize cluster manager for favorites markers. | |
m_ClusterManagerFav = new ClusterManager(this, m_map); | |
//Initialize cluster renderer, and keep a reference that will be usefull for the InfoWindowsAdapter | |
m_ClusterRendererFav = new ClusterRenderer(this, m_map, m_ClusterManagerFav, m_dicAllMarkerOnMap); | |
m_ClusterManagerFav.Renderer = m_ClusterRendererFav; | |
//Custom info window : single markers only (a click on a cluster marker should not show info window) | |
m_ClusterManagerFav.MarkerCollection.SetOnInfoWindowAdapter(m_InfoWindowAdapter); | |
//Handle Info Window's click event | |
m_ClusterManagerFav.SetOnClusterItemInfoWindowClickListener(this); | |
} | |
public void OnClusterItemInfoWindowClick(Java.Lang.Object p0) | |
{ | |
//... | |
//Dismiss the info window clicked | |
Marker markerClicked = m_ClusterRenderer.GetMarker(itemClicked); | |
if (markerClicked == null) | |
markerClicked = m_ClusterRendererFav.GetMarker(itemClicked); | |
markerClicked.HideInfoWindow(); | |
} | |
public void OnCameraIdle() | |
{ | |
m_ClusterManager.OnCameraIdle(); | |
m_ClusterManagerFav.OnCameraIdle(); | |
} | |
public View GetInfoContents(Marker marker) | |
{ | |
View v = m_ClusterManager.MarkerManager.GetInfoContents(marker); | |
if (v == null) | |
v = m_ClusterManagerFav.MarkerManager.GetInfoContents(marker); | |
return v; | |
} | |
public View GetInfoWindow(Marker marker) | |
{ | |
View v = m_ClusterManager.MarkerManager.GetInfoWindow(marker); | |
if (v == null) | |
v = m_ClusterManagerFav.MarkerManager.GetInfoWindow(marker); | |
return v; | |
} | |
public void OnInfoWindowClick(Marker marker) | |
{ | |
m_ClusterManager.OnInfoWindowClick(marker); | |
m_ClusterManagerFav.OnInfoWindowClick(marker); | |
} | |
private void SetupMap() | |
{ | |
//... | |
LatLng LatLonMeylan = new LatLng(45.2333, 5.7833); | |
lsMarkers = new List<ClusterItem>(); | |
//Add 50 markers using a spiral algorithm (cheers SushiHangover) | |
for (int i = 0; i < 50; ++i) | |
{ | |
double theta = i * System.Math.PI * 0.29f; | |
double radius = 0.004 * System.Math.Exp(0.2 * theta); | |
double x = radius * System.Math.Cos(theta); | |
double y = radius * System.Math.Sin(theta); | |
ClusterItem newMarker = new ClusterItem(LatLonMeylan.Latitude + x, LatLonMeylan.Longitude + y, "radius = " + radius); | |
newMarker.m_bIsFav = true; | |
lsMarkers.Add(newMarker); | |
} | |
//Add markers to the map through the cluster manager | |
m_ClusterManagerFav.AddItems(lsMarkers); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment