how can i change cluster icon? i wolud like to have same icon, with some other color than blue.
Asked
Active
Viewed 6.1k times
35

Amro
- 123,847
- 25
- 243
- 454

user198003
- 11,029
- 28
- 94
- 152
-
These icons are not on Googles servers anymore. – Kaippally May 12 '16 at 10:34
-
they change repo to git hub here is the icone https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images – jayesh May 12 '16 at 12:00
-
1@Kaippally I've covered a solution to this in the following SO post [what is the alternate source path for google markerclusterer.js library?](http://stackoverflow.com/a/37183674/1301937) – Chris Cook May 12 '16 at 20:28
5 Answers
65
You need to use styles parameter when initializing MarkerClusterer object - the code below shows default styles so if you want to recolour one of the icons just change the relevant url to your image...
//set style options for marker clusters (these are the default styles)
mcOptions = {styles: [{
height: 53,
url: "http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/images/m1.png",
width: 53
},
{
height: 56,
url: "https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images/m2.png",
width: 56
},
{
height: 66,
url: "https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images/m3.png",
width: 66
},
{
height: 78,
url: "https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images/m4.png",
width: 78
},
{
height: 90,
url: "https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images/m5.png",
width: 90
}]}
//init clusterer with your options
var mc = new MarkerClusterer(map, markers, mcOptions);

Michal
- 13,439
- 3
- 35
- 33
-
Looks like there are comma's missing in the property list for each individual marker... from FireFox `Error: missing } after property list`. – Unpossible Sep 14 '11 at 02:08
-
1
-
New image url is "https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images/" – Michal Sep 25 '18 at 04:46
-
You can also use "anchor" for text position, "textColor" for text color and "textSize" for size. Example: anchor: [3, 0], textColor: '#ff00ff', textSize: 10 – Michael Schober Sep 01 '19 at 20:22
11
Google changed his repo. Latest cluster repo is: https://github.com/googlemaps/js-marker-clusterer images : https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images
You may also consider downloading source and give link from your local path. This way you will have more control of resources your application needs.
local_path "/pucblic/"
mcOptions = {styles: [{
height: 53,
url: local_path+"m1.png",
width: 53
},
{
height: 56,
url: local_path+"m2.png",
width: 56
},
{
height: 66,
url: local_path+"m3.png",
width: 66
},
{
height: 78,
url: local_path+"m4.png",
width: 78
},
{
height: 90,
url: local_path+"m5.png",
width: 90
}]}
3
A shortcut is overriding the image path like this:
MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_PATH_ =
"https://raw.githubusercontent.com/googlemaps/v3-utility-library/master/markerclustererplus/images/m";

hoju
- 28,392
- 37
- 134
- 178
-
1Above image path not correct https://raw.githubusercontent.com/googlemaps/v3-utility-library/master/markerclustererplus/images/m1.png – Shiv Kumar Sah May 29 '16 at 03:49
-
Awesome solution, just use a local path instead of the raw github content url. – phaberest Nov 17 '16 at 14:38
3
Here are the original photos
markerClusterOptions = {styles: [{
height: 53,
url: "https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m1.png",
width: 53
},
{
height: 56,
url: "https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m2.png",
width: 56
},
{
height: 66,
url: "https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m3.png",
width: 66
},
{
height: 78,
url: "https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m4.png",
width: 78
},
{
height: 90,
url: "https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m5.png,
width: 90
}]}
markerCluster = new MarkerClusterer(map, markers,markerClusterOptions);

Sandeep Sherpur
- 2,418
- 25
- 27
0
Here is the code, to create the custom icons for cluster
const algorithm = new SuperClusterAlgorithm({
maxZoom: this.maxZoom,
radius: 150,
minZoom: 0,
zoomOnClick:false
});
const renderer = {
render: function ({ count, position }) {
return new google.maps.Marker({
label: {text: count.toString(), color: 'white', fontSize: '12px'},
position,
icon: 'icon1.png',
title: 'Zoom in to view resources in this area',
// adjust zIndex to be above other markers
zIndex: Number(google.maps.Marker.MAX_ZINDEX) + count,
});
}
};
this.markerCluster = new MarkerClusterer({
map: this.map,
markers: this.markers,
algorithm: algorithm,
renderer:renderer
});

Umer Siddiq
- 1
- 1