0
votes

I am trying to dynamically change the color of the maps marker on a google apps script project. The following code is in a loop that adds all the points in my google sheet to the map based on their coordinates, I am retrieving the color from that sheet If I set my color manually the script works fine

     for (var row = 0; row < (endRow-1); row++) {
     map.setMarkerStyle(Maps.StaticMap.MarkerSize.TINY, Maps.StaticMap.Color.BLUE, 'T');
     map.addMarker(reportData[row][5], reportData[row][6]);

however when I use a variable which has been defined as the color

   //Removes the first portion of the color icon name used for Fusion Tables
   var rowColor = reportData[row][16].slice(6).toUpperCase();
   map.setMarkerStyle(Maps.StaticMap.MarkerSize.TINY, Maps.StaticMap.Color.rowColor, 'T');
   map.addMarker(reportData[row][5], reportData[row][6]);

I get a "Invalid argument: color (line 230, file "Daily Report")" error and it shows the color variable as undefined in the execution transcript when run.

What did i do wrong? I'm new to google apps script and programming in general so I'm fairly certain I'm doing something wrong with the way i'm trying to reference my color variable when setting the color for Maps.

1

1 Answers

0
votes

When typed like that the Enum is looking for a property called "rowColor" for Maps.StaticMap.Color which doesn't exist

If you want to determine color based on the spreadsheet, use rgb values as a string in the format "0xrrggbb"

var hexColor = "0x000000" 
var rowColor = reportData[row][16].slice(6).toUpperCase();
if (rowColor == 'BLUE'){
   var hexColor = "0x0000FF"
}
map.setMarkerStyle(Maps.StaticMap.MarkerSize.TINY, hexColor, 'T');