Source: formats/kml/KmlTimePrimitive.js

  1. /*
  2. * Copyright 2003-2006, 2009, 2017, 2020 United States Government, as represented
  3. * by the Administrator of the National Aeronautics and Space Administration.
  4. * All rights reserved.
  5. *
  6. * The NASAWorldWind/WebWorldWind platform is licensed under the Apache License,
  7. * Version 2.0 (the "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License
  9. * at http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. *
  16. * NASAWorldWind/WebWorldWind also contains the following 3rd party Open Source
  17. * software:
  18. *
  19. * ES6-Promise – under MIT License
  20. * libtess.js – SGI Free Software License B
  21. * Proj4 – under MIT License
  22. * JSZip – under MIT License
  23. *
  24. * A complete listing of 3rd Party software notices and licenses included in
  25. * WebWorldWind can be found in the WebWorldWind 3rd-party notices and licenses
  26. * PDF found in code directory.
  27. */
  28. /**
  29. * @exports KmlTimePrimitive
  30. */
  31. define([
  32. './KmlObject'
  33. ], function (KmlObject) {
  34. "use strict";
  35. /**
  36. * Constructs an KmlTimePrimitive. Applications usually don't call this constructor. It is called by {@link KmlFile}
  37. * as objects from KmlFile are read.
  38. * @alias KmlTimePrimitive
  39. * @classdesc It is ancestor for all TimePrimitives - TimeSpan and TimeStamp
  40. * @param options {Object}
  41. * @param options.objectNode {Node} Node representing Kml TimePrimitive.
  42. * @constructor
  43. * @see https://developers.google.com/kml/documentation/kmlreference#timeprimitive
  44. * @augments KmlObject
  45. */
  46. var KmlTimePrimitive = function (options) {
  47. KmlObject.call(this, options);
  48. };
  49. KmlTimePrimitive.prototype = Object.create(KmlObject.prototype);
  50. /**
  51. * It returns range applicable to current time.
  52. * @returns {{from: Date, to: Date}}
  53. */
  54. KmlTimePrimitive.prototype.timeRange = function() {
  55. var from, to;
  56. if(this.kmlBegin) {
  57. to = from = this.kmlBegin.valueOf();
  58. }
  59. if(this.kmlEnd) {
  60. to = this.kmlEnd.valueOf();
  61. if(!from) {
  62. from = to;
  63. }
  64. }
  65. if(this.kmlWhen) {
  66. to = from = this.kmlWhen.valueOf();
  67. }
  68. return {
  69. from: from,
  70. to: to
  71. };
  72. };
  73. /**
  74. * @inheritDoc
  75. */
  76. KmlTimePrimitive.prototype.getTagNames = function () {
  77. return ['TimeSpan', 'TimeStamp'];
  78. };
  79. return KmlTimePrimitive;
  80. });