TimelineHighlightRange.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*global define*/
  2. define([
  3. '../../Core/defaultValue',
  4. '../../Core/JulianDate'
  5. ], function(
  6. defaultValue,
  7. JulianDate) {
  8. "use strict";
  9. /**
  10. * @private
  11. */
  12. function TimelineHighlightRange(color, heightInPx, base) {
  13. this._color = color;
  14. this._height = heightInPx;
  15. this._base = defaultValue(base, 0);
  16. }
  17. TimelineHighlightRange.prototype.getHeight = function() {
  18. return this._height;
  19. };
  20. TimelineHighlightRange.prototype.getBase = function() {
  21. return this._base;
  22. };
  23. TimelineHighlightRange.prototype.getStartTime = function() {
  24. return this._start;
  25. };
  26. TimelineHighlightRange.prototype.getStopTime = function() {
  27. return this._stop;
  28. };
  29. TimelineHighlightRange.prototype.setRange = function(start, stop) {
  30. this._start = start;
  31. this._stop = stop;
  32. };
  33. TimelineHighlightRange.prototype.render = function(renderState) {
  34. var range = '';
  35. if (this._start && this._stop && this._color) {
  36. var highlightStart = JulianDate.secondsDifference(this._start, renderState.epochJulian);
  37. var highlightLeft = Math.round(renderState.timeBarWidth * renderState.getAlpha(highlightStart));
  38. var highlightStop = JulianDate.secondsDifference(this._stop, renderState.epochJulian);
  39. var highlightWidth = Math.round(renderState.timeBarWidth * renderState.getAlpha(highlightStop)) - highlightLeft;
  40. if (highlightLeft < 0) {
  41. highlightWidth += highlightLeft;
  42. highlightLeft = 0;
  43. }
  44. if ((highlightLeft + highlightWidth) > renderState.timeBarWidth) {
  45. highlightWidth = renderState.timeBarWidth - highlightLeft;
  46. }
  47. if (highlightWidth > 0) {
  48. range = '<span class="cesium-timeline-highlight" style="left: ' + highlightLeft.toString() +
  49. 'px; width: ' + highlightWidth.toString() + 'px; bottom: ' + this._base.toString() +
  50. 'px; height: ' + this._height + 'px; background-color: ' + this._color + ';"></span>';
  51. }
  52. }
  53. return range;
  54. };
  55. return TimelineHighlightRange;
  56. });