Source: formats/geojson/GeoJSONFeature.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 GeoJSONFeature
  30. */
  31. define(['../../error/ArgumentError',
  32. './GeoJSONConstants',
  33. '../../util/Logger'
  34. ],
  35. function (ArgumentError,
  36. GeoJSONConstants,
  37. Logger) {
  38. "use strict";
  39. /**
  40. * Constructs a GeoJSON Feature object. Applications typically do not call this constructor. It is called by
  41. * {@link GeoJSON} as GeoJSON is read.
  42. * @alias GeoJSONFeature
  43. * @constructor
  44. * @classdesc Contains the data associated with a GeoJSON Feature Object.
  45. * A feature object must have a member with the name "geometry".
  46. * The value of the geometry member is a geometry object or a JSON null value.
  47. * A feature object must have a member with the name "properties".
  48. * The value of the properties member is an object (any JSON object or a JSON null value).
  49. * If a feature has a commonly used identifier, that identifier should be included as a member of the
  50. * feature object with the name "id".
  51. * To include information on the coordinate range for features, a GeoJSON object may have a member
  52. * named "bbox".
  53. * @param {Object} geometry An object containing the value of GeoJSON geometry member.
  54. * @param {Object} properties An object containing the value of GeoJSON properties member.
  55. * @param {Object} id An object containing the value of GeoJSON Feature id member.
  56. * @param {Object} bbox An object containing the value of GeoJSON Feature bbox member.
  57. * @throws {ArgumentError} If the specified mandatory geometries or properties are null or undefined.
  58. */
  59. var GeoJSONFeature = function (geometry, properties, id, bbox) {
  60. if (!geometry) {
  61. throw new ArgumentError(
  62. Logger.logMessage(Logger.LEVEL_SEVERE, "GeoJSONFeature", "constructor",
  63. "missingGeometry"));
  64. }
  65. if (!geometry[GeoJSONConstants.FIELD_TYPE]) {
  66. throw new ArgumentError(
  67. Logger.logMessage(Logger.LEVEL_SEVERE, "GeoJSONFeature", "constructor",
  68. "missingFeatureGeometryType"));
  69. }
  70. if (!properties) {
  71. throw new ArgumentError(
  72. Logger.logMessage(Logger.LEVEL_SEVERE, "GeoJSONFeature", "constructor",
  73. "missingProperties"));
  74. }
  75. // Documented in defineProperties below.
  76. this._geometry = geometry;
  77. // Documented in defineProperties below.
  78. this._properties = properties;
  79. // Documented in defineProperties below.
  80. this._id = id;
  81. // Documented in defineProperties below.
  82. this._bbox = bbox;
  83. };
  84. Object.defineProperties(GeoJSONFeature.prototype, {
  85. /**
  86. * The GeoJSON Feature geometry as specified to this GeoJSONFeature's constructor.
  87. * @memberof GeoJSONFeature.prototype
  88. * @type {Object}
  89. * @readonly
  90. */
  91. geometry: {
  92. get: function () {
  93. return this._geometry;
  94. }
  95. },
  96. /**
  97. * The GeoJSON Feature properties as specified to this GeoJSONFeature's constructor.
  98. * @memberof GeoJSONFeature.prototype
  99. * @type {Object}
  100. * @readonly
  101. */
  102. properties: {
  103. get: function () {
  104. return this._properties;
  105. }
  106. },
  107. /**
  108. * The GeoJSON Feature id as specified to this GeoJSONFeature's constructor.
  109. * @memberof GeoJSONFeature.prototype
  110. * @type {Object}
  111. * @readonly
  112. */
  113. id: {
  114. get: function () {
  115. return this._id;
  116. }
  117. },
  118. /**
  119. * The GeoJSON Feature bbox member as specified to this GeoJSONFeature's constructor.
  120. * @memberof GeoJSONFeature.prototype
  121. * @type {Object}
  122. * @readonly
  123. */
  124. bbox: {
  125. get: function () {
  126. return this._bbox;
  127. }
  128. }
  129. });
  130. return GeoJSONFeature;
  131. });