Skip to content

Instantly share code, notes, and snippets.

@icholy
Last active December 18, 2015 03:08
Show Gist options
  • Save icholy/5715833 to your computer and use it in GitHub Desktop.
Save icholy/5715833 to your computer and use it in GitHub Desktop.
better google earth style api.
var applyStyle = (function () {
var type_handlers = {
line: function (s) { return s.getLineStyle(); },
icon: function (s) { return s.getIconStyle(); },
poly: function (s) { return s.getPolyStyle(); },
list: function (s) { return s.getListStyle(); },
balloon: function (s) { return s.getBalloonStyle(); },
label: function (s) { return s.getLabelStyle(); }
};
var property_handlers = {
href: function (p, s, v) { s.getIcon().setHref(v); },
scale: function (p, s, v) { s.setScale(v); },
heading: function (p, s, v) { s.setHeading(v); },
width: function (p, s, v) { s.setWidth(v); },
color: function (p, s, v) { s.getColor().set(v); }
};
return function (p, style, styles) {
var apply = function (s, props) {
Object.keys(props).forEach(function (k) {
property_handlers[k](p, s, props[k]);
});
};
Object.keys(styles).forEach(function (type) {
apply(type_handlers[type](style), styles[type]);
});
};
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment