android中集群组的自定义图标

时间:2017-04-24 05:36:56

标签: android google-maps marker markerclusterer

我想用我的drawable图标更改defult cluster group图标。 请检查我的代码以获取群集程序。

MyClusterRenderer.java

dis_
我的片段中的

代码用于设置cluser

var result = $('[class^=dis_]').filter(function () {
            return this.class.match(/dis_\d+$/); //regex for the pattern "rank_ followed by a number"
    });

3 个答案:

答案 0 :(得分:2)

尝试使用Else方法而不是onBeforeClusterRendered更改群集图标:

onBeforeClusterItemRendered

答案 1 :(得分:2)

    public  class MyClusterRenderer extends DefaultClusterRenderer<MyItem> {
        private final IconGenerator mClusterIconGenerator = new IconGenerator(
                getActivity());
        public MyClusterRenderer(Context context, GoogleMap map,
                                 ClusterManager<MyItem> clusterManager) {
            super(context, map, clusterManager);


            View multiProfile = getActivity().getLayoutInflater().inflate(
                    R.layout.cluster_custome_icon, null);
            mClusterIconGenerator.setContentView(multiProfile);
        }

        @Override
        protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {

         markerOptions.title("").icon(BitmapDescriptorFactory.fromResource(R.mipmap.location_both));

            super.onBeforeClusterItemRendered(item, markerOptions);
        }

//        @Override
//        protected void onClusterItemRendered(final MyItem clusterItem, Marker marker) {
//            super.onClusterItemRendered(clusterItem, marker);
//
//        }
        @Override
        protected void onBeforeClusterRendered(Cluster<MyItem> cluster,
                                               MarkerOptions markerOptions) {

            Log.e("get_item_list_nir", "CallMap onBeforeClusterRendered 13");
            try {
                mClusterIconGenerator.setBackground(null);
                Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster
                        .getSize()));
                markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
            } catch (Exception e) {
                e.printStackTrace();
                Log.e("get_item_list_nir", "error 13.1 : " + e.toString());
            }
            Log.e("get_item_list_nir", "CallMap onBeforeClusterRendered 14");
        }
    }

答案 2 :(得分:1)

最好的方法是

         private val clusterIconGenerator = IconGenerator(context)

         override fun getDescriptorForCluster(cluster: Cluster<PromotionMarker>): BitmapDescriptor {
            clusterIconGenerator.setBackground(ContextCompat.getDrawable(context, R.drawable.background_marker))
            val icon: Bitmap = clusterIconGenerator.makeIcon(cluster.size.toString())
            return BitmapDescriptorFactory.fromBitmap(icon)
         }