Reputation: 1309
Apologies for the rather simple question.... I'm fairly new to both coffeescript and Google Maps API.
I'm trying to replicate the circle symbol for a Marker in this example using coffeescript, but I'm struggling with the syntax on the icon
statement.
Can anyone show me how to do write the following code in coffeescript, specifically the icon part?
var marker = new google.maps.Marker({
position: map.getCenter(),
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale: 10
}
})
Upvotes: 1
Views: 99
Reputation: 434585
You could just drop the var
and be done with it:
marker = new google.maps.Marker({
position: map.getCenter(),
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale: 10
}
})
Function-calling parentheses and object braces are often optional in CoffeeScript but you can still include them if it makes the code clearer to you.
Or you could drop the optional commas, parentheses, and braces:
marker = new google.maps.Marker
position: map.getCenter()
icon:
path: google.maps.SymbolPath.CIRCLE
scale: 10
Note that the parentheses on the map.getCenter
call are not optional since that function is called without any arguments.
Or you could say:
marker = new google.maps.Marker(
position: map.getCenter()
icon:
path: google.maps.SymbolPath.CIRCLE
scale: 10
)
to make the nesting a little clearer. This is probably the one I'd use. If there was more nesting then I'd probably start adding braces to make the structure clearer or break it into pieces:
icon =
path: google.maps.SymbolPath.CIRCLE
scale: 10
marker = new google.maps.Marker(
position: map.getCenter()
icon: icon
)
Upvotes: 2