TimelineHighlightRange.js 2.1 KB

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