简体   繁体   English

带有毕加索的Google Maps Cluster项目标记图标

[英]Google Maps Cluster Item Marker Icon with Picasso

I'm using Google Map SDK 7.3.0 with android-maps-utils 0.3.4 because I need clusters for my Markers on the map. 我将Google Map SDK 7.3.0与android-maps-utils 0.3.4结合使用,因为我需要在地图上为我的标记创建集群。

我的地图

Ok, so here the problem is, I shouldn't have a red marker. 好的,所以这里的问题是,我不应该使用红色标记。 Only green+blue markers. 仅绿色+蓝色标记。 I subclassed DefaultClusterRenderer to create my custom marker view but sometimes it just doesn't work. 我将DefaultClusterRenderer子类化以创建我的自定义标记视图,但是有时它不起作用。

I'm using picasso to get the green icon because it's coming from an API. 我正在使用Picasso来获取绿色图标,因为它来自API。 But the problem is, when picasso has loaded the bitmap it's too late, the icon has already been set to the default one (red). 但是问题是,当毕加索加载位图时,为时已晚,该图标已经设置为默认图标(红色)。

Here's my onBeforeClusterItemRenderer : 这是我的onBeforeClusterItemRenderer:

            Picasso.with(getApplicationContext()).load(item.url).into(new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                FrameLayout icon = (FrameLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.marker, null);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    icon.findViewById(R.id.bg).setBackground(new BitmapDrawable(getResources(), bitmap));
                } else {
                    icon.findViewById(R.id.bg).setBackgroundDrawable(new BitmapDrawable(getResources(), bitmap));
                }


                Bitmap b = createDrawableFromView(Home.this, icon);

                if (marker != null) {
                    marker.icon(BitmapDescriptorFactory.fromBitmap(b));
                }
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {

            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {

            }
        });

--- EDITED --- -编辑-

When downloading the image inside onBeforeClusterItemRendered you are actually downloading the image every time the Cluster Manager tries to load a marker, so if you have, for example, 100 markers you will download the image 100 times. onBeforeClusterItemRendered内部下载映像时,实际上,每次Cluster Manager尝试加载标记时,实际上就是在下载映像,因此,例如,如果有100个标记,则将下载映像100次。

You should download the image inside onCreate , save it in a static variable, call mClusterManager.cluster(); 您应该在onCreate下载图像,将其保存在静态变量中,调用mClusterManager.cluster(); after saving the image, and finally inside onBeforeClusterItemRendered wrtie marker.icon(BitmapDescriptorFactory.fromBitmap(YourActivity.b)); 保存图像后,最后将其放在onBeforeClusterItemRendered wrtie marker.icon(BitmapDescriptorFactory.fromBitmap(YourActivity.b));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM