question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting marker cluster icon depending on markers inside it

See original GitHub issue

Issue description

I have to set marker cluster icon depending on markers inside it. If at least one object in cluster has value isOpened === true then we use icon1.png else we use icon2.png

Steps to reproduce and a minimal demo of the problem

<agm-marker-cluster [imagePath]="'assets/m'" [averageCenter]="true"
  [styles]="[{url: 'assets/m1.png', textColor: '#fff', textSize: '20', height: '50', width: '50'}, {url: 'assets/m2.png', textColor: '#fff', textSize: '20', height: '50', width: '50'}, {url: 'assets/m3.png', textColor: '#fff', textSize: '20', height: '50', width: '50'}, {url: 'assets/m4.png', textColor: '#fff', textSize: '20', height: '50', width: '50'}, {url: 'assets/m5.png', textColor: '#fff', textSize: '20', height: '50', width: '50'}]" >
    <agm-marker *ngFor="let place of places" [latitude]="place.location ? place.location.lat : ''"
      [longitude]="place.location ? place.location.lng : ''" [iconUrl]="place.icon">

Current behavior

I want to use function setCalculator() as supposed here https://stackoverflow.com/questions/27375173/markerclusterer-set-marker-cluster-icon-depending-on-markers-inside-it but can’t find a way to do this.

Expected/desired behavior

solution to solve the problem

angular2 & angular-google-maps version

@agm/core”: “^1.0.0-beta.0”, “@agm/js-marker-clusterer”: “^1.0.0-beta.1”, “@agm/snazzy-info-window”: “^1.0.0-beta.1”, “@angular/cli”: “^1.4.7”, “@angular/common”: “^4.4.5”, “@angular/compiler”: “^4.4.5”, “@angular/compiler-cli”: “^4.4.5”, “@angular/core”: “^4.4.5”,

Other information

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:8

github_iconTop GitHub Comments

6reactions
lmachado-eticommented, Mar 9, 2018

Based on the date of your question, I believe you have solve the issue.

If you solve, can you post the solution?

Anyway, some help:

  1. Declare an array of ClusterStyle
   clusterStyles: ClusterStyle[] =  [
       {
           textColor: "#FFFFFF",
           url: "assets/markers/marker_duascores_gb.png",
           height: 36,
           width: 58
       },
       {
           textColor: "#FFFFFF",
           url: "assets/markers/marker_duascores_rg.png",
           height: 36,
           width: 58
       }
   ];
  1. Use the directive. <agm-marker-cluster [styles]="clusterStyles">
0reactions
alextanasiecommented, Jul 4, 2022

Hello, you can use also this solution

<agm-marker-cluster [styles]=“mapOptions.styles” [calculator]=“mapOptions.calculator”>

mapOptions = {

	styles: [{
		height: 53,
		url: "assets/map-machine-icons/green.png",
		width: 52
	},
	{
		height: 53,
		url: "assets/map-machine-icons/red.png",
		width: 52
	}],
	calculator: (markers) => {
		for (let i = 0; i < markers.length; i++) {
			// you have access all the markers from each cluster
		}
		return { text: markers.length, index: 1 };

		// index: 1 -> for green icon
		// index: 2 -> for red icon
	}
};

Unfortunately in the calculator you do not have access to any data about the marker (like id, name etc - anything that you set on the marker object) except for title and metadata like position, draggable, position etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

set marker cluster icon depending on markers inside it
I've put together a map with clusters. The idea was that cluster's color should depend on the color of markers inside: if there...
Read more >
Setting marker cluster icon depending on markers inside it
Issue description I have to set marker cluster icon depending on markers inside it. If at least one object in cluster has value...
Read more >
Javascript – Markerclusterer set marker cluster icon ... - iTecNote
How can I make a cluster icon dependant on the markers inside it? For example: Parking A is green; Parking B is red;...
Read more >
Marker Clustering | Maps JavaScript API - Google Developers
This tutorial shows you how to use marker clusters to display a large number of markers on a map. You can use the...
Read more >
How to Create Marker Clusters on Google Maps - Medium
You can use marker clusters so that Google map automatically clusters the markers into groups based on the location of the marker.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found