Getting Google Map MarkerClusterer Plus Icons In One Color

前端 未结 2 938
渐次进展
渐次进展 2020-12-19 00:10

Can some one please let me know how to set MarkerClusterer plus to show all Clusters in One color? as you can see the MarkerClusterer automatically changes the color of the

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-19 01:06

    I had similar problem. Solution: develop a function with color parameter which generates inline svg icon. It's not so difficult to reverse engineer it with basic shapes:

     var getGoogleClusterInlineSvg = function (color) {
            var encoded = window.btoa('');
    
            return ('data:image/svg+xml;base64,' + encoded);
        };
    
    var cluster_styles = [
            {
                width: 40,
                height: 40,
                url: getGoogleClusterInlineSvg('blue'),
                textColor: 'white',
                textSize: 12
            },
            {
                width: 50,
                height: 50,
                url: getGoogleClusterInlineSvg('violet'),
                textColor: 'white',
                textSize: 14
            },
            {
                width: 60,
                height: 60,
                url: getGoogleClusterInlineSvg('yellow'),
                textColor: 'white',
                textSize: 16
            }
            //up to 5
        ];
    
    //...
    
     markerClusterer = new MarkerClusterer(map, markers, {
                //...
                styles: cluster_styles
            });
    

    SVG source:

    
        
            
                
                
                
            
        
        
            
            
                
            
            
                
            
            
                
            
        
    

提交回复
热议问题