Source: formats/kml/KmlLookAt.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. define([
  29. './KmlAbstractView',
  30. './KmlElements',
  31. './util/KmlNodeTransformers',
  32. '../../geom/Position'
  33. ], function (KmlAbstractView,
  34. KmlElements,
  35. NodeTransformers,
  36. Position
  37. ) {
  38. "use strict";
  39. /**
  40. * Constructs an KmlLookAt. Applications usually don't call this constructor. It is called by {@link KmlFile} as
  41. * objects from Kml file are read. This object is already concrete implementation.
  42. * @alias KmlLookAt
  43. * @classdesc Contains the data associated with LookAt node.
  44. * @param options {Object}
  45. * @param options.objectNode {Node} Node representing looking at something in the document.
  46. * @constructor
  47. * @throws {ArgumentError} If the node is null or undefined.
  48. * @see https://developers.google.com/kml/documentation/kmlreference#lookat
  49. * @augments KmlAbstractView
  50. */
  51. var KmlLookAt = function (options) {
  52. KmlAbstractView.call(this, options);
  53. };
  54. KmlLookAt.prototype = Object.create(KmlAbstractView.prototype);
  55. Object.defineProperties(KmlLookAt.prototype, {
  56. /**
  57. * Longitude of the point the camera is looking at. Angular distance in degrees, relative to the Prime
  58. * Meridian. Values west of the Meridian range from -180 to 0 degrees. Values east of the Meridian range
  59. * from 0 to 180 degrees.
  60. * @memberof KmlLookAt.prototype
  61. * @readonly
  62. * @type {Number}
  63. */
  64. kmlLongitude: {
  65. get: function () {
  66. return this._factory.specific(this, {name: 'longitude', transformer: NodeTransformers.number});
  67. }
  68. },
  69. /**
  70. * Latitude of the point the camera is looking at. Degrees north or south of the Equator (0 degrees). Values
  71. * range from -90 degrees to 90 degrees.
  72. * @memberof KmlLookAt.prototype
  73. * @readonly
  74. * @type {Number}
  75. */
  76. kmlLatitude: {
  77. get: function () {
  78. return this._factory.specific(this, {name: 'latitude', transformer: NodeTransformers.number});
  79. }
  80. },
  81. /**
  82. * Distance from the earth's surface, in meters. Interpreted according to the LookAt's altitude mode.
  83. * @memberof KmlLookAt.prototype
  84. * @readonly
  85. * @type {Number}
  86. */
  87. kmlAltitude: {
  88. get: function () {
  89. return this._factory.specific(this, {name: 'altitude', transformer: NodeTransformers.number});
  90. }
  91. },
  92. /**
  93. * Direction (that is, North, South, East, West), in degrees. Default=0 (North). (See diagram below.) Values
  94. * range from 0 to 360 degrees.
  95. * @memberof KmlLookAt.prototype
  96. * @readonly
  97. * @type {Number}
  98. */
  99. kmlHeading: {
  100. get: function () {
  101. return this._factory.specific(this, {name: 'heading', transformer: NodeTransformers.number});
  102. }
  103. },
  104. /**
  105. * Angle between the direction of the LookAt position and the normal to the surface of the earth. (See
  106. * diagram below.) Values range from 0 to 90 degrees. Values for <tilt> cannot be negative. A <tilt> value
  107. * of 0 degrees indicates viewing from directly above. A <tilt> value of 90 degrees indicates viewing along
  108. * the horizon.
  109. * @memberof KmlLookAt.prototype
  110. * @readonly
  111. * @type {Number}
  112. */
  113. kmlTilt: {
  114. get: function () {
  115. return this._factory.specific(this, {name: 'tilt', transformer: NodeTransformers.number});
  116. }
  117. },
  118. /**
  119. * Distance in meters from the point specified by <longitude>, <latitude>, and <altitude> to the LookAt
  120. * position. (See diagram below.)
  121. * @memberof KmlLookAt.prototype
  122. * @readonly
  123. * @type {Number}
  124. */
  125. kmlRange: {
  126. get: function () {
  127. return this._factory.specific(this, {name: 'range', transformer: NodeTransformers.number});
  128. }
  129. },
  130. /**
  131. * Specifies how the <altitude> specified for the LookAt point is interpreted. Possible values are as
  132. * follows: clampToGround - (default) Indicates to ignore the <altitude> specification and place the LookAt
  133. * position on the ground. relativeToGround - Interprets the <altitude> as a value in meters above the
  134. * ground. absolute - Interprets the <altitude> as a value in meters above sea level.
  135. * @memberof KmlLookAt.prototype
  136. * @readonly
  137. * @type {String}
  138. */
  139. kmlAltitudeMode: {
  140. get: function () {
  141. return this._factory.specific(this, {name: 'altitudeMode', transformer: NodeTransformers.string});
  142. }
  143. }
  144. });
  145. /**
  146. * Go to the look at location.
  147. */
  148. KmlLookAt.prototype.update = function(options) {
  149. if(options.wwd) {
  150. var altitude = this.kmlAltitude || 4000;
  151. // TODO: Respect altitude mode.
  152. options.wwd.goTo(new Position(this.kmlLatitude, this.kmlLongitude, altitude));
  153. }
  154. };
  155. /**
  156. * @inheritDoc
  157. */
  158. KmlLookAt.prototype.getTagNames = function () {
  159. return ['LookAt'];
  160. };
  161. KmlElements.addKey(KmlLookAt.prototype.getTagNames()[0], KmlLookAt);
  162. return KmlLookAt;
  163. });