Tell me please, why do markers load into clusters for a very long time? 500 markers - about 5 seconds, 1000 markers about 9 seconds. I tried a third-party library for the sake of interest, there 20,000 are instantly loaded .. Here is my code:
public class MyClusterItem implements ClusterItem { private final LatLng mPosition; private BitmapDescriptor mIcon; // ΠΈΠΊΠΎΠ½ΠΊΠ° private String mTitle; // ΠΈΠΌΡ ΠΌΠ°ΡΠΊΠ΅ΡΠ° Π² Title public MyClusterItem(double lat, double lng, BitmapDescriptor icon, String title) { mPosition = new LatLng(lat, lng); mIcon = icon; mTitle = title; } @Override public LatLng getPosition() { return mPosition; } public BitmapDescriptor getIcon() { return mIcon; } public String getTitle() { return mTitle; } } private void setUpClusterer() { // Initialize the manager with the context and the map. // (Activity extends context, so we can pass 'this' in the constructor.) mClusterManager = new ClusterManager<MyClusterItem>(mapsActivity, mapsActivity.mMap); // Point the map's listeners at the listeners implemented by the cluster manager. mapsActivity.mMap.setOnCameraIdleListener(mClusterManager); mapsActivity.mMap.setOnMarkerClickListener(mClusterManager); } private void addItems_Markers(String lat, String lng, String iconName, String markNameTitle) { int resourceId = mapsActivity.getResources().getIdentifier(iconName, "drawable", mapsActivity.getPackageName()); BitmapDescriptor markerDescriptor = BitmapDescriptorFactory.fromResource(resourceId); MyClusterItem offsetItem = new MyClusterItem(Double.parseDouble(lat), Double.parseDouble(lng), markerDescriptor, markNameTitle); mClusterManager.setRenderer(new MyClusterRenderer(mapsActivity, mapsActivity.mMap, mClusterManager)); mClusterManager.addItem(offsetItem); } public class MyClusterRenderer extends DefaultClusterRenderer<MyClusterItem> { private final IconGenerator mClusterIconGenerator = new IconGenerator(mapsActivity.getApplicationContext()); public MyClusterRenderer(Context context, GoogleMap map, ClusterManager<MyClusterItem> clusterManager) { super(context, map, clusterManager); } @Override protected void onBeforeClusterItemRendered(MyClusterItem item, MarkerOptions markerOptions) { markerOptions.icon(item.getIcon()); markerOptions.title(item.getTitle()); super.onBeforeClusterItemRendered(item, markerOptions); } @Override protected void onClusterItemRendered(MyClusterItem clusterItem, Marker marker) { super.onClusterItemRendered(clusterItem, marker); } @Override protected void onBeforeClusterRendered(Cluster<MyClusterItem> cluster, MarkerOptions markerOptions){ final Drawable clusterIcon = ContextCompat.getDrawable(mapsActivity, R.drawable.z_cl_1); mClusterIconGenerator.setBackground(clusterIcon); Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)); } }
And I load the loop from the loaded list, I take 4 parameters from there, the name of the drawable icon, the name of the marker and the coordinates Lat, Lng:
setUpClusterer(); // Π΄Π»Ρ ΡΠΎΠ·Π΄Π°Π½ΠΈΡ ΠΊΠ»Π°ΡΡΠ΅ΡΠ°
.....
for (int i = 0; i < myPoints.size(); i++) { String i_var_0 = myPoints.get(i)[0]; String i_var_1 = myPoints.get(i)[1]; String i_var_2 = myPoints.get(i)[2]; String i_var_3 = myPoints.get(i)[3]; addItems_Markers(i_var_2, i_var_3, i_var_0, i_var_1); } mClusterManager.cluster();
Here the whole problem in the class MyClusterRenderer - DefaultClusterRenderer, if you remove it, then with standard icons everything loads instantly .. But how to do with your icons, and so that the loading of your icons does not slow down the whole process?