Android maps utils cluster icon color

前端 未结 6 1640
谎友^
谎友^ 2020-12-13 07:23

Is there any method to change the background color of the cluster item? (the one that displays the count of the markers, like 100+, 200+ ...). I tried to look into the sourc

6条回答
  •  再見小時候
    2020-12-13 07:50

    Go to DefaultClusterRenderer (package com.google.maps.android.clustering.view;), and change the getColor() method to this:

    private int getColor(int clusterSize) {
            // custom color
            double _logClusterSize; // log
            final int _maxRed = Integer.parseInt("ff", 16);
    //        Log.v("kai", String.valueOf(_maxRed));
            final int _minRed = Integer.parseInt("e6", 16);
            final int _maxGreen = Integer.parseInt("a2", 16);
            final int _minGreen = Integer.parseInt("47", 16);
            final int _maxBlue = Integer.parseInt("93", 16);
            final int _minBlue = Integer.parseInt("2d", 16);
            final double _maxLogClusterSize = 10;
            double _step = (_maxRed - _minRed) / _maxLogClusterSize;
    
            _logClusterSize = Math.log(clusterSize);
            if(_logClusterSize > 10) _logClusterSize = 10;
    
            int _red = _maxRed - (int) (_step * _logClusterSize);
            int _green = _maxGreen - (int) (_step * _logClusterSize);
            int _blue = _maxBlue - (int) (_step * _logClusterSize);
    
            return Color.rgb(_red, _green, _blue);
    
    //        final float hueRange = 220;
    //        final float sizeRange = 300;
    //        final float size = Math.min(clusterSize, sizeRange);
    //        final float hue = (sizeRange - size) * (sizeRange - size) / (sizeRange * sizeRange) * hueRange;
    //        return Color.HSVToColor(new float[]{
    //                hue, 1f, .6f
    //        });
        }
    

    This will change the Cluster color to pink, in the range of the color defined by min(max) red(green, blue). Hope that help!

提交回复
热议问题