Skip to content

Instantly share code, notes, and snippets.

@nerik
Last active August 4, 2017 08:53
Show Gist options
  • Save nerik/9a31d02077c8fd1ed444f7d15f916a87 to your computer and use it in GitHub Desktop.
Save nerik/9a31d02077c8fd1ed444f7d15f916a87 to your computer and use it in GitHub Desktop.
// ES6 allows multiline strings with backticks, and it is natively available on all browsers except IE
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
// just changing the docs to promote using ES6 by default (with an ES5 fallback) would already help a great deal
var countriesStyle = new carto.style.CartoCSS(`
#layer {
polygon-fill: #333333;
}
`);
// baked in simple object literal to multiline string conversion shouldn't be to hard to implement
var countriesStyle = new carto.style.CartoCSS({
'#layer': {
'polygon-fill': '#333333'
}
});
// and this would also allows for interesting scenarios with dynamically generated CartoCSS
// (again using an ES6 feature, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer)
var layerName = '#layer';
var num = 42;
var countriesStyle = new carto.style.CartoCSS({
[layerName]: {
'polygon-fill': '#333333'
}
[`someLayer${num}`]: {
'polygon-fill': '#333333'
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment