android-maps-utils icon indicating copy to clipboard operation
android-maps-utils copied to clipboard

Sometimes marker icon automatically changed while zooming in or zooming out

Open Kaushik1502 opened this issue 9 years ago • 2 comments

I am loading markers' icon using Glide while I zoom in or zoom out in map sometimes those icons are changed automatically. Here is code snippet below

@Override
        protected void onBeforeClusterItemRendered(final Person person, MarkerOptions markerOptions) {
            // Draw a single person.
            // Set the info window to show their name.
            if (!TextUtils.isEmpty(person.profilePhoto)) {
                Glide
                        .with(CustomMarkerClusteringDemoActivity.this)
                        .load(person.profilePhoto)
                        .fitCenter()
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .into(new SimpleTarget<GlideDrawable>() {
                            @Override
                            public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                                mImageView.setImageDrawable(resource);
                                Bitmap icon = mIconGenerator.makeIcon();
                                Marker markerToChange = null;
                                for (Marker marker : mClusterManager.getMarkerCollection().getMarkers()) {
                                    if (marker.getPosition().equals(person.getPosition())) {
                                        markerToChange = marker;
                                    }
                                }
                                // if found - change icon
                                if (markerToChange != null) {
                                    markerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon));
                                }
                            }
                        });
                Bitmap icon = mIconGenerator.makeIcon();
                markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
            } else {
                Glide
                        .with(CustomMarkerClusteringDemoActivity.this)
                        .load(R.mipmap.ic_launcher)
                        .fitCenter()
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .into(new SimpleTarget<GlideDrawable>() {
                            @Override
                            public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                                mImageView.setImageDrawable(resource);
                                Bitmap icon = mIconGenerator.makeIcon();
                                Marker markerToChange = null;
                                for (Marker marker : mClusterManager.getMarkerCollection().getMarkers()) {
                                    if (marker.getPosition().equals(person.getPosition())) {
                                        markerToChange = marker;
                                    }
                                }
                                // if found - change icon
                                if (markerToChange != null) {
                                    markerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon));
                                }
                            }
                        });
                Bitmap icon = mIconGenerator.makeIcon();
                markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
            }

        }

        @Override
        protected void onBeforeClusterRendered(final Cluster<Person> cluster,final 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).
            final List<Drawable> profilePhotos = new ArrayList<Drawable>(Math.min(4, cluster.getSize()));
            final int width = mDimension;
            final int height = mDimension;

            int i = 0;

            for (final Person p : cluster.getItems()) {
                // Draw 4 at most.
                i++;
                Glide
                        .with(CustomMarkerClusteringDemoActivity.this)
                        .load(p.profilePhoto)
                        .fitCenter()
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .into(new SimpleTarget<GlideDrawable>() {
                            @Override
                            public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                                resource.setBounds(0, 0, width, height);
                                profilePhotos.add(resource);
                                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));
                            }
                        });

                if (i == 4) break;
            }
            mIconGenerator.setBackground(null);
            Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
            markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
        }

        @Override
        protected boolean shouldRenderAsCluster(Cluster cluster) {
            // Always render clusters.
            return cluster.getSize() > 1;
        }

        @Override
        protected void onClusterRendered(final Cluster<Person> cluster,final Marker marker) {
            super.onClusterRendered(cluster, marker);
            // Draw multiple people.
            // Note: this method runs on the UI thread. Don't spend too much time in here (like in this example).
            final List<Drawable> profilePhotos = new ArrayList<Drawable>(Math.min(4, cluster.getSize()));
            final int width = mDimension;
            final int height = mDimension;

            int i = 0;

            for (final Person p : cluster.getItems()) {
                // Draw 4 at most.
                i++;
                Glide
                        .with(CustomMarkerClusteringDemoActivity.this)
                        .load(p.profilePhoto)
                        .fitCenter()
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .into(new SimpleTarget<GlideDrawable>() {
                            @Override
                            public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                                resource.setBounds(0, 0, width, height);
                                profilePhotos.add(resource);
                                MultiDrawable multiDrawable = new MultiDrawable(profilePhotos);
                                multiDrawable.setBounds(0, 0, width, height);

                                mClusterImageView.setImageDrawable(multiDrawable);
                                Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
                                marker.setIcon(BitmapDescriptorFactory.fromBitmap(icon));
                            }
                        });

                if (i == 4) break;
            }
            /*Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
            marker.setIcon(BitmapDescriptorFactory.fromBitmap(icon));*/
        }

        @Override
        protected void onClusterItemRendered(final Person person, Marker marker) {
            super.onClusterItemRendered(person, marker);
            // Draw a single person.
            // Set the info window to show their name.
            if (!TextUtils.isEmpty(person.profilePhoto)) {
                Glide
                        .with(CustomMarkerClusteringDemoActivity.this)
                        .load(person.profilePhoto)
                        .fitCenter()
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .into(new SimpleTarget<GlideDrawable>() {
                            @Override
                            public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                                mImageView.setImageDrawable(resource);
                                Bitmap icon = mIconGenerator.makeIcon();
                                Marker markerToChange = null;
                                for (Marker marker : mClusterManager.getMarkerCollection().getMarkers()) {
                                    if (marker.getPosition().equals(person.getPosition())) {
                                        markerToChange = marker;
                                    }
                                }
                                // if found - change icon
                                if (markerToChange != null) {
                                    markerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon));
                                }
                            }
                        });
                Bitmap icon = mIconGenerator.makeIcon();
                marker.setIcon(BitmapDescriptorFactory.fromBitmap(icon));
            } else {
                Glide
                        .with(CustomMarkerClusteringDemoActivity.this)
                        .load(R.mipmap.ic_launcher)
                        .fitCenter()
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .into(new SimpleTarget<GlideDrawable>() {
                            @Override
                            public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                                mImageView.setImageDrawable(resource);
                                Bitmap icon = mIconGenerator.makeIcon();
                                Marker markerToChange = null;
                                for (Marker marker : mClusterManager.getMarkerCollection().getMarkers()) {
                                    if (marker.getPosition().equals(person.getPosition())) {
                                        markerToChange = marker;
                                    }
                                }
                                // if found - change icon
                                if (markerToChange != null) {
                                    markerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon));
                                }
                            }
                        });
                Bitmap icon = mIconGenerator.makeIcon();
                marker.setIcon(BitmapDescriptorFactory.fromBitmap(icon));
            }
        }

Any help will be highly appriciated

Kaushik1502 avatar Dec 15 '16 07:12 Kaushik1502

This issue has been automatically marked as stale because it has not had recent activity. Please comment here if it is still valid so that we can reprioritize. Thank you!

stale[bot] avatar Oct 03 '19 13:10 stale[bot]

Closing this. Please reopen if you believe it should be addressed. Thank you for your contribution.

stale[bot] avatar Nov 02 '19 13:11 stale[bot]