ColorStyle.js 900 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {Style} from "./Style";
  2. /**
  3. * Simple solid color style represented and stored as a CSS color.
  4. *
  5. * Example value formats supported "rgb(0, 153, 255)" or "rgba(0, 153, 255, 0.3)" or "#0099ff" or "#0099ffaa" or "red".
  6. *
  7. * @class
  8. * @extends {Style}
  9. * @param {string} color Color of the style, if undefined it is set to black.
  10. */
  11. function ColorStyle(color)
  12. {
  13. Style.call(this);
  14. /**
  15. * Color of this style object.
  16. *
  17. * @type {string}
  18. */
  19. this.color = color || "#000000";
  20. }
  21. ColorStyle.prototype = Object.create(Style.prototype);
  22. Style.register(ColorStyle, "Color");
  23. ColorStyle.prototype.get = function(context)
  24. {
  25. return this.color;
  26. };
  27. ColorStyle.prototype.serialize = function()
  28. {
  29. return {
  30. type: "Color",
  31. color: this.color
  32. };
  33. };
  34. ColorStyle.prototype.parse = function(data)
  35. {
  36. this.color = data.color;
  37. };
  38. export {ColorStyle};